X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/cb4e517e9aae83b3bc0beac4ad9fb9f2318a4dd2..2534d28e343f7d50a813a801c9c59dfedfea1bbd:/print-udp.c diff --git a/print-udp.c b/print-udp.c index 11f60838..fde6aad6 100644 --- a/print-udp.c +++ b/print-udp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.76 2000-08-01 17:36:49 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.96 2001-06-26 06:19:06 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -30,14 +30,8 @@ static const char rcsid[] = #include #include -#include #include -#include -#include -#include -#include -#include #ifdef SEGSIZE #undef SEGSIZE @@ -47,21 +41,19 @@ static const char rcsid[] = #include #include - -#ifdef INET6 -#include -#endif +#include #include "interface.h" #include "addrtoname.h" #include "appletalk.h" -#ifdef NOERROR -#undef NOERROR /* Solaris sucks */ -#endif -#ifdef T_UNSPEC -#undef T_UNSPEC /* SINIX does too */ +#include "udp.h" + +#include "ip.h" +#ifdef INET6 +#include "ip6.h" #endif + #include "nameser.h" #include "nfs.h" #include "bootp.h" @@ -182,7 +174,7 @@ rtp_print(const void *hdr, u_int len, register const struct udphdr *up) i0 & 0xffff, i1); if (vflag) { - printf(" %u", i1); + printf(" %u", (u_int32_t)ntohl(((u_int *)hdr)[2])); if (hasopt) { u_int i2, optlen; do { @@ -327,7 +319,7 @@ static int udp_cksum(register const struct ip *ip, sum += *sp++; if (tlen & 1) { - sum += htons( (*(const char *)sp) << 8); + sum += htons( (*(const u_int8_t *)sp) << 8); } while (sum > 0xffff) @@ -375,7 +367,7 @@ static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up, sum += *sp++; if (tlen & 1) - sum += htons((*(const char *)sp) << 8); + sum += htons((*(const u_int8_t *)sp) << 8); while (sum > 0xffff) sum = (sum & 0xffff) + (sum >> 16); @@ -394,16 +386,22 @@ static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up, #define NTP_PORT 123 /*XXX*/ #define SNMPTRAP_PORT 162 /*XXX*/ #define ISAKMP_PORT 500 /*XXX*/ +#define TIMED_PORT 525 /*XXX*/ #define RIP_PORT 520 /*XXX*/ #define KERBEROS_SEC_PORT 750 /*XXX*/ #define L2TP_PORT 1701 /*XXX*/ -#define ISAKMP_PORT_USER1 7500 /*??? - nonstandard*/ -#define ISAKMP_PORT_USER2 8500 /*??? - nonstandard*/ +#define ISAKMP_PORT_USER1 7500 /*XXX - nonstandard*/ +#define ISAKMP_PORT_USER2 8500 /*XXX - nonstandard*/ #define RX_PORT_LOW 7000 /*XXX*/ #define RX_PORT_HIGH 7009 /*XXX*/ #define NETBIOS_NS_PORT 137 #define NETBIOS_DGRAM_PORT 138 #define CISCO_AUTORP_PORT 496 /*XXX*/ +#define RADIUS_PORT 1645 +#define RADIUS_NEW_PORT 1812 +#define RADIUS_ACCOUNTING_PORT 1646 +#define RADIUS_NEW_ACCOUNTING_PORT 1813 +#define LWRES_PORT 921 #ifdef INET6 #define RIPNG_PORT 521 /*XXX*/ @@ -412,7 +410,8 @@ static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up, #endif void -udp_print(register const u_char *bp, u_int length, register const u_char *bp2) +udp_print(register const u_char *bp, u_int length, + register const u_char *bp2, int fragmented) { register const struct udphdr *up; register const struct ip *ip; @@ -428,7 +427,7 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) up = (struct udphdr *)bp; ip = (struct ip *)bp2; #ifdef INET6 - if (ip->ip_v == 6) + if (IP_V(ip) == 6) ip6 = (struct ip6_hdr *)bp2; else ip6 = NULL; @@ -561,15 +560,10 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) (atalk_port(sport) || atalk_port(dport))) { if (vflag) fputs("kip ", stdout); - atalk_print(cp, length); + llap_print(cp, length); return; } } -#if 0 - (void)printf("%s.%s > %s.%s:", - ipaddr_string(&ip->ip_src), udpport_string(sport), - ipaddr_string(&ip->ip_dst), udpport_string(dport)); -#else #ifdef INET6 if (ip6) { if (ip6->ip6_nxt == IPPROTO_UDP) { @@ -596,30 +590,29 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) udpport_string(sport), udpport_string(dport)); } } -#endif - if (ip->ip_v == 4 && vflag) { + if (IP_V(ip) == 4 && vflag && !fragmented) { int sum = up->uh_sum; if (sum == 0) { - (void)printf(" [no cksum]"); + (void)printf("[no cksum] "); } else if (TTEST2(cp[0], length)) { sum = udp_cksum(ip, up, length); if (sum != 0) - (void)printf(" [bad udp cksum %x!]", sum); + (void)printf("[bad udp cksum %x!] ", sum); else - (void)printf(" [udp sum ok]"); + (void)printf("[udp sum ok] "); } } #ifdef INET6 - if (ip->ip_v == 6 && ip6->ip6_plen && vflag) { + if (IP_V(ip) == 6 && ip6->ip6_plen && vflag && !fragmented) { int sum = up->uh_sum; /* for IPv6, UDP checksum is mandatory */ if (TTEST2(cp[0], length)) { sum = udp6_cksum(ip6, up, length); if (sum != 0) - (void)printf(" [bad udp cksum %x!]", sum); + (void)printf("[bad udp cksum %x!] ", sum); else - (void)printf(" [udp sum ok]"); + (void)printf("[udp sum ok] "); } } #endif @@ -628,6 +621,8 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) #define ISPORT(p) (dport == (p) || sport == (p)) if (ISPORT(NAMESERVER_PORT)) ns_print((const u_char *)(up + 1), length); + else if (ISPORT(TIMED_PORT)) + timed_print((const u_char *)(up + 1), length); else if (ISPORT(TFTP_PORT)) tftp_print((const u_char *)(up + 1), length); else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS)) @@ -649,12 +644,10 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) krb_print((const void *)(up + 1), length); else if (ISPORT(L2TP_PORT)) l2tp_print((const u_char *)(up + 1), length); - else if (ISPORT(NETBIOS_NS_PORT)) { + else if (ISPORT(NETBIOS_NS_PORT)) nbt_udp137_print((const u_char *)(up + 1), length); - } - else if (ISPORT(NETBIOS_DGRAM_PORT)) { + else if (ISPORT(NETBIOS_DGRAM_PORT)) nbt_udp138_print((const u_char *)(up + 1), length); - } else if (dport == 3456) vat_print((const void *)(up + 1), length, up); /* @@ -680,6 +673,13 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) wb_print((const void *)(up + 1), length); else if (ISPORT(CISCO_AUTORP_PORT)) cisco_autorp_print((const void *)(up + 1), length); + else if (ISPORT(RADIUS_PORT) || + ISPORT(RADIUS_NEW_PORT) || + ISPORT(RADIUS_ACCOUNTING_PORT) || + ISPORT(RADIUS_NEW_ACCOUNTING_PORT) ) + radius_print((const u_char *)(up+1), length); + else if (ISPORT(LWRES_PORT)) + lwres_print((const u_char *)(up + 1), length); else (void)printf(" udp %u", (u_int32_t)(ulen - sizeof(*up)));