int main(int argc, char const *argv[]) { char interface[256] = "", bpfstr[256] = ""; int packets = 0, c, i; // Get the command line options, if any while ((c = getopt (argc, argv, "hi:n:")) != -1) { switch (c) { case 'h': printf("usage: %s [-h] [-i ] [-n ] []\n", argv[0]); exit(0); break; case 'i': strcpy(interface, optarg); break; case 'n': packets = atoi(optarg); break; } } // Get the packet capture filter expression, if any. for (i = optind; i < argc; i++) { strcat(bpfstr, argv[i]); strcat(bpfstr, " "); } // Open libpcap, set the program termination signals then start // processing packets. if ((pd = open_pcap_socket(interface, bpfstr))) { signal(SIGINT, bailout); signal(SIGTERM, bailout); signal(SIGQUIT, bailout); capture_loop(pd, packets, (pcap_handler)parse_packet); bailout(0); } // pcap_loop(descr,-1,another_callback,NULL); return 0; }
int main(int argc,char **argv) { mac_array = malloc(sizeof(struct MACarray)); ip_array = malloc(sizeof(struct IParray)); initIParray(ip_array,10); initMACarray(mac_array,10); char interface[256] = "", bpfstr[256] = ""; int packets = 0, c, i; while ((c = getopt (argc, argv, "hi:n:")) != -1) { switch (c) { case 'h': printf("Usage: %s [-h] [-i ] []\n", argv[0]); exit(0); break; case 'i': strcpy(interface, optarg); break; } } for (i = optind; i < argc; i++) { strcat(bpfstr, argv[i]); strcat(bpfstr, " "); } if ((handle = open_pcap_socket(interface, bpfstr))) { signal(SIGINT, program_terminate); signal(SIGTERM, program_terminate); signal(SIGQUIT, program_terminate); capture_loop(handle, packets, (pcap_handler)handle_packet); } return 0; }