//#define HAVE_REMOTE #include #define PCAP_SRC_IF_STRING "rpcap://" #define PCAP_OPENFLAG_PROMISCUOUS 1 /* ������������ */ void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data); void packet_handler_1(u_char *dumpfile, const struct pcap_pkthdr *header, const u_char *pkt_data); int main(int argc, char **argv) { pcap_if_t *alldevs; pcap_if_t *d; int inum; int i=0; pcap_t *adhandle; char errbuf[PCAP_ERRBUF_SIZE]; pcap_dumper_t *dumpfile; /* ���������������� */ if(argc != 2) { printf("usage: %s filename", argv[0]); return -1; } /* ���������������� */ if (pcap_findalldevs(&alldevs, errbuf) == -1) { fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf); exit(1); } /* �������� */ for(d=alldevs; d; d=d->next) { printf("%d. %s", ++i, d->name); if (d->description) printf(" (%s)\n", d->description); else printf(" (No description available)\n"); } if(i==0) { printf("\nNo interfaces found! Make sure WinPcap is installed.\n"); return -1; } printf("Enter the interface number (1-%d):",i); scanf("%d", &inum); if(inum < 1 || inum > i) { printf("\nInterface number out of range.\n"); /* �������� */ pcap_freealldevs(alldevs); return -1; } /* ������������������ */ for(d=alldevs, i=0; i< inum-1 ; d=d->next, i++); /* ���������� */ if ( (adhandle= pcap_open_live(d->name, // ������ 65536, // �������������������� // 65535�������������������������������������������������� 1, // �������� 1000, // ������������ errbuf // ���������� ) ) == NULL) { fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name); /* ������������ */ pcap_freealldevs(alldevs); return -1; } /* ���������� */ dumpfile = pcap_dump_open(adhandle, argv[1]); if(dumpfile==NULL) { fprintf(stderr,"\nError opening output file\n"); return -1; } printf("\nlistening on %s... Press Ctrl+C to stop...\n", d->description); /* ������������ */ pcap_freealldevs(alldevs); /* �������� */ pcap_loop(adhandle, 0, packet_handler, (unsigned char *)dumpfile); return 0; } /* ������������������������ */ void packet_handler(u_char *dumpfile, const struct pcap_pkthdr *header, const u_char *pkt_data) { /* ������������������ */ pcap_dump(dumpfile, header, pkt_data); }