void confirm_cover ( int n_left, int n_right, int *pointers, int *indices, int *flow, int *vweight, int *resid, /* residual weight at each vertex */ int sep_size, int *sep_nodes ) { int *marked; int sep_weight; int i, j, neighbor; int count_flow(); void count_resid(), check_resid(); marked = smalloc((n_left + n_right) * sizeof(int)); for (i = 0; i < n_left + n_right; i++) { marked[i] = FALSE; } sep_weight = 0; for (i = 0; i < sep_size; i++) { marked[sep_nodes[i]] = TRUE; sep_weight += vweight[sep_nodes[i]]; } for (i = 0; i < n_left; i++) { if (!marked[i]) { for (j = pointers[i]; j < pointers[i + 1]; j++) { neighbor = indices[j]; if (!marked[neighbor]) { printf("Edge (%d, %d) not covered\n", i, neighbor); } } } } i = count_flow(n_left, n_right, pointers, flow); if (i != sep_weight) { printf("ERROR: total_flow = %d, sep_weight = %d, sep_size = %d\n", i, sep_weight, sep_size); } else { printf("total_flow = %d, sep_weight = %d, sep_size = %d\n", i, sep_weight, sep_size); } /* Now check if any separator nodes have remaining flow. */ count_resid(n_left, n_right, resid, vweight, marked); check_resid(n_left, n_right, vweight, resid, pointers, indices, flow); sfree(marked); }
int main(int argc, char **argv) { pcap_t *pcap; char errbuf[PCAP_ERRBUF_SIZE]; const u_char *pkt; struct pcap_pkthdr hdr; struct ether_header *eptr; struct ip *ip_hdr; struct tcphdr *tcp_hdr; unsigned long nbp,nbip,nbtcp; unsigned long long totalSize; flow * flowrec; int c,optpkt; struct timeval t0,t1; uint32_t last_expiration,current_ts; // Default Paramaters for the classification labeling=clusterport; SSL_labeling=SSL_clusterport; sslparsing=0; threshold=-255; action=ACTION_LABEL; memory=NOOPTMEM; pktlimit=model.nbpackets; optpkt=pktlimit; stats.nbstats=0; bzero(stats.timeidx,sizeof(stats.timeidx)); bzero(stats.creations,sizeof(stats.creations)); bzero(stats.deletions,sizeof(stats.deletions)); nbflows=0; last_expiration=0; // Parsing options while ((c = getopt (argc, argv, "m:hCDPLSt:p:")) != -1) switch (c) { case 'h': usage(argv); break; case 'P': action=ACTION_PARSE; break; case 'L': action=ACTION_LABEL; break; case 'D': labeling=dominant; SSL_labeling=dominant; break; case 'C': labeling=clusterport; SSL_labeling=SSL_clusterport; break; case 'm': if (atoi(optarg)>=0) { memory=atoi(optarg); break; } else { fprintf(stderr,"Invalid Memory option\n"); usage(argv); } break; case 'S': sslparsing=1; break; case 't': if (atoi(optarg)>0) { threshold=-atoi(optarg); break; } else { fprintf(stderr,"Invalid threshold value\n"); usage(argv); } case 'p': if (atoi(optarg)>0) { optpkt=atoi(optarg); break; } else { fprintf(stderr,"Invalid packet value\n"); usage(argv); } case '?': if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); usage(argv); default: usage(argv); } if (action==ACTION_PARSE) pktlimit=optpkt; if (optind>=argc) { fprintf(stderr,"No file specified\n"); usage(argv); } // Opening pcap file fprintf(stderr,"Opening file : %s\n",argv[optind]); if ((pcap = pcap_open_offline(argv[optind], errbuf)) == NULL) { fprintf(stderr,"Error opening pcap file : %s\n",errbuf); usage(argv); } init_hashes (); // Empty connection to start list first_flow=(flow*)malloc(sizeof(flow)); first_flow->src.s_addr=0; first_flow->dst.s_addr=0; first_flow->sport=0; first_flow->dport=0; active_flows=first_flow; // Parse packets one by one nbp=0;nbip=0;nbtcp=0; totalSize=0; gettimeofday (&t0,NULL); while (pkt = pcap_next( pcap, &hdr )) { nbp++; totalSize+=hdr.len; current_ts=hdr.ts.tv_sec; if (last_expiration==0) last_expiration=current_ts; if (current_ts-last_expiration>CLEAN_TIME) { if (memory>=OPT_GARBAGE) clean_flows(first_flow->next,current_ts); statistics(current_ts-last_expiration); last_expiration=current_ts; } if (nbp % PRINTPKT== 0) { fprintf(stderr, "Pkt : %lu",nbp); fprintf(stderr, "\r"); fflush(stderr); } eptr = (struct ether_header *) pkt; if (ntohs (eptr->ether_type) != ETHERTYPE_IP) { continue; } else { nbip++; ip_hdr=(struct ip *)(pkt+14); if (ip_hdr->ip_p==IPPROTO_TCP && ((ntohs (ip_hdr->ip_off) & IP_OFFMASK)==0)) { nbtcp++; count_flow(ip_hdr,hdr.caplen-14,hdr.ts.tv_sec); } } } if (memory>=OPT_GARBAGE) clean_flows(first_flow->next,current_ts); statistics(current_ts-last_expiration); last_expiration=current_ts; dump_flows(first_flow->next); statistics(1); gettimeofday (&t1,NULL); pcap_close(pcap); fprintf(stderr,"\n%lu Packets parsed in %.2fms\n(%lu non-ip / %lu non-tcp)\n" "TCP Connections with Syn: %lu\n" "Total Volume: %llu\n" "Duration: %lu\n", nbp, (float)((t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec))/1000, nbp-nbip,nbp-nbtcp,flow_hash->total_insert,totalSize,stats.timeidx[stats.nbstats]); //dump_hashtab_stats(flow_hash); //print_statistics(); }