X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/2ac0770c0d953b98414f80a45889a44f7e9606fd..refs/pull/1034/head:/print-vsock.c diff --git a/print-vsock.c b/print-vsock.c index f93e0a2e..1fd09fce 100644 --- a/print-vsock.c +++ b/print-vsock.c @@ -30,6 +30,7 @@ #include "netdissect-stdinc.h" #include +#define ND_LONGJMP_FROM_TCHECK #include "netdissect.h" #include "extract.h" @@ -165,12 +166,12 @@ vsock_transport_hdr_size(uint16_t transport) /* Returns 0 on success, -1 on truncation */ static int vsock_transport_hdr_print(netdissect_options *ndo, uint16_t transport, - const u_char *p, const u_int len) + const u_char *p, const u_int caplen) { u_int transport_size = vsock_transport_hdr_size(transport); const void *hdr; - if (len < sizeof(struct af_vsockmon_hdr) + transport_size) { + if (caplen < sizeof(struct af_vsockmon_hdr) + transport_size) { return -1; } @@ -188,7 +189,7 @@ vsock_transport_hdr_print(netdissect_options *ndo, uint16_t transport, } static void -vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len) +vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int caplen) { const struct af_vsockmon_hdr *hdr = (const struct af_vsockmon_hdr *)p; uint16_t hdr_transport, hdr_op; @@ -204,7 +205,7 @@ vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len) /* If verbose level is more than 0 print transport details */ if (ndo->ndo_vflag) { - ret = vsock_transport_hdr_print(ndo, hdr_transport, p, len); + ret = vsock_transport_hdr_print(ndo, hdr_transport, p, caplen); if (ret == 0) ND_PRINT("\n\t"); } else @@ -219,7 +220,7 @@ vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len) hdr_src_cid, hdr_src_port, hdr_dst_cid, hdr_dst_port, tok2str(vsock_op, " invalid op (%u)", hdr_op), - len); + caplen); if (ret < 0) goto trunc; @@ -229,12 +230,12 @@ vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len) total_hdr_size = (u_int)sizeof(struct af_vsockmon_hdr) + vsock_transport_hdr_size(hdr_transport); if (ndo->ndo_vflag > 1 && hdr_op == AF_VSOCK_OP_PAYLOAD) { - if (len > total_hdr_size) { + if (caplen > total_hdr_size) { const u_char *payload = p + total_hdr_size; ND_PRINT("\n"); print_unknown_data(ndo, payload, "\t", - len - total_hdr_size); + caplen - total_hdr_size); } else goto trunc; } @@ -244,18 +245,13 @@ trunc: nd_print_trunc(ndo); } -u_int +void vsock_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *cp) { - u_int len = h->caplen; - ndo->ndo_protocol = "vsock"; - if (len < sizeof(struct af_vsockmon_hdr)) - nd_print_trunc(ndo); - else - vsock_hdr_print(ndo, cp, len); - - return len; + ND_TCHECK_LEN(cp, sizeof(struct af_vsockmon_hdr)); + ndo->ndo_ll_hdr_len += sizeof(struct af_vsockmon_hdr); + vsock_hdr_print(ndo, cp, h->caplen); }