]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-smb.c
Use more the EXTRACT_8BITS() macro to fetch a one-byte value (17/n)
[tcpdump] / print-smb.c
index 7330d6b528335b644b01f92ddd4d145087777b99..a89c514a3d2d787d2eba1b879bf69e11d7eb7fd8 100644 (file)
@@ -6,6 +6,8 @@
  * or later
  */
 
+/* \summary: SMB/CIFS printer */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -99,7 +101,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);
     }
 }
 
@@ -134,7 +136,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:
@@ -415,7 +417,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);
@@ -425,7 +427,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:
@@ -459,7 +461,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);
@@ -469,7 +471,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:
@@ -509,7 +511,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:
@@ -804,9 +806,6 @@ print_smb(netdissect_options *ndo,
 
     ND_TCHECK(buf[9]);
     request = (buf[9] & 0x80) ? 0 : 1;
-    flags2 = EXTRACT_LE_16BITS(&buf[10]);
-    unicodestr = flags2 & 0x8000;
-    nterrcodes = flags2 & 0x4000;
     startbuf = buf;
 
     command = buf[4];
@@ -821,16 +820,21 @@ print_smb(netdissect_options *ndo,
     if (ndo->ndo_vflag < 2)
        return;
 
+    ND_TCHECK_16BITS(&buf[10]);
+    flags2 = EXTRACT_LE_16BITS(buf + 10);
+    unicodestr = flags2 & 0x8000;
+    nterrcodes = flags2 & 0x4000;
+
     /* print out the header */
     smb_fdata(ndo, buf, fmt_smbheader, buf + 33, unicodestr);
 
     if (nterrcodes) {
-       nterror = EXTRACT_LE_32BITS(&buf[5]);
+       nterror = EXTRACT_LE_32BITS(buf + 5);
        if (nterror)
            ND_PRINT((ndo, "NTError = %s\n", nt_errstr(nterror)));
     } else {
        if (buf[5])
-           ND_PRINT((ndo, "SMBError = %s\n", smb_errstr(buf[5], EXTRACT_LE_16BITS(&buf[7]))));
+           ND_PRINT((ndo, "SMBError = %s\n", smb_errstr(buf[5], EXTRACT_LE_16BITS(buf + 7))));
     }
 
     smboffset = 32;
@@ -882,7 +886,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)));
                }
            }
        }
@@ -937,7 +941,7 @@ nbt_tcp_print(netdissect_options *ndo,
        goto trunc;
     maxbuf = data + caplen;
     type = data[0];
-    nbt_len = EXTRACT_16BITS(data + 2);
+    nbt_len = EXTRACT_BE_16BITS(data + 2);
     length -= 4;
     caplen -= 4;
 
@@ -1103,15 +1107,15 @@ nbt_udp137_print(netdissect_options *ndo,
     int total, i;
 
     ND_TCHECK2(data[10], 2);
-    name_trn_id = EXTRACT_16BITS(data);
+    name_trn_id = EXTRACT_BE_16BITS(data);
     response = (data[2] >> 7);
     opcode = (data[2] >> 3) & 0xF;
     nm_flags = ((data[2] & 0x7) << 4) + (data[3] >> 4);
     rcode = data[3] & 0xF;
-    qdcount = EXTRACT_16BITS(data + 4);
-    ancount = EXTRACT_16BITS(data + 6);
-    nscount = EXTRACT_16BITS(data + 8);
-    arcount = EXTRACT_16BITS(data + 10);
+    qdcount = EXTRACT_BE_16BITS(data + 4);
+    ancount = EXTRACT_BE_16BITS(data + 6);
+    nscount = EXTRACT_BE_16BITS(data + 8);
+    arcount = EXTRACT_BE_16BITS(data + 10);
     startbuf = data;
 
     if (maxbuf <= data)
@@ -1163,11 +1167,13 @@ nbt_udp137_print(netdissect_options *ndo,
            p = smb_fdata(ndo, p, "Name=[n1]\n#", maxbuf, 0);
            if (p == NULL)
                goto out;
-           restype = EXTRACT_16BITS(p);
+           ND_TCHECK_16BITS(p);
+           restype = EXTRACT_BE_16BITS(p);
            p = smb_fdata(ndo, p, "ResType=[rw]\nResClass=[rw]\nTTL=[rD]\n", p + 8, 0);
            if (p == NULL)
                goto out;
-           rdlen = EXTRACT_16BITS(p);
+           ND_TCHECK_16BITS(p);
+           rdlen = EXTRACT_BE_16BITS(p);
            ND_PRINT((ndo, "ResourceLength=%d\nResourceData=\n", rdlen));
            p += 2;
            if (rdlen == 6) {
@@ -1208,7 +1214,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;
                }
            }
@@ -1244,7 +1250,7 @@ smb_tcp_print(netdissect_options *ndo,
     if (caplen < 4)
        goto trunc;
     maxbuf = data + caplen;
-    smb_len = EXTRACT_24BITS(data + 1);
+    smb_len = EXTRACT_BE_24BITS(data + 1);
     length -= 4;
     caplen -= 4;
 
@@ -1308,7 +1314,7 @@ out:
 /*
    print netbeui frames
 */
-struct nbf_strings {
+static struct nbf_strings {
        const char      *name;
        const char      *nonverbose;
        const char      *verbose;