]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Clean up signed vs. unsigned.
authorGuy Harris <[email protected]>
Sun, 7 Jan 2018 06:18:00 +0000 (22:18 -0800)
committerGuy Harris <[email protected]>
Sun, 7 Jan 2018 06:18:00 +0000 (22:18 -0800)
Use unsigned for lengths.  Add additional length checks, as we can no
longer cheat and rely on "underflow turns the length negative, so just
check for > 0".

Show most NBT and SMB numerical fields as unsigned, as that's what they
are.  Have "d" and "D" treat the value as signed; add "u" and "U" for
unsigned values.

netdissect.h
print-smb.c
smbutil.c

index c1e4eaee0bc6fe5204d1a835010347aa6a83bfb7..d6800a50c3b8f9a854a5a9f047b03606e71dd97e 100644 (file)
@@ -594,10 +594,10 @@ extern void mpls_print(netdissect_options *, const u_char *, u_int);
 extern int mptcp_print(netdissect_options *, const u_char *, u_int, u_char);
 extern void msdp_print(netdissect_options *, const u_char *, u_int);
 extern void msnlb_print(netdissect_options *, const u_char *);
-extern void nbt_tcp_print(netdissect_options *, const u_char *, int);
-extern void nbt_udp137_print(netdissect_options *, const u_char *, int);
-extern void nbt_udp138_print(netdissect_options *, const u_char *, int);
-extern void netbeui_print(netdissect_options *, u_short, const u_char *, int);
+extern void nbt_tcp_print(netdissect_options *, const u_char *, u_int);
+extern void nbt_udp137_print(netdissect_options *, const u_char *, u_int);
+extern void nbt_udp138_print(netdissect_options *, const u_char *, u_int);
+extern void netbeui_print(netdissect_options *, u_short, const u_char *, u_int);
 extern void nfsreply_print(netdissect_options *, const u_char *, u_int, const u_char *);
 extern void nfsreply_noaddr_print(netdissect_options *, const u_char *, u_int, const u_char *);
 extern void nfsreq_noaddr_print(netdissect_options *, const u_char *, u_int, const u_char *);
@@ -636,8 +636,8 @@ extern void sctp_print(netdissect_options *, const u_char *, const u_char *, u_i
 extern void sflow_print(netdissect_options *, const u_char *, u_int);
 extern void sip_print(netdissect_options *, const u_char *, u_int);
 extern void slow_print(netdissect_options *, const u_char *, u_int);
-extern void smb_print_data(netdissect_options *, const u_char *, int);
-extern void smb_tcp_print(netdissect_options *, const u_char *, int);
+extern void smb_print_data(netdissect_options *, const u_char *, u_int);
+extern void smb_tcp_print(netdissect_options *, const u_char *, u_int);
 extern void smtp_print(netdissect_options *, const u_char *, u_int);
 extern int snap_print(netdissect_options *, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *, u_int);
 extern void snmp_print(netdissect_options *, const u_char *, u_int);
index b3f855bd1316242ebe4a5bd94145244a29b6246e..6c84f73336668fdd26bf223c5ee2cd49f9a579eb 100644 (file)
@@ -42,7 +42,7 @@ struct smbdescriptint {
     const char *req_f2;
     const char *rep_f1;
     const char *rep_f2;
-    void (*fn)(netdissect_options *, const u_char *, const u_char *, int, int);
+    void (*fn)(netdissect_options *, const u_char *, const u_char *, u_int, u_int);
 };
 
 struct smbfns
@@ -91,14 +91,14 @@ smbfindint(int id, const struct smbfnsint *list)
 
 static void
 trans2_findfirst(netdissect_options *ndo,
-                 const u_char *param, const u_char *data, int pcnt, int dcnt)
+                 const u_char *param, const u_char *data, u_int pcnt, u_int dcnt)
 {
     const char *fmt;
 
     if (request)
-       fmt = "Attribute=[A]\nSearchCount=[d]\nFlags=[w]\nLevel=[dP4]\nFile=[S]\n";
+       fmt = "Attribute=[A]\nSearchCount=[u]\nFlags=[w]\nLevel=[uP4]\nFile=[S]\n";
     else
-       fmt = "Handle=[w]\nCount=[d]\nEOS=[w]\nEoffset=[d]\nLastNameOfs=[w]\n";
+       fmt = "Handle=[w]\nCount=[u]\nEOS=[w]\nEoffset=[u]\nLastNameOfs=[w]\n";
 
     smb_fdata(ndo, param, fmt, param + pcnt, unicodestr);
     if (dcnt) {
@@ -109,26 +109,26 @@ trans2_findfirst(netdissect_options *ndo,
 
 static void
 trans2_qfsinfo(netdissect_options *ndo,
-               const u_char *param, const u_char *data, int pcnt, int dcnt)
+               const u_char *param, const u_char *data, u_int pcnt, u_int dcnt)
 {
-    static int level = 0;
+    static u_int level = 0;
     const char *fmt="";
 
     if (request) {
        ND_TCHECK_2(param);
        level = EXTRACT_LE_U_2(param);
-       fmt = "InfoLevel=[d]\n";
+       fmt = "InfoLevel=[u]\n";
        smb_fdata(ndo, param, fmt, param + pcnt, unicodestr);
     } else {
        switch (level) {
        case 1:
-           fmt = "idFileSystem=[W]\nSectorUnit=[D]\nUnit=[D]\nAvail=[D]\nSectorSize=[d]\n";
+           fmt = "idFileSystem=[W]\nSectorUnit=[U]\nUnit=[U]\nAvail=[U]\nSectorSize=[u]\n";
            break;
        case 2:
            fmt = "CreationTime=[T2]VolNameLength=[lb]\nVolumeLabel=[c]\n";
            break;
        case 0x105:
-           fmt = "Capabilities=[W]\nMaxFileLen=[D]\nVolNameLen=[lD]\nVolume=[C]\n";
+           fmt = "Capabilities=[W]\nMaxFileLen=[U]\nVolNameLen=[lU]\nVolume=[C]\n";
            break;
        default:
            fmt = "UnknownLevel\n";
@@ -147,9 +147,9 @@ trunc:
 
 static const struct smbfnsint trans2_fns[] = {
     { 0, "TRANSACT2_OPEN", 0,
-       { "Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[D]\nRes=([w, w, w, w, w])\nPath=[S]",
+       { "Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[U]\nRes=([w, w, w, w, w])\nPath=[S]",
          NULL,
-         "Handle=[d]\nAttrib=[A]\nTime=[T2]\nSize=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nInode=[W]\nOffErr=[d]\n|EALength=[d]\n",
+         "Handle=[u]\nAttrib=[A]\nTime=[T2]\nSize=[U]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nInode=[W]\nOffErr=[u]\n|EALength=[u]\n",
          NULL, NULL }},
     { 1, "TRANSACT2_FINDFIRST", 0,
        { NULL, NULL, NULL, NULL, trans2_findfirst }},
@@ -179,7 +179,7 @@ print_trans2(netdissect_options *ndo,
     const u_char *data, *param;
     const u_char *w = words + 1;
     const char *f1 = NULL, *f2 = NULL;
-    int pcnt, dcnt;
+    u_int pcnt, dcnt;
 
     ND_TCHECK_1(words);
     if (request) {
@@ -202,24 +202,24 @@ print_trans2(netdissect_options *ndo,
        data = buf + EXTRACT_LE_U_2(w + 7 * 2);
     }
 
-    ND_PRINT((ndo, "%s param_length=%d data_length=%d\n", fn->name, pcnt, dcnt));
+    ND_PRINT((ndo, "%s param_length=%u data_length=%u\n", fn->name, pcnt, dcnt));
 
     if (request) {
        if (EXTRACT_U_1(words) == 8) {
            smb_fdata(ndo, words + 1,
-               "Trans2Secondary\nTotParam=[d]\nTotData=[d]\nParamCnt=[d]\nParamOff=[d]\nParamDisp=[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nHandle=[d]\n",
+               "Trans2Secondary\nTotParam=[u]\nTotData=[u]\nParamCnt=[u]\nParamOff=[u]\nParamDisp=[u]\nDataCnt=[u]\nDataOff=[u]\nDataDisp=[u]\nHandle=[u]\n",
                maxbuf, unicodestr);
            return;
        } else {
            smb_fdata(ndo, words + 1,
-               "TotParam=[d]\nTotData=[d]\nMaxParam=[d]\nMaxData=[d]\nMaxSetup=[b][P1]\nFlags=[w]\nTimeOut=[D]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nDataCnt=[d]\nDataOff=[d]\nSetupCnt=[b][P1]\n",
+               "TotParam=[u]\nTotData=[u]\nMaxParam=[u]\nMaxData=[u]\nMaxSetup=[b][P1]\nFlags=[w]\nTimeOut=[D]\nRes1=[w]\nParamCnt=[u]\nParamOff=[u]\nDataCnt=[u]\nDataOff=[u]\nSetupCnt=[b][P1]\n",
                words + 1 + 14 * 2, unicodestr);
        }
        f1 = fn->descript.req_f1;
        f2 = fn->descript.req_f2;
     } else {
        smb_fdata(ndo, words + 1,
-           "TotParam=[d]\nTotData=[d]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nParamDisp[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nSetupCnt=[b][P1]\n",
+           "TotParam=[u]\nTotData=[u]\nRes1=[w]\nParamCnt=[u]\nParamOff=[u]\nParamDisp[u]\nDataCnt=[u]\nDataOff=[u]\nDataDisp=[u]\nSetupCnt=[b][P1]\n",
            words + 1 + 10 * 2, unicodestr);
        f1 = fn->descript.rep_f1;
        f2 = fn->descript.rep_f2;
@@ -241,10 +241,10 @@ trunc:
 
 static void
 print_browse(netdissect_options *ndo,
-             const u_char *param, int paramlen, const u_char *data, int datalen)
+             const u_char *param, u_int paramlen, const u_char *data, u_int datalen)
 {
     const u_char *maxbuf = data + datalen;
-    int command;
+    u_int command;
 
     ND_TCHECK_1(data);
     command = EXTRACT_U_1(data);
@@ -254,13 +254,13 @@ print_browse(netdissect_options *ndo,
     switch (command) {
     case 0xF:
        data = smb_fdata(ndo, data,
-           "BROWSE PACKET:\nType=[B] (LocalMasterAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
+           "BROWSE PACKET:\nType=[B] (LocalMasterAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[u]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
            maxbuf, unicodestr);
        break;
 
     case 0x1:
        data = smb_fdata(ndo, data,
-           "BROWSE PACKET:\nType=[B] (HostAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
+           "BROWSE PACKET:\nType=[B] (HostAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[u]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
            maxbuf, unicodestr);
        break;
 
@@ -272,7 +272,7 @@ print_browse(netdissect_options *ndo,
 
     case 0xc:
        data = smb_fdata(ndo, data,
-           "BROWSE PACKET:\nType=[B] (WorkgroupAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nCommentPointer=[W]\nServerName=[S]\n",
+           "BROWSE PACKET:\nType=[B] (WorkgroupAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[u]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nCommentPointer=[W]\nServerName=[S]\n",
            maxbuf, unicodestr);
        break;
 
@@ -323,7 +323,7 @@ trunc:
 
 static void
 print_ipc(netdissect_options *ndo,
-          const u_char *param, int paramlen, const u_char *data, int datalen)
+          const u_char *param, u_int paramlen, const u_char *data, u_int datalen)
 {
     if (paramlen)
        smb_fdata(ndo, param, "Command=[w]\nStr1=[S]\nStr2=[S]\n", param + paramlen,
@@ -341,7 +341,7 @@ print_trans(netdissect_options *ndo,
     const char *f1, *f2, *f3, *f4;
     const u_char *data, *param;
     const u_char *w = words + 1;
-    int datalen, paramlen;
+    u_int datalen, paramlen;
 
     if (request) {
        ND_TCHECK_2(w + (12 * 2));
@@ -349,7 +349,7 @@ print_trans(netdissect_options *ndo,
        param = buf + EXTRACT_LE_U_2(w + 10 * 2);
        datalen = EXTRACT_LE_U_2(w + 11 * 2);
        data = buf + EXTRACT_LE_U_2(w + 12 * 2);
-       f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nMaxParmCnt=[d] \nMaxDataCnt=[d]\nMaxSCnt=[d] \nTransFlags=[w] \nRes1=[w] \nRes2=[w] \nRes3=[w]\nParamCnt=[d] \nParamOff=[d] \nDataCnt=[d] \nDataOff=[d] \nSUCnt=[d]\n";
+       f1 = "TotParamCnt=[u] \nTotDataCnt=[u] \nMaxParmCnt=[u] \nMaxDataCnt=[u]\nMaxSCnt=[u] \nTransFlags=[w] \nRes1=[w] \nRes2=[w] \nRes3=[w]\nParamCnt=[u] \nParamOff=[u] \nDataCnt=[u] \nDataOff=[u] \nSUCnt=[u]\n";
        f2 = "|Name=[S]\n";
        f3 = "|Param ";
        f4 = "|Data ";
@@ -359,7 +359,7 @@ print_trans(netdissect_options *ndo,
        param = buf + EXTRACT_LE_U_2(w + 4 * 2);
        datalen = EXTRACT_LE_U_2(w + 6 * 2);
        data = buf + EXTRACT_LE_U_2(w + 7 * 2);
-       f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nRes1=[d]\nParamCnt=[d] \nParamOff=[d] \nRes2=[d] \nDataCnt=[d] \nDataOff=[d] \nRes3=[d]\nLsetup=[d]\n";
+       f1 = "TotParamCnt=[u] \nTotDataCnt=[u] \nRes1=[u]\nParamCnt=[u] \nParamOff=[u] \nRes2=[u] \nDataCnt=[u] \nDataOff=[u] \nRes3=[u]\nLsetup=[u]\n";
        f2 = "|Unknown ";
        f3 = "|Param ";
        f4 = "|Data ";
@@ -409,11 +409,11 @@ print_negprot(netdissect_options *ndo,
        f2 = "*|Dialect=[Y]\n";
     else {
        if (wct == 1)
-           f1 = "Core Protocol\nDialectIndex=[d]";
+           f1 = "Core Protocol\nDialectIndex=[u]";
        else if (wct == 17)
-           f1 = "NT1 Protocol\nDialectIndex=[d]\nSecMode=[B]\nMaxMux=[d]\nNumVcs=[d]\nMaxBuffer=[D]\nRawSize=[D]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[d]\nCryptKey=";
+           f1 = "NT1 Protocol\nDialectIndex=[u]\nSecMode=[B]\nMaxMux=[u]\nNumVcs=[u]\nMaxBuffer=[U]\nRawSize=[U]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[u]\nCryptKey=";
        else if (wct == 13)
-           f1 = "Coreplus/Lanman1/Lanman2 Protocol\nDialectIndex=[d]\nSecMode=[w]\nMaxXMit=[d]\nMaxMux=[d]\nMaxVcs=[d]\nBlkMode=[w]\nSessionKey=[W]\nServerTime=[T1]TimeZone=[d]\nRes=[W]\nCryptKey=";
+           f1 = "Coreplus/Lanman1/Lanman2 Protocol\nDialectIndex=[u]\nSecMode=[w]\nMaxXMit=[u]\nMaxMux=[u]\nMaxVcs=[u]\nBlkMode=[w]\nSessionKey=[W]\nServerTime=[T1]TimeZone=[u]\nRes=[W]\nCryptKey=";
     }
 
     if (f1)
@@ -449,14 +449,14 @@ print_sesssetup(netdissect_options *ndo,
     wct = EXTRACT_U_1(words);
     if (request) {
        if (wct == 10)
-           f1 = "Com2=[w]\nOff2=[d]\nBufSize=[d]\nMpxMax=[d]\nVcNum=[d]\nSessionKey=[W]\nPassLen=[d]\nCryptLen=[d]\nCryptOff=[d]\nPass&Name=\n";
+           f1 = "Com2=[w]\nOff2=[u]\nBufSize=[u]\nMpxMax=[u]\nVcNum=[u]\nSessionKey=[W]\nPassLen=[u]\nCryptLen=[u]\nCryptOff=[u]\nPass&Name=\n";
        else
-           f1 = "Com2=[B]\nRes1=[B]\nOff2=[d]\nMaxBuffer=[d]\nMaxMpx=[d]\nVcNumber=[d]\nSessionKey=[W]\nCaseInsensitivePasswordLength=[d]\nCaseSensitivePasswordLength=[d]\nRes=[W]\nCapabilities=[W]\nPass1&Pass2&Account&Domain&OS&LanMan=\n";
+           f1 = "Com2=[B]\nRes1=[B]\nOff2=[u]\nMaxBuffer=[u]\nMaxMpx=[u]\nVcNumber=[u]\nSessionKey=[W]\nCaseInsensitivePasswordLength=[u]\nCaseSensitivePasswordLength=[u]\nRes=[W]\nCapabilities=[W]\nPass1&Pass2&Account&Domain&OS&LanMan=\n";
     } else {
        if (wct == 3) {
-           f1 = "Com2=[w]\nOff2=[d]\nAction=[w]\n";
+           f1 = "Com2=[w]\nOff2=[u]\nAction=[w]\n";
        } else if (wct == 13) {
-           f1 = "Com2=[B]\nRes=[B]\nOff2=[d]\nAction=[w]\n";
+           f1 = "Com2=[B]\nRes=[B]\nOff2=[u]\nAction=[w]\n";
            f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n";
        }
     }
@@ -494,14 +494,14 @@ print_lockingandx(netdissect_options *ndo,
     ND_TCHECK_1(words);
     wct = EXTRACT_U_1(words);
     if (request) {
-       f1 = "Com2=[w]\nOff2=[d]\nHandle=[d]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[d]\nLockCount=[d]\n";
+       f1 = "Com2=[w]\nOff2=[u]\nHandle=[u]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[u]\nLockCount=[u]\n";
        ND_TCHECK_1(words + 7);
        if (EXTRACT_U_1(words + 7) & 0x10)
-           f2 = "*Process=[d]\n[P2]Offset=[M]\nLength=[M]\n";
+           f2 = "*Process=[u]\n[P2]Offset=[M]\nLength=[M]\n";
        else
-           f2 = "*Process=[d]\nOffset=[D]\nLength=[D]\n";
+           f2 = "*Process=[u]\nOffset=[D]\nLength=[U]\n";
     } else {
-       f1 = "Com2=[w]\nOff2=[d]\n";
+       f1 = "Com2=[w]\nOff2=[u]\n";
     }
 
     maxwords = min(words + 1 + wct * 2, maxbuf);
@@ -530,7 +530,7 @@ static const struct smbfns smb_fns[] = {
 
     { SMBtcon, "SMBtcon", 0,
        { NULL, "Path=[Z]\nPassword=[Z]\nDevice=[Z]\n",
-         "MaxXmit=[d]\nTreeId=[d]\n", NULL,
+         "MaxXmit=[u]\nTreeId=[u]\n", NULL,
          NULL } },
 
     { SMBtdis, "SMBtdis", 0, DEFDESCRIPT },
@@ -538,15 +538,15 @@ static const struct smbfns smb_fns[] = {
     { SMBioctl, "SMBioctl", 0, DEFDESCRIPT },
 
     { SMBecho, "SMBecho", 0,
-       { "ReverbCount=[d]\n", NULL,
-         "SequenceNum=[d]\n", NULL,
+       { "ReverbCount=[u]\n", NULL,
+         "SequenceNum=[u]\n", NULL,
          NULL } },
 
     { SMBulogoffX, "SMBulogoffX", FLG_CHAIN, DEFDESCRIPT },
 
     { SMBgetatr, "SMBgetatr", 0,
        { NULL, "Path=[Z]\n",
-         "Attribute=[A]\nTime=[T2]Size=[D]\nRes=([w,w,w,w,w])\n", NULL,
+         "Attribute=[A]\nTime=[T2]Size=[U]\nRes=([w,w,w,w,w])\n", NULL,
          NULL } },
 
     { SMBsetatr, "SMBsetatr", 0,
@@ -557,36 +557,36 @@ static const struct smbfns smb_fns[] = {
        { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
 
     { SMBsearch, "SMBsearch", 0,
-       { "Count=[d]\nAttrib=[A]\n",
-         "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\n",
-         "Count=[d]\n",
-         "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",
+       { "Count=[u]\nAttrib=[A]\n",
+         "Path=[Z]\nBlkType=[B]\nBlkLen=[u]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\nRes2=[W]\n",
+         "Count=[u]\n",
+         "BlkType=[B]\nBlkLen=[u]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[U]\nName=[s13]\n",
          NULL } },
 
     { SMBopen, "SMBopen", 0,
        { "Mode=[w]\nAttribute=[A]\n", "Path=[Z]\n",
-         "Handle=[d]\nOAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\n",
+         "Handle=[u]\nOAttrib=[A]\nTime=[T2]Size=[U]\nAccess=[w]\n",
          NULL, NULL } },
 
     { SMBcreate, "SMBcreate", 0,
-       { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } },
+       { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[u]\n", NULL, NULL } },
 
     { SMBmknew, "SMBmknew", 0,
-       { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } },
+       { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[u]\n", NULL, NULL } },
 
     { SMBunlink, "SMBunlink", 0,
        { "Attrib=[A]\n", "Path=[Z]\n", NULL, NULL, NULL } },
 
     { SMBread, "SMBread", 0,
-       { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
-         "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } },
+       { "Handle=[u]\nByteCount=[u]\nOffset=[D]\nCountLeft=[u]\n", NULL,
+         "Count=[u]\nRes=([w,w,w,w])\n", NULL, NULL } },
 
     { SMBwrite, "SMBwrite", 0,
-       { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
-         "Count=[d]\n", NULL, NULL } },
+       { "Handle=[u]\nByteCount=[u]\nOffset=[D]\nCountLeft=[u]\n", NULL,
+         "Count=[u]\n", NULL, NULL } },
 
     { SMBclose, "SMBclose", 0,
-       { "Handle=[d]\nTime=[T2]", NULL, NULL, NULL, NULL } },
+       { "Handle=[u]\nTime=[T2]", NULL, NULL, NULL, NULL } },
 
     { SMBmkdir, "SMBmkdir", 0,
        { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
@@ -596,7 +596,7 @@ static const struct smbfns smb_fns[] = {
 
     { SMBdskattr, "SMBdskattr", 0,
        { NULL, NULL,
-         "TotalUnits=[d]\nBlocksPerUnit=[d]\nBlockSize=[d]\nFreeUnits=[d]\nMedia=[w]\n",
+         "TotalUnits=[u]\nBlocksPerUnit=[u]\nBlockSize=[u]\nFreeUnits=[u]\nMedia=[w]\n",
          NULL, NULL } },
 
     { SMBmv, "SMBmv", 0,
@@ -609,147 +609,147 @@ static const struct smbfns smb_fns[] = {
     { pSETDIR, "SMBsetdir", 0, { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
 
     { SMBlseek, "SMBlseek", 0,
-       { "Handle=[d]\nMode=[w]\nOffset=[D]\n", "Offset=[D]\n", NULL, NULL, NULL } },
+       { "Handle=[u]\nMode=[w]\nOffset=[D]\n", "Offset=[D]\n", NULL, NULL, NULL } },
 
-    { SMBflush, "SMBflush", 0, { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
+    { SMBflush, "SMBflush", 0, { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
 
     { SMBsplopen, "SMBsplopen", 0,
-       { "SetupLen=[d]\nMode=[w]\n", "Ident=[Z]\n", "Handle=[d]\n",
+       { "SetupLen=[u]\nMode=[w]\n", "Ident=[Z]\n", "Handle=[u]\n",
          NULL, NULL } },
 
     { SMBsplclose, "SMBsplclose", 0,
-       { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
+       { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
 
     { SMBsplretq, "SMBsplretq", 0,
-       { "MaxCount=[d]\nStartIndex=[d]\n", NULL,
-         "Count=[d]\nIndex=[d]\n",
-         "*Time=[T2]Status=[B]\nJobID=[d]\nSize=[D]\nRes=[B]Name=[s16]\n",
+       { "MaxCount=[u]\nStartIndex=[u]\n", NULL,
+         "Count=[u]\nIndex=[u]\n",
+         "*Time=[T2]Status=[B]\nJobID=[u]\nSize=[U]\nRes=[B]Name=[s16]\n",
          NULL } },
 
     { SMBsplwr, "SMBsplwr", 0,
-       { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
+       { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
 
     { SMBlock, "SMBlock", 0,
-       { "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
+       { "Handle=[u]\nCount=[U]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
 
     { SMBunlock, "SMBunlock", 0,
-       { "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
+       { "Handle=[u]\nCount=[U]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
 
     /* CORE+ PROTOCOL FOLLOWS */
 
     { SMBreadbraw, "SMBreadbraw", 0,
-       { "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[d]\n",
+       { "Handle=[u]\nOffset=[D]\nMaxCount=[u]\nMinCount=[u]\nTimeOut=[D]\nRes=[u]\n",
          NULL, NULL, NULL, NULL } },
 
     { SMBwritebraw, "SMBwritebraw", 0,
-       { "Handle=[d]\nTotalCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\n|DataSize=[d]\nDataOff=[d]\n",
+       { "Handle=[u]\nTotalCount=[u]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\n|DataSize=[u]\nDataOff=[u]\n",
          NULL, "WriteRawAck", NULL, NULL } },
 
     { SMBwritec, "SMBwritec", 0,
-       { NULL, NULL, "Count=[d]\n", NULL, NULL } },
+       { NULL, NULL, "Count=[u]\n", NULL, NULL } },
 
     { SMBwriteclose, "SMBwriteclose", 0,
-       { "Handle=[d]\nCount=[d]\nOffset=[D]\nTime=[T2]Res=([w,w,w,w,w,w])",
-         NULL, "Count=[d]\n", NULL, NULL } },
+       { "Handle=[u]\nCount=[u]\nOffset=[D]\nTime=[T2]Res=([w,w,w,w,w,w])",
+         NULL, "Count=[u]\n", NULL, NULL } },
 
     { SMBlockread, "SMBlockread", 0,
-       { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
-         "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } },
+       { "Handle=[u]\nByteCount=[u]\nOffset=[D]\nCountLeft=[u]\n", NULL,
+         "Count=[u]\nRes=([w,w,w,w])\n", NULL, NULL } },
 
     { SMBwriteunlock, "SMBwriteunlock", 0,
-       { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
-         "Count=[d]\n", NULL, NULL } },
+       { "Handle=[u]\nByteCount=[u]\nOffset=[D]\nCountLeft=[u]\n", NULL,
+         "Count=[u]\n", NULL, NULL } },
 
     { SMBreadBmpx, "SMBreadBmpx", 0,
-       { "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[w]\n",
+       { "Handle=[u]\nOffset=[D]\nMaxCount=[u]\nMinCount=[u]\nTimeOut=[D]\nRes=[w]\n",
          NULL,
-         "Offset=[D]\nTotCount=[d]\nRemaining=[d]\nRes=([w,w])\nDataSize=[d]\nDataOff=[d]\n",
+         "Offset=[D]\nTotCount=[u]\nRemaining=[u]\nRes=([w,w])\nDataSize=[u]\nDataOff=[u]\n",
          NULL, NULL } },
 
     { SMBwriteBmpx, "SMBwriteBmpx", 0,
-       { "Handle=[d]\nTotCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\nDataSize=[d]\nDataOff=[d]\n", NULL,
-         "Remaining=[d]\n", NULL, NULL } },
+       { "Handle=[u]\nTotCount=[u]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\nDataSize=[u]\nDataOff=[u]\n", NULL,
+         "Remaining=[u]\n", NULL, NULL } },
 
     { SMBwriteBs, "SMBwriteBs", 0,
-       { "Handle=[d]\nTotCount=[d]\nOffset=[D]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\n",
-         NULL, "Count=[d]\n", NULL, NULL } },
+       { "Handle=[u]\nTotCount=[u]\nOffset=[D]\nRes=[W]\nDataSize=[u]\nDataOff=[u]\n",
+         NULL, "Count=[u]\n", NULL, NULL } },
 
     { SMBsetattrE, "SMBsetattrE", 0,
-       { "Handle=[d]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]", NULL,
+       { "Handle=[u]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]", NULL,
          NULL, NULL, NULL } },
 
     { SMBgetattrE, "SMBgetattrE", 0,
-       { "Handle=[d]\n", NULL,
-         "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D]\nAllocSize=[D]\nAttribute=[A]\n",
+       { "Handle=[u]\n", NULL,
+         "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[U]\nAllocSize=[U]\nAttribute=[A]\n",
          NULL, NULL } },
 
     { SMBtranss, "SMBtranss", 0, DEFDESCRIPT },
     { SMBioctls, "SMBioctls", 0, DEFDESCRIPT },
 
     { SMBcopy, "SMBcopy", 0,
-       { "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
-         "CopyCount=[d]\n",  "|ErrStr=[S]\n",  NULL } },
+       { "TreeID2=[u]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
+         "CopyCount=[u]\n",  "|ErrStr=[S]\n",  NULL } },
 
     { SMBmove, "SMBmove", 0,
-       { "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
-         "MoveCount=[d]\n",  "|ErrStr=[S]\n",  NULL } },
+       { "TreeID2=[u]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
+         "MoveCount=[u]\n",  "|ErrStr=[S]\n",  NULL } },
 
     { SMBopenX, "SMBopenX", FLG_CHAIN,
-       { "Com2=[w]\nOff2=[d]\nFlags=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]OFun=[w]\nSize=[D]\nTimeOut=[D]\nRes=[W]\n",
+       { "Com2=[w]\nOff2=[u]\nFlags=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]OFun=[w]\nSize=[U]\nTimeOut=[D]\nRes=[W]\n",
          "Path=[S]\n",
-         "Com2=[w]\nOff2=[d]\nHandle=[d]\nAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nFileID=[W]\nRes=[w]\n",
+         "Com2=[w]\nOff2=[u]\nHandle=[u]\nAttrib=[A]\nTime=[T2]Size=[U]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nFileID=[W]\nRes=[w]\n",
          NULL, NULL } },
 
     { SMBreadX, "SMBreadX", FLG_CHAIN,
-       { "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nCountLeft=[d]\n",
+       { "Com2=[w]\nOff2=[u]\nHandle=[u]\nOffset=[D]\nMaxCount=[u]\nMinCount=[u]\nTimeOut=[D]\nCountLeft=[u]\n",
          NULL,
-         "Com2=[w]\nOff2=[d]\nRemaining=[d]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\nRes=([w,w,w,w])\n",
+         "Com2=[w]\nOff2=[u]\nRemaining=[u]\nRes=[W]\nDataSize=[u]\nDataOff=[u]\nRes=([w,w,w,w])\n",
          NULL, NULL } },
 
     { SMBwriteX, "SMBwriteX", FLG_CHAIN,
-       { "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nCountLeft=[d]\nRes=[w]\nDataSize=[d]\nDataOff=[d]\n",
+       { "Com2=[w]\nOff2=[u]\nHandle=[u]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nCountLeft=[u]\nRes=[w]\nDataSize=[u]\nDataOff=[u]\n",
          NULL,
-         "Com2=[w]\nOff2=[d]\nCount=[d]\nRemaining=[d]\nRes=[W]\n",
+         "Com2=[w]\nOff2=[u]\nCount=[u]\nRemaining=[u]\nRes=[W]\n",
          NULL, NULL } },
 
     { SMBffirst, "SMBffirst", 0,
-       { "Count=[d]\nAttrib=[A]\n",
-         "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
-         "Count=[d]\n",
-         "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",
+       { "Count=[u]\nAttrib=[A]\n",
+         "Path=[Z]\nBlkType=[B]\nBlkLen=[u]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\n",
+         "Count=[u]\n",
+         "BlkType=[B]\nBlkLen=[u]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[U]\nName=[s13]\n",
          NULL } },
 
     { SMBfunique, "SMBfunique", 0,
-       { "Count=[d]\nAttrib=[A]\n",
-         "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
-         "Count=[d]\n",
-         "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",
+       { "Count=[u]\nAttrib=[A]\n",
+         "Path=[Z]\nBlkType=[B]\nBlkLen=[u]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\n",
+         "Count=[u]\n",
+         "BlkType=[B]\nBlkLen=[u]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[U]\nName=[s13]\n",
          NULL } },
 
     { SMBfclose, "SMBfclose", 0,
-       { "Count=[d]\nAttrib=[A]\n",
-         "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
-         "Count=[d]\n",
-         "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",
+       { "Count=[u]\nAttrib=[A]\n",
+         "Path=[Z]\nBlkType=[B]\nBlkLen=[u]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\n",
+         "Count=[u]\n",
+         "BlkType=[B]\nBlkLen=[u]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[U]\nName=[s13]\n",
          NULL } },
 
     { SMBfindnclose, "SMBfindnclose", 0,
-       { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
+       { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
 
     { SMBfindclose, "SMBfindclose", 0,
-       { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
+       { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
 
     { SMBsends, "SMBsends", 0,
        { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
 
     { SMBsendstrt, "SMBsendstrt", 0,
-       { NULL, "Source=[Z]\nDest=[Z]\n", "GroupID=[d]\n", NULL, NULL } },
+       { NULL, "Source=[Z]\nDest=[Z]\n", "GroupID=[u]\n", NULL, NULL } },
 
     { SMBsendend, "SMBsendend", 0,
-       { "GroupID=[d]\n", NULL, NULL, NULL, NULL } },
+       { "GroupID=[u]\n", NULL, NULL, NULL, NULL } },
 
     { SMBsendtxt, "SMBsendtxt", 0,
-       { "GroupID=[d]\n", NULL, NULL, NULL, NULL } },
+       { "GroupID=[u]\n", NULL, NULL, NULL, NULL } },
 
     { SMBsendb, "SMBsendb", 0,
        { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
@@ -765,8 +765,8 @@ static const struct smbfns smb_fns[] = {
        { NULL, NULL, NULL, NULL, print_sesssetup } },
 
     { SMBtconX, "SMBtconX", FLG_CHAIN,
-       { "Com2=[w]\nOff2=[d]\nFlags=[w]\nPassLen=[d]\nPasswd&Path&Device=\n",
-         NULL, "Com2=[w]\nOff2=[d]\n", "ServiceType=[R]\n", NULL } },
+       { "Com2=[w]\nOff2=[u]\nFlags=[w]\nPassLen=[u]\nPasswd&Path&Device=\n",
+         NULL, "Com2=[w]\nOff2=[u]\n", "ServiceType=[R]\n", NULL } },
 
     { SMBlockingX, "SMBlockingX", FLG_CHAIN,
        { NULL, NULL, NULL, NULL, print_lockingandx } },
@@ -782,9 +782,9 @@ static const struct smbfns smb_fns[] = {
     { SMBnttranss, "SMBnttranss", 0, DEFDESCRIPT },
 
     { SMBntcreateX, "SMBntcreateX", FLG_CHAIN,
-       { "Com2=[w]\nOff2=[d]\nRes=[b]\nNameLen=[ld]\nFlags=[W]\nRootDirectoryFid=[D]\nAccessMask=[W]\nAllocationSize=[L]\nExtFileAttributes=[W]\nShareAccess=[W]\nCreateDisposition=[W]\nCreateOptions=[W]\nImpersonationLevel=[W]\nSecurityFlags=[b]\n",
+       { "Com2=[w]\nOff2=[u]\nRes=[b]\nNameLen=[lu]\nFlags=[W]\nRootDirectoryFid=[U]\nAccessMask=[W]\nAllocationSize=[L]\nExtFileAttributes=[W]\nShareAccess=[W]\nCreateDisposition=[W]\nCreateOptions=[W]\nImpersonationLevel=[W]\nSecurityFlags=[b]\n",
          "Path=[C]\n",
-         "Com2=[w]\nOff2=[d]\nOplockLevel=[b]\nFid=[d]\nCreateAction=[W]\nCreateTime=[T3]LastAccessTime=[T3]LastWriteTime=[T3]ChangeTime=[T3]ExtFileAttributes=[W]\nAllocationSize=[L]\nEndOfFile=[L]\nFileType=[w]\nDeviceState=[w]\nDirectory=[b]\n",
+         "Com2=[w]\nOff2=[u]\nOplockLevel=[b]\nFid=[u]\nCreateAction=[W]\nCreateTime=[T3]LastAccessTime=[T3]LastWriteTime=[T3]ChangeTime=[T3]ExtFileAttributes=[W]\nAllocationSize=[L]\nEndOfFile=[L]\nFileType=[w]\nDeviceState=[w]\nDirectory=[b]\n",
          NULL, NULL } },
 
     { SMBntcancel, "SMBntcancel", 0, DEFDESCRIPT },
@@ -801,14 +801,14 @@ print_smb(netdissect_options *ndo,
           const u_char *buf, const u_char *maxbuf)
 {
     uint16_t flags2;
-    int nterrcodes;
-    int command;
+    u_int nterrcodes;
+    u_int command;
     uint32_t nterror;
     const u_char *words, *maxwords, *data;
     const struct smbfns *fn;
     const char *fmt_smbheader =
-        "[P4]SMB Command   =  [B]\nError class   =  [BP1]\nError code    =  [d]\nFlags1        =  [B]\nFlags2        =  [B][P13]\nTree ID       =  [d]\nProc ID       =  [d]\nUID           =  [d]\nMID           =  [d]\nWord Count    =  [b]\n";
-    int smboffset;
+        "[P4]SMB Command   =  [B]\nError class   =  [BP1]\nError code    =  [u]\nFlags1        =  [B]\nFlags2        =  [B][P13]\nTree ID       =  [u]\nProc ID       =  [u]\nUID           =  [u]\nMID           =  [u]\nWord Count    =  [b]\n";
+    u_int smboffset;
 
     ND_TCHECK_1(buf + 9);
     request = (EXTRACT_U_1(buf + 9) & 0x80) ? 0 : 1;
@@ -850,7 +850,7 @@ print_smb(netdissect_options *ndo,
        const char *f1, *f2;
        int wct;
        u_int bcc;
-       int newsmboffset;
+       u_int newsmboffset;
 
        words = buf + smboffset;
        ND_TCHECK_1(words);
@@ -873,13 +873,13 @@ print_smb(netdissect_options *ndo,
                if (f1)
                    smb_fdata(ndo, words + 1, f1, words + 1 + wct * 2, unicodestr);
                else {
-                   int i;
-                   int v;
+                   u_int i;
+                   u_int v;
 
                    for (i = 0; words + 1 + 2 * i < maxwords; i++) {
                        ND_TCHECK_2(words + 1 + 2 * i);
                        v = EXTRACT_LE_U_2(words + 1 + 2 * i);
-                       ND_PRINT((ndo, "smb_vwv[%d]=%d (0x%X)\n", i, v, v));
+                       ND_PRINT((ndo, "smb_vwv[%u]=%u (0x%X)\n", i, v, v));
                    }
                }
            }
@@ -932,10 +932,10 @@ trunc:
  */
 void
 nbt_tcp_print(netdissect_options *ndo,
-              const u_char *data, int length)
+              const u_char *data, u_int length)
 {
-    int caplen;
-    int type;
+    u_int caplen;
+    u_int type;
     u_int nbt_len;
     const u_char *maxbuf;
 
@@ -973,7 +973,7 @@ nbt_tcp_print(netdissect_options *ndo,
 
        case 0x83:
          {
-           int ecode;
+           u_int ecode;
 
            if (nbt_len < 4)
                goto trunc;
@@ -1016,16 +1016,16 @@ nbt_tcp_print(netdissect_options *ndo,
        ND_PRINT((ndo, "\n>>> NBT Session Packet\n"));
        switch (type) {
        case 0x00:
-           data = smb_fdata(ndo, data, "[P1]NBT Session Message\nFlags=[B]\nLength=[rd]\n",
+           data = smb_fdata(ndo, data, "[P1]NBT Session Message\nFlags=[B]\nLength=[ru]\n",
                data + 4, 0);
            if (data == NULL)
                break;
            if (nbt_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) {
-               if ((int)nbt_len > caplen) {
-                   if ((int)nbt_len > length)
+               if (nbt_len > caplen) {
+                   if (nbt_len > length)
                        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 %u\n",
                            nbt_len - caplen));
                }
                print_smb(ndo, data, maxbuf > data + nbt_len ? data + nbt_len : maxbuf);
@@ -1035,21 +1035,21 @@ nbt_tcp_print(netdissect_options *ndo,
 
        case 0x81:
            data = smb_fdata(ndo, data,
-               "[P1]NBT Session Request\nFlags=[B]\nLength=[rd]\nDestination=[n1]\nSource=[n1]\n",
+               "[P1]NBT Session Request\nFlags=[B]\nLength=[ru]\nDestination=[n1]\nSource=[n1]\n",
                maxbuf, 0);
            break;
 
        case 0x82:
-           data = smb_fdata(ndo, data, "[P1]NBT Session Granted\nFlags=[B]\nLength=[rd]\n", maxbuf, 0);
+           data = smb_fdata(ndo, data, "[P1]NBT Session Granted\nFlags=[B]\nLength=[ru]\n", maxbuf, 0);
            break;
 
        case 0x83:
          {
            const u_char *origdata;
-           int ecode;
+           u_int ecode;
 
            origdata = data;
-           data = smb_fdata(ndo, data, "[P1]NBT SessionReject\nFlags=[B]\nLength=[rd]\nReason=[B]\n",
+           data = smb_fdata(ndo, data, "[P1]NBT SessionReject\nFlags=[B]\nLength=[ru]\nReason=[B]\n",
                maxbuf, 0);
            if (data == NULL)
                break;
@@ -1077,7 +1077,7 @@ nbt_tcp_print(netdissect_options *ndo,
            break;
 
        case 0x85:
-           data = smb_fdata(ndo, data, "[P1]NBT Session Keepalive\nFlags=[B]\nLength=[rd]\n", maxbuf, 0);
+           data = smb_fdata(ndo, data, "[P1]NBT Session Keepalive\nFlags=[B]\nLength=[ru]\n", maxbuf, 0);
            break;
 
        default:
@@ -1107,13 +1107,13 @@ static const struct tok opcode_str[] = {
  */
 void
 nbt_udp137_print(netdissect_options *ndo,
-                 const u_char *data, int length)
+                 const u_char *data, u_int length)
 {
     const u_char *maxbuf = data + length;
-    int name_trn_id, response, opcode, nm_flags, rcode;
-    int qdcount, ancount, nscount, arcount;
+    u_int name_trn_id, response, opcode, nm_flags, rcode;
+    u_int qdcount, ancount, nscount, arcount;
     const u_char *p;
-    int total, i;
+    u_int total, i;
 
     ND_TCHECK_2(data + 10);
     name_trn_id = EXTRACT_BE_U_2(data);
@@ -1143,7 +1143,7 @@ nbt_udp137_print(netdissect_options *ndo,
     if (ndo->ndo_vflag < 2)
        return;
 
-    ND_PRINT((ndo, "\nTrnID=0x%X\nOpCode=%d\nNmFlags=0x%X\nRcode=%d\nQueryCount=%d\nAnswerCount=%d\nAuthorityCount=%d\nAddressRecCount=%d\n",
+    ND_PRINT((ndo, "\nTrnID=0x%X\nOpCode=%u\nNmFlags=0x%X\nRcode=%u\nQueryCount=%u\nAnswerCount=%u\nAuthorityCount=%u\nAddressRecCount=%u\n",
        name_trn_id, opcode, nm_flags, rcode, qdcount, ancount, nscount,
        arcount));
 
@@ -1170,20 +1170,20 @@ nbt_udp137_print(netdissect_options *ndo,
     if (total) {
        ND_PRINT((ndo, "\nResourceRecords:\n"));
        for (i = 0; i < total; i++) {
-           int rdlen;
-           int restype;
+           u_int rdlen;
+           u_int restype;
 
            p = smb_fdata(ndo, p, "Name=[n1]\n#", maxbuf, 0);
            if (p == NULL)
                goto out;
            ND_TCHECK_2(p);
            restype = EXTRACT_BE_U_2(p);
-           p = smb_fdata(ndo, p, "ResType=[rw]\nResClass=[rw]\nTTL=[rD]\n", p + 8, 0);
+           p = smb_fdata(ndo, p, "ResType=[rw]\nResClass=[rw]\nTTL=[rU]\n", p + 8, 0);
            if (p == NULL)
                goto out;
            ND_TCHECK_2(p);
            rdlen = EXTRACT_BE_U_2(p);
-           ND_PRINT((ndo, "ResourceLength=%d\nResourceData=\n", rdlen));
+           ND_PRINT((ndo, "ResourceLength=%u\nResourceData=\n", rdlen));
            p += 2;
            if (rdlen == 6) {
                p = smb_fdata(ndo, p, "AddrType=[rw]\nAddress=[b.b.b.b]\n", p + rdlen, 0);
@@ -1191,7 +1191,7 @@ nbt_udp137_print(netdissect_options *ndo,
                    goto out;
            } else {
                if (restype == 0x21) {
-                   int numnames;
+                   u_int numnames;
 
                    ND_TCHECK_1(p);
                    numnames = EXTRACT_U_1(p);
@@ -1203,6 +1203,8 @@ nbt_udp137_print(netdissect_options *ndo,
                        if (p == NULL)
                            goto out;
                        ND_TCHECK_1(p);
+                       if (p >= maxbuf)
+                           goto out;
                        if (EXTRACT_U_1(p) & 0x80)
                            ND_PRINT((ndo, "<GROUP> "));
                        switch (EXTRACT_U_1(p) & 0x60) {
@@ -1223,6 +1225,8 @@ nbt_udp137_print(netdissect_options *ndo,
                        p += 2;
                    }
                } else {
+                   if (p >= maxbuf)
+                       goto out;
                    smb_print_data(ndo, p, min(rdlen, length - (p - data)));
                    p += rdlen;
                }
@@ -1245,9 +1249,9 @@ trunc:
  */
 void
 smb_tcp_print(netdissect_options *ndo,
-              const u_char * data, int length)
+              const u_char * data, u_int length)
 {
-    int caplen;
+    u_int caplen;
     u_int smb_len;
     const u_char *maxbuf;
 
@@ -1267,11 +1271,11 @@ smb_tcp_print(netdissect_options *ndo,
     data += 4;
 
     if (smb_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) {
-       if ((int)smb_len > caplen) {
-           if ((int)smb_len > length)
+       if (smb_len > caplen) {
+           if (smb_len > length)
                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 %u\n",
                    smb_len - caplen));
        } else
            ND_PRINT((ndo, " "));
@@ -1288,7 +1292,7 @@ trunc:
  */
 void
 nbt_udp138_print(netdissect_options *ndo,
-                 const u_char *data, int length)
+                 const u_char *data, u_int length)
 {
     const u_char *maxbuf = data + length;
 
@@ -1304,7 +1308,7 @@ nbt_udp138_print(netdissect_options *ndo,
     }
 
     data = smb_fdata(ndo, data,
-       "\n>>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[rd] Length=[rd] Res2=[rw]\nSourceName=[n1]\nDestName=[n1]\n#",
+       "\n>>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[ru] Length=[ru] Res2=[rw]\nSourceName=[n1]\nDestName=[n1]\n#",
        maxbuf, 0);
 
     if (data != NULL) {
@@ -1380,11 +1384,11 @@ static struct nbf_strings {
 
 void
 netbeui_print(netdissect_options *ndo,
-              u_short control, const u_char *data, int length)
+              u_short control, const u_char *data, u_int length)
 {
     const u_char *maxbuf = data + length;
-    int len;
-    int command;
+    u_int len;
+    u_int command;
     const u_char *data2;
     int is_truncated = 0;
 
@@ -1406,7 +1410,7 @@ netbeui_print(netdissect_options *ndo,
        data = smb_fdata(ndo, data, "[P5]#", maxbuf, 0);
     } else {
        ND_PRINT((ndo, "\n>>> NBF Packet\nType=0x%X ", control));
-       data = smb_fdata(ndo, data, "Length=[d] Signature=[w] Command=[B]\n#", maxbuf, 0);
+       data = smb_fdata(ndo, data, "Length=[u] Signature=[w] Command=[B]\n#", maxbuf, 0);
     }
     if (data == NULL)
        goto out;
@@ -1453,12 +1457,12 @@ netbeui_print(netdissect_options *ndo,
     if (memcmp(data2, "\377SMB",4) == 0)
        print_smb(ndo, data2, maxbuf);
     else {
-       int i;
+       u_int i;
        for (i = 0; i < 128; i++) {
            if ((data2 + i + 3) >= maxbuf)
                break;
            if (memcmp(data2 + i, "\377SMB", 4) == 0) {
-               ND_PRINT((ndo, "found SMB packet at %d\n", i));
+               ND_PRINT((ndo, "found SMB packet at %u\n", i));
                print_smb(ndo, data2 + i, maxbuf);
                break;
            }
@@ -1484,7 +1488,7 @@ ipx_netbios_print(netdissect_options *ndo,
      * this is a hack till I work out how to parse the rest of the
      * NetBIOS-over-IPX stuff
      */
-    int i;
+    u_int i;
     const u_char *maxbuf;
 
     maxbuf = data + length;
index 536cd30f3e9634176821daec55c026ad851b8b69..2d6132975aa46aef87ad25c1929ae1639dd4a102 100644 (file)
--- a/smbutil.c
+++ b/smbutil.c
@@ -128,7 +128,7 @@ name_interpret(netdissect_options *ndo,
                const u_char *in, const u_char *maxbuf, char *out)
 {
     int ret;
-    int len;
+    u_int len;
 
     if (in >= maxbuf)
        return(-1);     /* name goes past the end of the buffer */
@@ -138,10 +138,10 @@ name_interpret(netdissect_options *ndo,
 
     *out=0;
 
-    if (len > 30 || len < 1)
+    if (len > 30 || len == 0)
        return(0);
 
-    while (len--) {
+    while (len) {
        ND_TCHECK_2(in);
        if (in + 1 >= maxbuf)
            return(-1); /* name goes past the end of the buffer */
@@ -153,6 +153,7 @@ name_interpret(netdissect_options *ndo,
        *out = ((EXTRACT_U_1(in) - 'A') << 4) + (EXTRACT_U_1(in + 1) - 'A');
        in += 2;
        out++;
+       len--;
     }
     *out = 0;
     ret = out[-1];
@@ -168,7 +169,7 @@ trunc:
  */
 static const u_char *
 name_ptr(netdissect_options *ndo,
-         const u_char *buf, int ofs, const u_char *maxbuf)
+         const u_char *buf, u_int ofs, const u_char *maxbuf)
 {
     const u_char *p;
     u_char c;
@@ -208,7 +209,7 @@ trunc:
  */
 static int
 name_extract(netdissect_options *ndo,
-             const u_char *buf, int ofs, const u_char *maxbuf, char *name)
+             const u_char *buf, u_int ofs, const u_char *maxbuf, char *name)
 {
     const u_char *p = name_ptr(ndo, buf, ofs, maxbuf);
     if (p == NULL)
@@ -249,9 +250,9 @@ trunc:
 
 static void
 print_asc(netdissect_options *ndo,
-          const u_char *buf, int len)
+          const u_char *buf, u_int len)
 {
-    int i;
+    u_int i;
     for (i = 0; i < len; i++)
         safeputchar(ndo, EXTRACT_U_1(buf + i));
 }
@@ -274,11 +275,11 @@ name_type_str(int name_type)
 }
 
 void
-smb_print_data(netdissect_options *ndo, const u_char *buf, int len)
+smb_print_data(netdissect_options *ndo, const u_char *buf, u_int len)
 {
-    int i = 0;
+    u_int i = 0;
 
-    if (len <= 0)
+    if (len == 0)
        return;
     ND_PRINT((ndo, "[%03X] ", i));
     for (i = 0; i < len; /*nothing*/) {
@@ -327,7 +328,7 @@ write_bits(netdissect_options *ndo,
            unsigned int val, const char *fmt)
 {
     const char *p = fmt;
-    int i = 0;
+    u_int i = 0;
 
     while ((p = strchr(fmt, '|'))) {
        size_t l = PTR_DIFF(p, fmt);
@@ -461,12 +462,12 @@ smb_fdata1(netdissect_options *ndo,
          {
            char bitfmt[128];
            char *p;
-           int l;
+           u_int l;
 
            p = strchr(++fmt, '}');
            l = PTR_DIFF(p, fmt);
 
-           if ((unsigned int)l > sizeof(bitfmt) - 1)
+           if (l > sizeof(bitfmt) - 1)
                    l = sizeof(bitfmt)-1;
 
            strncpy(bitfmt, fmt, l);
@@ -504,10 +505,10 @@ smb_fdata1(netdissect_options *ndo,
          }
        case 'd':
          {
-           unsigned int x;
+           int x;
            ND_TCHECK_2(buf);
-           x = reverse ? EXTRACT_BE_U_2(buf) :
-                         EXTRACT_LE_U_2(buf);
+           x = reverse ? EXTRACT_BE_S_2(buf) :
+                         EXTRACT_LE_S_2(buf);
            ND_PRINT((ndo, "%d (0x%x)", x, x));
            buf += 2;
            fmt++;
@@ -515,10 +516,10 @@ smb_fdata1(netdissect_options *ndo,
          }
        case 'D':
          {
-           unsigned int x;
+           int x;
            ND_TCHECK_4(buf);
-           x = reverse ? EXTRACT_BE_U_4(buf) :
-                         EXTRACT_LE_U_4(buf);
+           x = reverse ? EXTRACT_BE_S_4(buf) :
+                         EXTRACT_LE_S_4(buf);
            ND_PRINT((ndo, "%d (0x%x)", x, x));
            buf += 4;
            fmt++;
@@ -535,6 +536,28 @@ smb_fdata1(netdissect_options *ndo,
            fmt++;
            break;
          }
+       case 'u':
+         {
+           unsigned int x;
+           ND_TCHECK_2(buf);
+           x = reverse ? EXTRACT_BE_U_2(buf) :
+                         EXTRACT_LE_U_2(buf);
+           ND_PRINT((ndo, "%u (0x%x)", x, x));
+           buf += 2;
+           fmt++;
+           break;
+         }
+       case 'U':
+         {
+           unsigned int x;
+           ND_TCHECK_4(buf);
+           x = reverse ? EXTRACT_BE_U_4(buf) :
+                         EXTRACT_LE_U_4(buf);
+           ND_PRINT((ndo, "%u (0x%x)", x, x));
+           buf += 4;
+           fmt++;
+           break;
+         }
        case 'M':
          {
            /* Weird mixed-endian length values in 64-bit locks */
@@ -596,6 +619,7 @@ smb_fdata1(netdissect_options *ndo,
                break;
 
            case 'd':
+           case 'u':
                ND_TCHECK_2(buf);
                stringlen = reverse ? EXTRACT_BE_U_2(buf) :
                                      EXTRACT_LE_U_2(buf);
@@ -604,6 +628,7 @@ smb_fdata1(netdissect_options *ndo,
                break;
 
            case 'D':
+           case 'U':
                ND_TCHECK_4(buf);
                stringlen = reverse ? EXTRACT_BE_U_4(buf) :
                                      EXTRACT_LE_U_4(buf);