]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-vsock.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / print-vsock.c
index 5f0209b2465b1a020d0ab0b1beef201f45c62305..d232a51b0c65ed05d341f599c76568f4b5d8247b 100644 (file)
 
 /* \summary: Linux vsock printer */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 #include <stddef.h>
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "extract.h"
 
@@ -148,12 +147,15 @@ vsock_virtio_hdr_print(netdissect_options *ndo, const struct virtio_vsock_hdr *h
        ND_PRINT(", fwd_cnt %u", u32_v);
 }
 
-static size_t
+/*
+ * This size had better fit in a u_int.
+ */
+static u_int
 vsock_transport_hdr_size(uint16_t transport)
 {
        switch (transport) {
                case AF_VSOCK_TRANSPORT_VIRTIO:
-                       return sizeof(struct virtio_vsock_hdr);
+                       return (u_int)sizeof(struct virtio_vsock_hdr);
                default:
                        return 0;
        }
@@ -162,12 +164,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)
 {
-       size_t transport_size = vsock_transport_hdr_size(transport);
+       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;
        }
 
@@ -185,13 +187,13 @@ 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;
        uint32_t hdr_src_port, hdr_dst_port;
        uint64_t hdr_src_cid, hdr_dst_cid;
-       size_t total_hdr_size;
+       u_int total_hdr_size;
        int ret = 0;
 
        hdr_transport = GET_LE_U_2(hdr->transport);
@@ -201,7 +203,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
@@ -216,21 +218,22 @@ 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;
 
        /* If debug level is more than 1 print payload contents */
-       total_hdr_size = sizeof(struct af_vsockmon_hdr) +
+       /* This size had better fit in a u_int */
+       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;
        }
@@ -240,18 +243,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);
 }