]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-smb.c
Default to first interface from pcap_findalldevs()
[tcpdump] / print-smb.c
index e4bacbbc253f5c57946f952cac35b437bb58966b..0147b20d65e71759e474fde9812d4ed34fd4e2c7 100644 (file)
@@ -6,16 +6,15 @@
  * or later
  */
 
-#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include <tcpdump-stdinc.h>
+#include <netdissect-stdinc.h>
 
 #include <string.h>
 
-#include "interface.h"
+#include "netdissect.h"
 #include "extract.h"
 #include "smb.h"
 
@@ -100,7 +99,7 @@ trans2_findfirst(netdissect_options *ndo,
     smb_fdata(ndo, param, fmt, param + pcnt, unicodestr);
     if (dcnt) {
        ND_PRINT((ndo, "data:\n"));
-       print_data(ndo, data, dcnt);
+       smb_print_data(ndo, data, dcnt);
     }
 }
 
@@ -135,7 +134,7 @@ trans2_qfsinfo(netdissect_options *ndo,
     }
     if (dcnt) {
        ND_PRINT((ndo, "data:\n"));
-       print_data(ndo, data, dcnt);
+       smb_print_data(ndo, data, dcnt);
     }
     return;
 trunc:
@@ -416,7 +415,7 @@ print_negprot(netdissect_options *ndo,
        smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf),
            unicodestr);
     else
-       print_data(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
+       smb_print_data(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
 
     ND_TCHECK2(*data, 2);
     bcc = EXTRACT_LE_16BITS(data);
@@ -426,7 +425,7 @@ print_negprot(netdissect_options *ndo,
            smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data),
                maxbuf), unicodestr);
        else
-           print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
+           smb_print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
     }
     return;
 trunc:
@@ -460,7 +459,7 @@ print_sesssetup(netdissect_options *ndo,
        smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf),
            unicodestr);
     else
-       print_data(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
+       smb_print_data(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
 
     ND_TCHECK2(*data, 2);
     bcc = EXTRACT_LE_16BITS(data);
@@ -470,7 +469,7 @@ print_sesssetup(netdissect_options *ndo,
            smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data),
                maxbuf), unicodestr);
        else
-           print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
+           smb_print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
     }
     return;
 trunc:
@@ -510,7 +509,7 @@ print_lockingandx(netdissect_options *ndo,
            smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data),
                maxbuf), unicodestr);
        else
-           print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
+           smb_print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
     }
     return;
 trunc:
@@ -793,10 +792,10 @@ static void
 print_smb(netdissect_options *ndo,
           const u_char *buf, const u_char *maxbuf)
 {
-    u_int16_t flags2;
+    uint16_t flags2;
     int nterrcodes;
     int command;
-    u_int32_t nterror;
+    uint32_t nterror;
     const u_char *words, *maxwords, *data;
     const struct smbfns *fn;
     const char *fmt_smbheader =
@@ -883,7 +882,7 @@ print_smb(netdissect_options *ndo,
            } else {
                if (bcc > 0) {
                    ND_PRINT((ndo, "smb_buf[]=\n"));
-                   print_data(ndo, data + 2, min(bcc, PTR_DIFF(maxbuf, data + 2)));
+                   smb_print_data(ndo, data + 2, min(bcc, PTR_DIFF(maxbuf, data + 2)));
                }
            }
        }
@@ -1079,6 +1078,16 @@ trunc:
     ND_PRINT((ndo, "%s", tstr));
 }
 
+static const struct tok opcode_str[] = {
+       { 0,  "QUERY"                   },
+       { 5,  "REGISTRATION"            },
+       { 6,  "RELEASE"                 },
+       { 7,  "WACK"                    },
+       { 8,  "REFRESH(8)"              },
+       { 9,  "REFRESH"                 },
+       { 15, "MULTIHOMED REGISTRATION" },
+       { 0, NULL }
+};
 
 /*
  * print a NBT packet received across udp on port 137
@@ -1090,7 +1099,6 @@ nbt_udp137_print(netdissect_options *ndo,
     const u_char *maxbuf = data + length;
     int name_trn_id, response, opcode, nm_flags, rcode;
     int qdcount, ancount, nscount, arcount;
-    const char *opcodestr;
     const u_char *p;
     int total, i;
 
@@ -1112,35 +1120,12 @@ nbt_udp137_print(netdissect_options *ndo,
     if (ndo->ndo_vflag > 1)
        ND_PRINT((ndo, "\n>>> "));
 
-    ND_PRINT((ndo, "NBT UDP PACKET(137): "));
-
-    switch (opcode) {
-    case 0: opcodestr = "QUERY"; break;
-    case 5: opcodestr = "REGISTRATION"; break;
-    case 6: opcodestr = "RELEASE"; break;
-    case 7: opcodestr = "WACK"; break;
-    case 8: opcodestr = "REFRESH(8)"; break;
-    case 9: opcodestr = "REFRESH"; break;
-    case 15: opcodestr = "MULTIHOMED REGISTRATION"; break;
-    default: opcodestr = "OPUNKNOWN"; break;
-    }
-    ND_PRINT((ndo, "%s", opcodestr));
+    ND_PRINT((ndo, "NBT UDP PACKET(137): %s", tok2str(opcode_str, "OPUNKNOWN", opcode)));
     if (response) {
-       if (rcode)
-           ND_PRINT((ndo, "; NEGATIVE"));
-       else
-           ND_PRINT((ndo, "; POSITIVE"));
+        ND_PRINT((ndo, "; %s", rcode ? "NEGATIVE" : "POSITIVE"));
     }
-
-    if (response)
-       ND_PRINT((ndo, "; RESPONSE"));
-    else
-       ND_PRINT((ndo, "; REQUEST"));
-
-    if (nm_flags & 1)
-       ND_PRINT((ndo, "; BROADCAST"));
-    else
-       ND_PRINT((ndo, "; UNICAST"));
+    ND_PRINT((ndo, "; %s; %s", response ? "RESPONSE" : "REQUEST",
+              (nm_flags & 1) ? "BROADCAST" : "UNICAST"));
 
     if (ndo->ndo_vflag < 2)
        return;
@@ -1223,7 +1208,7 @@ nbt_udp137_print(netdissect_options *ndo,
                        p += 2;
                    }
                } else {
-                   print_data(ndo, p, min(rdlen, length - (p - data)));
+                   smb_print_data(ndo, p, min(rdlen, length - (p - data)));
                    p += rdlen;
                }
            }
@@ -1269,14 +1254,15 @@ smb_tcp_print(netdissect_options *ndo,
     if (smb_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) {
        if ((int)smb_len > caplen) {
            if ((int)smb_len > length)
-               ND_PRINT((ndo, "WARNING: Packet is continued in later TCP segments\n"));
+               ND_PRINT((ndo, " WARNING: Packet is continued in later TCP segments\n"));
            else
-               ND_PRINT((ndo, "WARNING: Short packet. Try increasing the snap length by %d\n",
+               ND_PRINT((ndo, " WARNING: Short packet. Try increasing the snap length by %d\n",
                    smb_len - caplen));
-       }
+       } else
+           ND_PRINT((ndo, " "));
        print_smb(ndo, data, maxbuf > data + smb_len ? data + smb_len : maxbuf);
     } else
-       ND_PRINT((ndo, "SMB-over-TCP packet:(raw data or continuation?)\n"));
+       ND_PRINT((ndo, " SMB-over-TCP packet:(raw data or continuation?)\n"));
     return;
 trunc:
     ND_PRINT((ndo, "%s", tstr));