]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-vsock.c
man: Add an example for printing TCP with RST+ACK both set
[tcpdump] / print-vsock.c
index 6d8a44e1433e7ada1af03d658e777988b9ad1b36..f93e0a2eb5c05e8e8fc2d4df1b74a0268a66d80f 100644 (file)
@@ -24,7 +24,7 @@
 /* \summary: Linux vsock printer */
 
 #ifdef HAVE_CONFIG_H
 /* \summary: Linux vsock printer */
 
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
 #include "netdissect-stdinc.h"
 #endif
 
 #include "netdissect-stdinc.h"
@@ -127,33 +127,36 @@ vsock_virtio_hdr_print(netdissect_options *ndo, const struct virtio_vsock_hdr *h
        uint16_t u16_v;
        uint32_t u32_v;
 
        uint16_t u16_v;
        uint32_t u32_v;
 
-       u32_v = GET_LE_U_4(&hdr->len);
+       u32_v = GET_LE_U_4(hdr->len);
        ND_PRINT("len %u", u32_v);
 
        ND_PRINT("len %u", u32_v);
 
-       u16_v = GET_LE_U_2(&hdr->type);
+       u16_v = GET_LE_U_2(hdr->type);
        ND_PRINT(", type %s",
                 tok2str(virtio_type, "Invalid type (%hu)", u16_v));
 
        ND_PRINT(", type %s",
                 tok2str(virtio_type, "Invalid type (%hu)", u16_v));
 
-       u16_v = GET_LE_U_2(&hdr->op);
+       u16_v = GET_LE_U_2(hdr->op);
        ND_PRINT(", op %s",
                 tok2str(virtio_op, "Invalid op (%hu)", u16_v));
 
        ND_PRINT(", op %s",
                 tok2str(virtio_op, "Invalid op (%hu)", u16_v));
 
-       u32_v = GET_LE_U_4(&hdr->flags);
+       u32_v = GET_LE_U_4(hdr->flags);
        ND_PRINT(", flags %x", u32_v);
 
        ND_PRINT(", flags %x", u32_v);
 
-       u32_v = GET_LE_U_4(&hdr->buf_alloc);
+       u32_v = GET_LE_U_4(hdr->buf_alloc);
        ND_PRINT(", buf_alloc %u", u32_v);
 
        ND_PRINT(", buf_alloc %u", u32_v);
 
-       u32_v = GET_LE_U_4(&hdr->fwd_cnt);
+       u32_v = GET_LE_U_4(hdr->fwd_cnt);
        ND_PRINT(", fwd_cnt %u", u32_v);
 }
 
        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:
 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;
        }
                default:
                        return 0;
        }
@@ -164,7 +167,7 @@ static int
 vsock_transport_hdr_print(netdissect_options *ndo, uint16_t transport,
                           const u_char *p, const u_int len)
 {
 vsock_transport_hdr_print(netdissect_options *ndo, uint16_t transport,
                           const u_char *p, const u_int len)
 {
-       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) {
        const void *hdr;
 
        if (len < sizeof(struct af_vsockmon_hdr) + transport_size) {
@@ -191,10 +194,10 @@ vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len)
        uint16_t hdr_transport, hdr_op;
        uint32_t hdr_src_port, hdr_dst_port;
        uint64_t hdr_src_cid, hdr_dst_cid;
        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;
 
        int ret = 0;
 
-       hdr_transport = GET_LE_U_2(&hdr->transport);
+       hdr_transport = GET_LE_U_2(hdr->transport);
        ND_PRINT("%s",
                 tok2str(vsock_transport, "Invalid transport (%u)",
                          hdr_transport));
        ND_PRINT("%s",
                 tok2str(vsock_transport, "Invalid transport (%u)",
                          hdr_transport));
@@ -207,11 +210,11 @@ vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len)
        } else
                ND_PRINT(" ");
 
        } else
                ND_PRINT(" ");
 
-       hdr_src_cid = GET_LE_U_8(&hdr->src_cid);
-       hdr_dst_cid = GET_LE_U_8(&hdr->dst_cid);
-       hdr_src_port = GET_LE_U_4(&hdr->src_port);
-       hdr_dst_port = GET_LE_U_4(&hdr->dst_port);
-       hdr_op = GET_LE_U_2(&hdr->op);
+       hdr_src_cid = GET_LE_U_8(hdr->src_cid);
+       hdr_dst_cid = GET_LE_U_8(hdr->dst_cid);
+       hdr_src_port = GET_LE_U_4(hdr->src_port);
+       hdr_dst_port = GET_LE_U_4(hdr->dst_port);
+       hdr_op = GET_LE_U_2(hdr->op);
        ND_PRINT("%" PRIu64 ".%u > %" PRIu64 ".%u %s, length %u",
                 hdr_src_cid, hdr_src_port,
                 hdr_dst_cid, hdr_dst_port,
        ND_PRINT("%" PRIu64 ".%u > %" PRIu64 ".%u %s, length %u",
                 hdr_src_cid, hdr_src_port,
                 hdr_dst_cid, hdr_dst_port,
@@ -222,7 +225,8 @@ vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len)
                goto trunc;
 
        /* If debug level is more than 1 print payload contents */
                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) {
                         vsock_transport_hdr_size(hdr_transport);
        if (ndo->ndo_vflag > 1 && hdr_op == AF_VSOCK_OP_PAYLOAD) {
                if (len > total_hdr_size) {