/* * pcapstein dumps all B-Fields found in a pcap file * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * authors: * (C) 2008 Andreas Schuler * (C) 2008 Matthias Wenzel * */ #include #include #include #include #include #include #include #include #include #include #include "pcapstein.h" struct file_info fi; void usage(void) { fprintf(stderr, "usage: pcapstein \n"); fprintf(stderr, " creates _pp.ima\n"); fprintf(stderr, " and _fp.ima\n"); fprintf(stderr, " for further g.721 audio processing\n"); fprintf(stderr, " e.g. decode and sox\n"); } void init(char * fname) { fi.p = pcap_open_offline(fname, errbuf); if (!fi.p) { fprintf(stderr, "couln't open(\"%s\"): %s\n", fname, strerror(errno)); fprintf(stderr, "pcap error: %s\n", errbuf); exit(1); } fprintf(stderr, "%s\n", pcap_lib_version()); fprintf(stderr, "pcap file version %d.%d\n", pcap_major_version(fi.p), pcap_minor_version(fi.p) ); /* output file handles */ char * imafname = malloc(strlen(fname)+23); if (!imafname) { fprintf(stderr, "out of memory: %s\n", strerror(errno)); exit(1); } /* PP output file */ sprintf(imafname, "%s_pp.ima", fname); fi.fpp = open(imafname, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (!fi.fpp) { fprintf(stderr, "couldn't open(\"%s\"): %s\n", imafname, strerror(errno)); exit(1); } /* FP output file */ sprintf(imafname, "%s_fp.ima", fname); fi.ffp = open(imafname, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (!fi.ffp) { fprintf(stderr, "couldn't open(\"%s\"): %s\n", imafname, strerror(errno)); exit(1); } free (imafname); } void process_b_field(const struct pcap_pkthdr *h, const u_char *pkt) { if ( (pkt[0x17] == 0x16) && (pkt[0x18] == 0x75) ) write(fi.fpp, &pkt[0x21], 40); else write(fi.ffp, &pkt[0x21], 40); } void process_pcap_packet( u_char *user, const struct pcap_pkthdr *h, const u_char *pkt) { #if 0 int i; printf("packet for %s [%u/%u] @%d.%d\n", user, h->len, h->caplen, h->ts.tv_sec, h->ts.tv_usec ); #endif if (pkt[ETH_TYPE_0_OFF] != ETH_TYPE_0) return; if (pkt[ETH_TYPE_1_OFF] != ETH_TYPE_1) return; #if 0 for (i=0; i