/* \summary: UDP printer */
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
-#include <netdissect-stdinc.h>
+#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "addrtoname.h"
#include "nfs.h"
-static const char vat_tstr[] = " [|vat]";
-static const char rtp_tstr[] = " [|rtp]";
-static const char rtcp_tstr[] = " [|rtcp]";
-static const char udp_tstr[] = " [|udp]";
struct rtcphdr {
nd_uint16_t rh_flags; /* T:2 P:1 CNT:5 PT:8 */
#define RTCP_PT_APP 204
static void
-vat_print(netdissect_options *ndo, const void *hdr, const struct udphdr *up)
+vat_print(netdissect_options *ndo, const void *hdr, u_int length)
{
/* vat/vt audio */
u_int ts;
+ ndo->ndo_protocol = "vat";
+ if (length < 2) {
+ ND_PRINT("udp/va/vat, length %u < 2", length);
+ return;
+ }
ND_TCHECK_2((const u_int *)hdr);
ts = EXTRACT_BE_U_2(hdr);
if ((ts & 0xf060) != 0) {
/* probably vt */
- ND_TCHECK_2(up->uh_ulen);
- ND_PRINT("udp/vt %u %d / %d",
- (uint32_t)(EXTRACT_BE_U_2(up->uh_ulen) - sizeof(*up)),
+ ND_PRINT("udp/vt %u %u / %u",
+ length,
ts & 0x3ff, ts >> 10);
} else {
/* probably vat */
uint32_t i0, i1;
+ if (length < 8) {
+ ND_PRINT("udp/vat, length %u < 8", length);
+ return;
+ }
ND_TCHECK_4(&((const u_int *)hdr)[0]);
i0 = EXTRACT_BE_U_4(&((const u_int *)hdr)[0]);
ND_TCHECK_4(&((const u_int *)hdr)[1]);
i1 = EXTRACT_BE_U_4(&((const u_int *)hdr)[1]);
- ND_TCHECK_2(up->uh_ulen);
- ND_PRINT("udp/vat %u c%d %u%s",
- (uint32_t)(EXTRACT_BE_U_2(up->uh_ulen) - sizeof(*up) - 8),
+ ND_PRINT("udp/vat %u c%u %u%s",
+ length - 8,
i0 & 0xffff,
i1, i0 & 0x800000? "*" : "");
/* audio format */
if (i0 & 0x1f0000)
- ND_PRINT(" f%d", (i0 >> 16) & 0x1f);
+ ND_PRINT(" f%u", (i0 >> 16) & 0x1f);
if (i0 & 0x3f000000)
- ND_PRINT(" s%d", (i0 >> 24) & 0x3f);
+ ND_PRINT(" s%u", (i0 >> 24) & 0x3f);
}
+ return;
trunc:
- ND_PRINT("%s", vat_tstr);
+ nd_print_trunc(ndo);
}
static void
-rtp_print(netdissect_options *ndo, const void *hdr, u_int len,
- const struct udphdr *up)
+rtp_print(netdissect_options *ndo, const void *hdr, u_int len)
{
/* rtp v1 or v2 */
const u_int *ip = (const u_int *)hdr;
uint32_t i0, i1;
const char * ptype;
+ ndo->ndo_protocol = "rtp";
+ if (len < 8) {
+ ND_PRINT("udp/rtp, length %u < 8", len);
+ return;
+ }
ND_TCHECK_4(&((const u_int *)hdr)[0]);
i0 = EXTRACT_BE_U_4(&((const u_int *)hdr)[0]);
ND_TCHECK_4(&((const u_int *)hdr)[1]);
i1 = EXTRACT_BE_U_4(&((const u_int *)hdr)[1]);
- ND_TCHECK_2(up->uh_ulen);
- dlen = EXTRACT_BE_U_2(up->uh_ulen) - sizeof(*up) - 8;
+ dlen = len - 8;
ip += 2;
len >>= 2;
len -= 2;
ptype = "rtpv1";
} else {
/* rtp v2 - RFC 3550 */
+ if (dlen < 4) {
+ ND_PRINT("udp/rtp, length %u < 12", dlen + 8);
+ return;
+ }
hasext = i0 & 0x10000000;
contype = (i0 >> 16) & 0x7f;
hasmarker = i0 & 0x800000;
ip += 1;
len -= 1;
}
- ND_PRINT("udp/%s %d c%d %s%s %d %u",
+ ND_PRINT("udp/%s %u c%u %s%s %u %u",
ptype,
dlen,
contype,
if (contype == 0x1f) /*XXX H.261 */
ND_PRINT(" 0x%04x", EXTRACT_BE_U_4(ip) >> 16);
}
+ return;
trunc:
- ND_PRINT("%s", rtp_tstr);
+ nd_print_trunc(ndo);
}
static const u_char *
const struct rtcphdr *rh = (const struct rtcphdr *)hdr;
u_int len;
uint16_t flags;
- int cnt;
+ u_int cnt;
double ts, dts;
+
+ ndo->ndo_protocol = "rtcp";
if ((const u_char *)(rh + 1) > ep)
goto trunc;
ND_TCHECK_SIZE(rh);
sr = (const struct rtcp_sr *)(rh + 1);
ND_PRINT(" sr");
if (len != cnt * sizeof(*rr) + sizeof(*sr) + sizeof(*rh))
- ND_PRINT(" [%d]", len);
+ ND_PRINT(" [%u]", len);
if (ndo->ndo_vflag)
ND_PRINT(" %u", EXTRACT_BE_U_4(rh->rh_ssrc));
if ((const u_char *)(sr + 1) > ep)
case RTCP_PT_RR:
ND_PRINT(" rr");
if (len != cnt * sizeof(*rr) + sizeof(*rh))
- ND_PRINT(" [%d]", len);
+ ND_PRINT(" [%u]", len);
rr = (const struct rtcp_rr *)(rh + 1);
if (ndo->ndo_vflag)
ND_PRINT(" %u", EXTRACT_BE_U_4(rh->rh_ssrc));
break;
case RTCP_PT_SDES:
- ND_PRINT(" sdes %d", len);
+ ND_PRINT(" sdes %u", len);
if (ndo->ndo_vflag)
ND_PRINT(" %u", EXTRACT_BE_U_4(rh->rh_ssrc));
cnt = 0;
break;
case RTCP_PT_BYE:
- ND_PRINT(" bye %d", len);
+ ND_PRINT(" bye %u", len);
if (ndo->ndo_vflag)
ND_PRINT(" %u", EXTRACT_BE_U_4(rh->rh_ssrc));
cnt = 0;
break;
default:
- ND_PRINT(" type-0x%x %d", flags & 0xff, len);
+ ND_PRINT(" type-0x%x %u", flags & 0xff, len);
cnt = 0;
break;
}
if (cnt > 1)
- ND_PRINT(" c%d", cnt);
- while (--cnt >= 0) {
+ ND_PRINT(" c%u", cnt);
+ while (cnt != 0) {
if ((const u_char *)(rr + 1) > ep)
goto trunc;
ND_TCHECK_SIZE(rr);
EXTRACT_BE_U_4(rr->rr_nl) & 0x00ffffff,
EXTRACT_BE_U_4(rr->rr_ls),
EXTRACT_BE_U_4(rr->rr_dv), ts, dts);
+ cnt--;
}
return (hdr + len);
trunc:
- ND_PRINT("%s", rtcp_tstr);
+ nd_print_trunc(ndo);
return ep;
}
if (EXTRACT_U_1(ip6->ip6_nxt) == IPPROTO_UDP) {
if (sport == -1) {
ND_PRINT("%s > %s: ",
- ip6addr_string(ndo, &ip6->ip6_src),
- ip6addr_string(ndo, &ip6->ip6_dst));
+ ip6addr_string(ndo, ip6->ip6_src),
+ ip6addr_string(ndo, ip6->ip6_dst));
} else {
ND_PRINT("%s.%s > %s.%s: ",
- ip6addr_string(ndo, &ip6->ip6_src),
+ ip6addr_string(ndo, ip6->ip6_src),
udpport_string(ndo, sport),
- ip6addr_string(ndo, &ip6->ip6_dst),
+ ip6addr_string(ndo, ip6->ip6_dst),
udpport_string(ndo, dport));
}
} else {
if (EXTRACT_U_1(ip->ip_p) == IPPROTO_UDP) {
if (sport == -1) {
ND_PRINT("%s > %s: ",
- ipaddr_string(ndo, &ip->ip_src),
- ipaddr_string(ndo, &ip->ip_dst));
+ ipaddr_string(ndo, ip->ip_src),
+ ipaddr_string(ndo, ip->ip_dst));
} else {
ND_PRINT("%s.%s > %s.%s: ",
- ipaddr_string(ndo, &ip->ip_src),
+ ipaddr_string(ndo, ip->ip_src),
udpport_string(ndo, sport),
- ipaddr_string(ndo, &ip->ip_dst),
+ ipaddr_string(ndo, ip->ip_dst),
udpport_string(ndo, dport));
}
} else {
const struct udphdr *up;
const struct ip *ip;
const u_char *cp;
- const u_char *ep = bp + length;
+ const u_char *ep = ndo->ndo_snapend;
uint16_t sport, dport, ulen;
const struct ip6_hdr *ip6;
- if (ep > ndo->ndo_snapend)
- ep = ndo->ndo_snapend;
+ ndo->ndo_protocol = "udp";
up = (const struct udphdr *)bp;
ip = (const struct ip *)bp2;
if (IP_V(ip) == 6)
ip6 = (const struct ip6_hdr *)bp2;
else
ip6 = NULL;
- if (!ND_TTEST(up->uh_dport)) {
+ if (!ND_TTEST_2(up->uh_dport)) {
udpipaddr_print(ndo, ip, -1, -1);
goto trunc;
}
if (length < sizeof(struct udphdr)) {
udpipaddr_print(ndo, ip, sport, dport);
- ND_PRINT("truncated-udp %d", length);
+ ND_PRINT("truncated-udp %u", length);
return;
}
- if (!ND_TTEST(up->uh_ulen)) {
+ if (!ND_TTEST_2(up->uh_ulen)) {
udpipaddr_print(ndo, ip, sport, dport);
goto trunc;
}
ulen = EXTRACT_BE_U_2(up->uh_ulen);
if (ulen < sizeof(struct udphdr)) {
udpipaddr_print(ndo, ip, sport, dport);
- ND_PRINT("truncated-udplength %d", ulen);
+ ND_PRINT("truncated-udplength %u", ulen);
return;
}
ulen -= sizeof(struct udphdr);
case PT_VAT:
udpipaddr_print(ndo, ip, sport, dport);
- vat_print(ndo, (const void *)(up + 1), up);
+ vat_print(ndo, (const void *)(up + 1), length);
break;
case PT_WB:
case PT_RPC:
rp = (const struct sunrpc_msg *)(up + 1);
- direction = (enum sunrpc_msg_type) EXTRACT_BE_U_4(&rp->rm_direction);
+ ND_TCHECK_4(rp->rm_direction);
+ direction = (enum sunrpc_msg_type) EXTRACT_BE_U_4(rp->rm_direction);
if (direction == SUNRPC_CALL)
sunrpc_print(ndo, (const u_char *)rp, length,
(const u_char *)ip);
case PT_RTP:
udpipaddr_print(ndo, ip, sport, dport);
- rtp_print(ndo, (const void *)(up + 1), length, up);
+ rtp_print(ndo, (const void *)(up + 1), length);
break;
case PT_RTCP:
enum sunrpc_msg_type direction;
rp = (const struct sunrpc_msg *)(up + 1);
- if (ND_TTEST(rp->rm_direction)) {
- direction = (enum sunrpc_msg_type) EXTRACT_BE_U_4(&rp->rm_direction);
+ if (ND_TTEST_4(rp->rm_direction)) {
+ direction = (enum sunrpc_msg_type) EXTRACT_BE_U_4(rp->rm_direction);
if (dport == NFS_PORT && direction == SUNRPC_CALL) {
- ND_PRINT("NFS request xid %u ", EXTRACT_BE_U_4(&rp->rm_xid));
+ ND_PRINT("NFS request xid %u ",
+ EXTRACT_BE_U_4(rp->rm_xid));
nfsreq_noaddr_print(ndo, (const u_char *)rp, length,
(const u_char *)ip);
return;
}
if (sport == NFS_PORT && direction == SUNRPC_REPLY) {
- ND_PRINT("NFS reply xid %u ", EXTRACT_BE_U_4(&rp->rm_xid));
+ ND_PRINT("NFS reply xid %u ",
+ EXTRACT_BE_U_4(rp->rm_xid));
nfsreply_noaddr_print(ndo, (const u_char *)rp, length,
(const u_char *)ip);
return;
* TCP does, and we do so for UDP-over-IPv6.
*/
if (IP_V(ip) == 4 && (ndo->ndo_vflag > 1)) {
+ ND_TCHECK_2(up->uh_sum);
udp_sum = EXTRACT_BE_U_2(up->uh_sum);
if (udp_sum == 0) {
ND_PRINT("[no cksum] ");
/* for IPv6, UDP checksum is mandatory */
if (ND_TTEST_LEN(cp, length)) {
sum = udp6_cksum(ndo, ip6, up, length + sizeof(struct udphdr));
+ ND_TCHECK_2(up->uh_sum);
udp_sum = EXTRACT_BE_U_2(up->uh_sum);
if (sum != 0) {
else if (IS_SRC_OR_DST_PORT(NTP_PORT))
ntp_print(ndo, (const u_char *)(up + 1), length);
else if (IS_SRC_OR_DST_PORT(KERBEROS_PORT) || IS_SRC_OR_DST_PORT(KERBEROS_SEC_PORT))
- krb_print(ndo, (const void *)(up + 1));
+ krb_print(ndo, (const u_char *)(up + 1));
else if (IS_SRC_OR_DST_PORT(L2TP_PORT))
l2tp_print(ndo, (const u_char *)(up + 1), length);
#ifdef ENABLE_SMB
nbt_udp138_print(ndo, (const u_char *)(up + 1), length);
#endif
else if (dport == VAT_PORT)
- vat_print(ndo, (const void *)(up + 1), up);
+ vat_print(ndo, (const void *)(up + 1), length);
else if (IS_SRC_OR_DST_PORT(ZEPHYR_SRV_PORT) || IS_SRC_OR_DST_PORT(ZEPHYR_CLT_PORT))
- zephyr_print(ndo, (const void *)(up + 1), length);
+ zephyr_print(ndo, (const u_char *)(up + 1), length);
/*
* Since there are 10 possible ports to check, I think
* a <> test would be more efficient
*/
else if ((sport >= RX_PORT_LOW && sport <= RX_PORT_HIGH) ||
(dport >= RX_PORT_LOW && dport <= RX_PORT_HIGH))
- rx_print(ndo, (const void *)(up + 1), length, sport, dport,
+ rx_print(ndo, (const u_char *)(up + 1), length, sport, dport,
(const u_char *) ip);
else if (IS_SRC_OR_DST_PORT(RIPNG_PORT))
ripng_print(ndo, (const u_char *)(up + 1), length);
else if (dport == WB_PORT)
wb_print(ndo, (const u_char *)(up + 1), length);
else if (IS_SRC_OR_DST_PORT(CISCO_AUTORP_PORT))
- cisco_autorp_print(ndo, (const void *)(up + 1), length);
+ cisco_autorp_print(ndo, (const u_char *)(up + 1), length);
else if (IS_SRC_OR_DST_PORT(RADIUS_PORT) ||
IS_SRC_OR_DST_PORT(RADIUS_NEW_PORT) ||
IS_SRC_OR_DST_PORT(RADIUS_ACCOUNTING_PORT) ||
lisp_print(ndo, (const u_char *)(up + 1), length);
else if (IS_SRC_OR_DST_PORT(VXLAN_GPE_PORT))
vxlan_gpe_print(ndo, (const u_char *)(up + 1), length);
- else if (ND_TTEST(((const struct LAP *)cp)->type) &&
- EXTRACT_U_1(((const struct LAP *)cp)->type) == lapDDP &&
- (atalk_port(sport) || atalk_port(dport))) {
+ else if (IS_SRC_OR_DST_PORT(ZEP_PORT))
+ zep_print(ndo, (const u_char *)(up + 1), length);
+ else if (ND_TTEST_1(((const struct LAP *)cp)->type) &&
+ EXTRACT_U_1(((const struct LAP *)cp)->type) == lapDDP &&
+ (atalk_port(sport) || atalk_port(dport))) {
if (ndo->ndo_vflag)
ND_PRINT("kip ");
llap_print(ndo, cp, length);
return;
trunc:
- ND_PRINT("%s", udp_tstr);
+ nd_print_trunc(ndo);
}
-
-
-/*
- * Local Variables:
- * c-style: whitesmith
- * c-basic-offset: 8
- * End:
- */