Пример #1
0
void
Monitor::NodeGenerator::findConnections(TreeNode * t)
{
  if (t == 0) {
    return;
  }

  std::string key = t->column(0).toString().toLocal8Bit().constData();
  std::string val = t->column(1).toString().toLocal8Bit().constData();

  // store this writer-->reader connection info
  TreeNode *c;
  std::string tmp;
  std::string conn;

  if (key == "Reader" || key == "Writer") {
    for (int i = 0; i < t->size(); ++i) {
      c = t->operator[](i);
      tmp = c->column(0).toString().toLocal8Bit().constData();

      if (nodeOpt_.abbrGUIDs()) {
        conn = abbr(c->column(1).toString().toLocal8Bit().constData());
        val = abbr(t->column(1).toString().toLocal8Bit().constData());
      }
      else {
        conn = c->column(1).toString().toLocal8Bit().constData();
      }

      if (tmp == "Writer" && key == "Reader") {
        rMap_[t] = conn;
      }
      else if (tmp == "Reader" && key == "Writer") {
        wMap_[val] = t;
      }
    }
  }

  for (int i = 0; i < t->size(); ++i) {
    findConnections(t->operator[](i));
  }
}
Пример #2
0
void
Monitor::NodeGenerator::connectNodes(QGraphicsScene *nodeScene)
{
  // erase old values
  rMap_.clear();
  wMap_.clear();

  findConnections(root_);

  std::map <TreeNode *, std::string>::const_iterator i;

  // connect reader to writers
  for (i = rMap_.begin(); i != rMap_.end(); ++i) {
    Node *parent = nMap_[i->first];
    Node *child = nMap_[wMap_[rMap_[i->first]]];
    if (parent && child) {
      Edge *edge = new Edge(parent, child, true, parent);
      nodeScene->addItem(edge);
      parent->addEdge(edge);
      child->addEdge(edge);
    }
  }
}
Пример #3
0
int main(int argc, char *argv[]){
	//decalre the required variables
	char errbuf[PCAP_ERRBUF_SIZE];
	char *capFile;
	unsigned int packet_counter=0;
	struct pcap_pkthdr header;
	const u_char *packet;
	int num_connections = 0;
	struct connection connections[MAX_NUM_CONNECTION];
	struct bpf_program fp;

	// Check if there is an argument provided with the program
	if(argc < 2){
		fprintf(stderr, "Please provide a trace file in the arguments\n");
		return(0);
	}

	capFile = argv[1]; // The name of the capture file

	pcap_t *handle;
	handle = pcap_open_offline(capFile, errbuf); //Open the capture file
	if(handle == NULL) {//Check if the file opened correctly
		fprintf(stderr, "Couldn't open pcap file %s: %s\n", capFile, errbuf);
		return(2);
	}

	if(pcap_compile(handle, &fp, "ip and tcp", 0, 0) == -1){//Try to compile the filter
		fprintf(stderr, "Couldn't compile filter 'ip and tcp'");
		return(2);
	}

	if(pcap_setfilter(handle, &fp) == -1){ // Try to apply the filter
		fprintf(stderr, "Coulnd't set the comiled filter");
		return(2);
	}

	//make an array of tcp connection structs
	struct tcp_connection cons[MAX_NUM_CONNECTION];\
	int size = 0;
	struct timeval startTime;
	int first = 1;

	// go through all the packets in the capture file
	while(packet = pcap_next(handle,&header)) {
		if(first){ //grab the start time
		    startTime = header.ts;
		    first = 0;
		} 
		// call findConnections and get how many connectiosn there are
		size = findConnections(packet, header.len, cons, size);
	}
	int i;
	for(i = 0; i < size; i++){
		//Go through each connection and call openConnection on it to get it's info
		openConnection(&cons[i], &connections[i], capFile, &startTime);
	}
	//Close the capture file
	pcap_close(handle);

	//print the results
	printout(size, connections);

	return 0;
}