static int uread(proc_t *p, void *kaddr, size_t len, uintptr_t uaddr) { return (proc_ops(UIO_READ, p, kaddr, uaddr, len)); }
static int uwrite(proc_t *p, void *kaddr, size_t len, uintptr_t uaddr) { return (proc_ops(UIO_WRITE, p, kaddr, uaddr, len)); }
/* Main code and general functions */ int main(int argc, char *argv[]) { char *dev = NULL; char errbuf[PCAP_ERRBUF_SIZE] = {0}; bpf_u_int32 mask; bpf_u_int32 net; if (argc > 1) { proc_ops(argc, argv); dev = argv[optind]; if(!dev) { printf("No network interface name given\n\n"); show_help(); } if(!op.port) { strcpy(filter_exp + 5, "3306"); op.port_n = 3306; } } else show_help(); if(pcap_lookupnet(dev, &net, &mask, errbuf) == -1) { printf("Couldn't get netmask for device %s: %s\n", dev, errbuf); net = mask = 0; } handle = pcap_open_live(dev, SNAP_LEN, 1, 1000, errbuf); if(handle == NULL) { printf("Couldn't open device %s: %s\n", dev, errbuf); exit(-1); } if (strlen(errbuf) > 0) { printf("Warning from pcap_open_live: %s\n", errbuf); } if(pcap_compile(handle, &fp, filter_exp, 0, net) == -1) { printf("Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(handle)); exit(-1); } if (pcap_setfilter(handle, &fp) == -1) { printf("Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(handle)); exit(-1); } printf("mysqlsniffer listening for MySQL on interface %s %s\n", dev, filter_exp); signal(SIGINT, handle_ctrl_c); signal(SIGHUP, handle_sighup); init_tags(); init_state_map(); pcap_loop(handle, -1, proc_packet, NULL); printf("ERROR: pcap_loop returned from an infinite loop\n"); cleanup(); print_stats(); exit(-1); }