]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-udp.c
document SIGUSR1 in manual page
[tcpdump] / print-udp.c
index e01cd995b4999b0f0450b2a65f0780476c47f924..c3edf6ef5de19b855731cd0c30bf07ab6a2d0275 100644 (file)
 
 #include "nameser.h"
 #include "nfs.h"
-#include "bootp.h"
 
 struct rtcphdr {
-       u_int16_t rh_flags;     /* T:2 P:1 CNT:5 PT:8 */
-       u_int16_t rh_len;       /* length of message (in words) */
-       u_int32_t rh_ssrc;      /* synchronization src id */
+       uint16_t rh_flags;      /* T:2 P:1 CNT:5 PT:8 */
+       uint16_t rh_len;        /* length of message (in words) */
+       uint32_t rh_ssrc;       /* synchronization src id */
 };
 
 typedef struct {
-       u_int32_t upper;        /* more significant 32 bits */
-       u_int32_t lower;        /* less significant 32 bits */
+       uint32_t upper; /* more significant 32 bits */
+       uint32_t lower; /* less significant 32 bits */
 } ntp64;
 
 /*
@@ -61,9 +60,9 @@ typedef struct {
  */
 struct rtcp_sr {
        ntp64 sr_ntp;           /* 64-bit ntp timestamp */
-       u_int32_t sr_ts;        /* reference media timestamp */
-       u_int32_t sr_np;        /* no. packets sent */
-       u_int32_t sr_nb;        /* no. bytes sent */
+       uint32_t sr_ts; /* reference media timestamp */
+       uint32_t sr_np; /* no. packets sent */
+       uint32_t sr_nb; /* no. bytes sent */
 };
 
 /*
@@ -71,12 +70,12 @@ struct rtcp_sr {
  * Time stamps are middle 32-bits of ntp timestamp.
  */
 struct rtcp_rr {
-       u_int32_t rr_srcid;     /* sender being reported */
-       u_int32_t rr_nl;        /* no. packets lost */
-       u_int32_t rr_ls;        /* extended last seq number received */
-       u_int32_t rr_dv;        /* jitter (delay variance) */
-       u_int32_t rr_lsr;       /* orig. ts from last rr from this src  */
-       u_int32_t rr_dlsr;      /* time from recpt of last rr to xmit time */
+       uint32_t rr_srcid;      /* sender being reported */
+       uint32_t rr_nl; /* no. packets lost */
+       uint32_t rr_ls; /* extended last seq number received */
+       uint32_t rr_dv; /* jitter (delay variance) */
+       uint32_t rr_lsr;        /* orig. ts from last rr from this src  */
+       uint32_t rr_dlsr;       /* time from recpt of last rr to xmit time */
 };
 
 /*XXX*/
@@ -98,18 +97,18 @@ static void
 vat_print(netdissect_options *ndo, const void *hdr, register const struct udphdr *up)
 {
        /* vat/vt audio */
-       u_int ts = *(u_int16_t *)hdr;
+       u_int ts = *(uint16_t *)hdr;
        if ((ts & 0xf060) != 0) {
                /* probably vt */
                ND_PRINT((ndo, "udp/vt %u %d / %d",
-                            (u_int32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up)),
+                            (uint32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up)),
                             ts & 0x3ff, ts >> 10));
        } else {
                /* probably vat */
-               u_int32_t i0 = EXTRACT_32BITS(&((u_int *)hdr)[0]);
-               u_int32_t i1 = EXTRACT_32BITS(&((u_int *)hdr)[1]);
+               uint32_t i0 = EXTRACT_32BITS(&((u_int *)hdr)[0]);
+               uint32_t i1 = EXTRACT_32BITS(&((u_int *)hdr)[1]);
                ND_PRINT((ndo, "udp/vat %u c%d %u%s",
-                       (u_int32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up) - 8),
+                       (uint32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up) - 8),
                        i0 & 0xffff,
                        i1, i0 & 0x800000? "*" : ""));
                /* audio format */
@@ -127,8 +126,8 @@ rtp_print(netdissect_options *ndo, const void *hdr, u_int len,
        /* rtp v1 or v2 */
        u_int *ip = (u_int *)hdr;
        u_int hasopt, hasext, contype, hasmarker;
-       u_int32_t i0 = EXTRACT_32BITS(&((u_int *)hdr)[0]);
-       u_int32_t i1 = EXTRACT_32BITS(&((u_int *)hdr)[1]);
+       uint32_t i0 = EXTRACT_32BITS(&((u_int *)hdr)[0]);
+       uint32_t i1 = EXTRACT_32BITS(&((u_int *)hdr)[1]);
        u_int dlen = EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up) - 8;
        const char * ptype;
 
@@ -199,7 +198,7 @@ rtcp_print(netdissect_options *ndo, const u_char *hdr, const u_char *ep)
        struct rtcp_sr *sr;
        struct rtcphdr *rh = (struct rtcphdr *)hdr;
        u_int len;
-       u_int16_t flags;
+       uint16_t flags;
        int cnt;
        double ts, dts;
        if ((u_char *)(rh + 1) > ep) {
@@ -276,7 +275,7 @@ static int udp_cksum(netdissect_options *ndo, register const struct ip *ip,
                     register const struct udphdr *up,
                     register u_int len)
 {
-       return nextproto4_cksum(ndo, ip, (const u_int8_t *)(void *)up, len, len,
+       return nextproto4_cksum(ndo, ip, (const uint8_t *)(void *)up, len, len,
                                IPPROTO_UDP);
 }
 
@@ -284,7 +283,7 @@ static int udp_cksum(netdissect_options *ndo, register const struct ip *ip,
 static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up,
        u_int len)
 {
-       return nextproto6_cksum(ip6, (const u_int8_t *)(void *)up, len, len,
+       return nextproto6_cksum(ip6, (const uint8_t *)(void *)up, len, len,
            IPPROTO_UDP);
 }
 #endif
@@ -304,13 +303,13 @@ udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dpo
                if (ip6->ip6_nxt == IPPROTO_UDP) {
                        if (sport == -1) {
                                ND_PRINT((ndo, "%s > %s: ",
-                                       ip6addr_string(&ip6->ip6_src),
-                                       ip6addr_string(&ip6->ip6_dst)));
+                                       ip6addr_string(ndo, &ip6->ip6_src),
+                                       ip6addr_string(ndo, &ip6->ip6_dst)));
                        } else {
                                ND_PRINT((ndo, "%s.%s > %s.%s: ",
-                                       ip6addr_string(&ip6->ip6_src),
+                                       ip6addr_string(ndo, &ip6->ip6_src),
                                        udpport_string(sport),
-                                       ip6addr_string(&ip6->ip6_dst),
+                                       ip6addr_string(ndo, &ip6->ip6_dst),
                                        udpport_string(dport)));
                        }
                } else {
@@ -326,13 +325,13 @@ udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dpo
                if (ip->ip_p == IPPROTO_UDP) {
                        if (sport == -1) {
                                ND_PRINT((ndo, "%s > %s: ",
-                                       ipaddr_string(&ip->ip_src),
-                                       ipaddr_string(&ip->ip_dst)));
+                                       ipaddr_string(ndo, &ip->ip_src),
+                                       ipaddr_string(ndo, &ip->ip_dst)));
                        } else {
                                ND_PRINT((ndo, "%s.%s > %s.%s: ",
-                                       ipaddr_string(&ip->ip_src),
+                                       ipaddr_string(ndo, &ip->ip_src),
                                        udpport_string(sport),
-                                       ipaddr_string(&ip->ip_dst),
+                                       ipaddr_string(ndo, &ip->ip_dst),
                                        udpport_string(dport)));
                        }
                } else {
@@ -353,7 +352,7 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
        register const struct ip *ip;
        register const u_char *cp;
        register const u_char *ep = bp + length;
-       u_int16_t sport, dport, ulen;
+       uint16_t sport, dport, ulen;
 #ifdef INET6
        register const struct ip6_hdr *ip6;
 #endif
@@ -368,7 +367,6 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
        else
                ip6 = NULL;
 #endif /*INET6*/
-       cp = (u_char *)(up + 1);
        if (!ND_TTEST(up->uh_dport)) {
                udpipaddr_print(ndo, ip, -1, -1);
                ND_PRINT((ndo, "[|udp]"));
@@ -383,20 +381,24 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
                ND_PRINT((ndo, "truncated-udp %d", length));
                return;
        }
+       ulen = EXTRACT_16BITS(&up->uh_ulen);
+       if (ulen < sizeof(struct udphdr)) {
+               udpipaddr_print(ndo, ip, sport, dport);
+               ND_PRINT((ndo, "truncated-udplength %d", ulen));
+               return;
+       }
+       ulen -= sizeof(struct udphdr);
        length -= sizeof(struct udphdr);
+       if (ulen < length)
+               length = ulen;
 
+       cp = (u_char *)(up + 1);
        if (cp > ndo->ndo_snapend) {
                udpipaddr_print(ndo, ip, sport, dport);
                ND_PRINT((ndo, "[|udp]"));
                return;
        }
 
-       ulen = EXTRACT_16BITS(&up->uh_ulen);
-       if (ulen < 8) {
-               udpipaddr_print(ndo, ip, sport, dport);
-               ND_PRINT((ndo, "truncated-udplength %d", ulen));
-               return;
-       }
        if (ndo->ndo_packettype) {
                register struct sunrpc_msg *rp;
                enum sunrpc_msg_type direction;
@@ -442,7 +444,7 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
 
                case PT_CNFP:
                        udpipaddr_print(ndo, ip, sport, dport);
-                       cnfp_print(ndo, cp, (const u_char *)ip);
+                       cnfp_print(ndo, cp);
                        break;
 
                case PT_TFTP:
@@ -522,7 +524,7 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
 
        if (ndo->ndo_vflag && !ndo->ndo_Kflag && !fragmented) {
                 /* Check the checksum, if possible. */
-                u_int16_t sum, udp_sum;
+                uint16_t sum, udp_sum;
 
                /*
                 * XXX - do this even if vflag == 1?
@@ -568,10 +570,10 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
                else if (ISPORT(MULTICASTDNS_PORT))
                        ns_print(ndo, (const u_char *)(up + 1), length, 1);
                else if (ISPORT(TIMED_PORT))
-                       timed_print((const u_char *)(up + 1));
+                       timed_print(ndo, (const u_char *)(up + 1));
                else if (ISPORT(TFTP_PORT))
                        tftp_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS))
+               else if (ISPORT(BOOTPC_PORT) || ISPORT(BOOTPS_PORT))
                        bootp_print(ndo, (const u_char *)(up + 1), length);
                else if (ISPORT(RIP_PORT))
                        rip_print(ndo, (const u_char *)(up + 1), length);
@@ -600,9 +602,9 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
                        l2tp_print(ndo, (const u_char *)(up + 1), length);
 #ifdef TCPDUMP_DO_SMB
                else if (ISPORT(NETBIOS_NS_PORT))
-                       nbt_udp137_print((const u_char *)(up + 1), length);
+                       nbt_udp137_print(ndo, (const u_char *)(up + 1), length);
                else if (ISPORT(NETBIOS_DGRAM_PORT))
-                       nbt_udp138_print((const u_char *)(up + 1), length);
+                       nbt_udp138_print(ndo, (const u_char *)(up + 1), length);
 #endif
                else if (dport == VAT_PORT)
                        vat_print(ndo, (const void *)(up + 1), up);
@@ -624,7 +626,7 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
                else if (ISPORT(AHCP_PORT))
                        ahcp_print(ndo, (const u_char *)(up + 1), length);
                else if (ISPORT(BABEL_PORT) || ISPORT(BABEL_PORT_OLD))
-                       babel_print((const u_char *)(up + 1), length);
+                       babel_print(ndo, (const u_char *)(up + 1), length);
 #endif /*INET6*/
                /*
                 * Kludge in test for whiteboard packets.
@@ -636,12 +638,13 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
                else if (ISPORT(RADIUS_PORT) ||
                         ISPORT(RADIUS_NEW_PORT) ||
                         ISPORT(RADIUS_ACCOUNTING_PORT) ||
-                        ISPORT(RADIUS_NEW_ACCOUNTING_PORT) )
+                        ISPORT(RADIUS_NEW_ACCOUNTING_PORT) ||
+                        ISPORT(RADIUS_COA_PORT) )
                        radius_print(ndo, (const u_char *)(up+1), length);
                else if (dport == HSRP_PORT)
                        hsrp_print(ndo, (const u_char *)(up + 1), length);
                else if (ISPORT(LWRES_PORT))
-                       lwres_print((const u_char *)(up + 1), length);
+                       lwres_print(ndo, (const u_char *)(up + 1), length);
                else if (ISPORT(LDP_PORT))
                        ldp_print(ndo, (const u_char *)(up + 1), length);
                else if (ISPORT(OLSR_PORT))
@@ -669,19 +672,30 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
                 else if (ISPORT(LWAPP_DATA_PORT))
                         lwapp_data_print(ndo, (const u_char *)(up + 1), length);
                 else if (ISPORT(SIP_PORT))
-                       sip_print((const u_char *)(up + 1), length);
+                       sip_print(ndo, (const u_char *)(up + 1), length);
                 else if (ISPORT(SYSLOG_PORT))
-                       syslog_print((const u_char *)(up + 1), length);
+                       syslog_print(ndo, (const u_char *)(up + 1), length);
                 else if (ISPORT(OTV_PORT))
                        otv_print(ndo, (const u_char *)(up + 1), length);
                 else if (ISPORT(VXLAN_PORT))
                        vxlan_print(ndo, (const u_char *)(up + 1), length);
-               else
-                       ND_PRINT((ndo, "UDP, length %u",
-                           (u_int32_t)(ulen - sizeof(*up))));
+                else if (ISPORT(GENEVE_PORT))
+                       geneve_print(ndo, (const u_char *)(up + 1), length);
+               else {
+                       if (ulen > length)
+                               ND_PRINT((ndo, "UDP, bad length %u > %u",
+                                   ulen, length));
+                       else
+                               ND_PRINT((ndo, "UDP, length %u", ulen));
+               }
 #undef ISPORT
-       } else
-               ND_PRINT((ndo, "UDP, length %u", (u_int32_t)(ulen - sizeof(*up))));
+       } else {
+               if (ulen > length)
+                       ND_PRINT((ndo, "UDP, bad length %u > %u",
+                           ulen, length));
+               else
+                       ND_PRINT((ndo, "UDP, length %u", ulen));
+       }
 }