#include #include #include #include #include "main.h" #include "route.h" #include "l2tp.h" #include "rpc.h" #include "udp.h" #include "util.h" #include "vars.h" unsigned short int uh_sport; unsigned short int uh_dport; static const char *udp_ports[65536]; static const char *portcache(int port) { if (! udp_ports[port]) { struct servent *sp; sp = getservbyport(port,"udp"); if (sp) { char *tmp; tmp = malloc(1+strlen(sp->s_name)+1); sprintf(tmp,"=%s",sp->s_name); udp_ports[port] = tmp; } else { udp_ports[port] = ""; } } return(udp_ports[port]); } void dump_udp(void) { unsigned long int uh_ulen; unsigned short int uh_sum; need(8,"UDP header"); printx(pkt,2); uh_sport = get16(0); printf("uh_sport [%d%s]\n",uh_sport,portcache(uh_sport)); consume(2); printx(pkt,2); uh_dport = get16(0); printf("uh_dport [%d%s]\n",uh_dport,portcache(uh_dport)); consume(2); printx(pkt,2); uh_ulen = get16(0); printf("uh_ulen [%lu]",uh_ulen); if (uh_ulen < pktleft+4) { printf(" (dropping %lu trailing byte%s)",pktleft+4-uh_ulen,((pktleft+4-uh_ulen)==1)?"":"s"); pktleft = uh_ulen - 4; } printf("\n"); if (uh_ulen < 8) { printf("*** Claimed header size too small\n"); dumpabort(); } if (uh_ulen > pktleft+4) { printf("*** UDP header claims %lu bytes in packet but have only %d\n",uh_ulen,pktleft+4); dumpabort(); } /* maybe do something if uh_ulen > pktleft+4? */ consume(2); printx(pkt,2); uh_sum = get16(0); printf("uh_sum\n"); consume(2); if ((uh_dport == 520) || (uh_sport == 520)) { dump_route(); } else if ((uh_sport == 1701) && (uh_dport == 1701)) { dump_l2tp(); } else { maybe_dump_rpc(); } }