/* Simple parser for tcpdump output. */ /* (c) Andrae Muys 1998 andrae@humbug.org.au */ /* To use type tcpdump -i eth0 -n -x -s 60 ip host 130.102.60.6 | traffic > logfile */ #include #include char *protoN[] = { "???", "ICMP", "???", "GtoG", "???", "???", "TCP", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "UDP", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???" }; int main () { char src[30], dst[30]; char time[30]; char junk[120]; char *srcPort, *dstPort; int proto = 0; int len; long total; printf ("Time, Src Addr, Src Port, Dst Addr, Dst Port, Proto, Len\n"); while (1) { scanf ("%s %s %*s %s", time, src, dst); gets (junk); scanf ("%*x %x %*x %*x %x ", &len, &proto); proto &= 0x00FF; gets (junk); gets (junk); gets (junk); srcPort = strrchr (src, '.'); *srcPort = '\0'; srcPort++; srcPort[strlen(srcPort) - 1] = '\0'; dstPort = strrchr (dst, '.'); *dstPort = '\0'; dstPort++; dstPort[strlen(dstPort) - 1] = '\0'; printf ("%s,%s,%s,%s,%s,%s,%d\n", time, src, srcPort, dst, dstPort, protoN[proto], len); } return 0; }