Home | History | Annotate | Line # | Download | only in dist
print-smb.c revision 1.7.12.1
      1       1.1  christos /*
      2       1.1  christos  * Copyright (C) Andrew Tridgell 1995-1999
      3       1.1  christos  *
      4       1.1  christos  * This software may be distributed either under the terms of the
      5       1.1  christos  * BSD-style license that accompanies tcpdump or the GNU GPL version 2
      6       1.1  christos  * or later
      7       1.1  christos  */
      8       1.1  christos 
      9       1.2  christos #include <sys/cdefs.h>
     10       1.1  christos #ifndef lint
     11  1.7.12.1    martin __RCSID("$NetBSD: print-smb.c,v 1.7.12.1 2020/04/13 07:56:31 martin Exp $");
     12       1.2  christos #endif
     13       1.4  christos 
     14       1.7       spz /* \summary: SMB/CIFS printer */
     15       1.7       spz 
     16       1.4  christos #ifdef HAVE_CONFIG_H
     17       1.4  christos #include "config.h"
     18       1.1  christos #endif
     19       1.1  christos 
     20       1.6  christos #include <netdissect-stdinc.h>
     21       1.1  christos 
     22       1.1  christos #include <string.h>
     23       1.1  christos 
     24       1.6  christos #include "netdissect.h"
     25       1.1  christos #include "extract.h"
     26       1.1  christos #include "smb.h"
     27       1.1  christos 
     28       1.4  christos static const char tstr[] = "[|SMB]";
     29       1.4  christos 
     30       1.1  christos static int request = 0;
     31       1.1  christos static int unicodestr = 0;
     32       1.1  christos 
     33       1.1  christos const u_char *startbuf = NULL;
     34       1.1  christos 
     35       1.1  christos struct smbdescript {
     36       1.1  christos     const char *req_f1;
     37       1.1  christos     const char *req_f2;
     38       1.1  christos     const char *rep_f1;
     39       1.1  christos     const char *rep_f2;
     40       1.4  christos     void (*fn)(netdissect_options *, const u_char *, const u_char *, const u_char *, const u_char *);
     41       1.1  christos };
     42       1.1  christos 
     43       1.1  christos struct smbdescriptint {
     44       1.1  christos     const char *req_f1;
     45       1.1  christos     const char *req_f2;
     46       1.1  christos     const char *rep_f1;
     47       1.1  christos     const char *rep_f2;
     48       1.4  christos     void (*fn)(netdissect_options *, const u_char *, const u_char *, int, int);
     49       1.1  christos };
     50       1.1  christos 
     51       1.1  christos struct smbfns
     52       1.1  christos {
     53       1.1  christos     int id;
     54       1.1  christos     const char *name;
     55       1.1  christos     int flags;
     56       1.1  christos     struct smbdescript descript;
     57       1.1  christos };
     58       1.1  christos 
     59       1.1  christos struct smbfnsint
     60       1.1  christos {
     61       1.1  christos     int id;
     62       1.1  christos     const char *name;
     63       1.1  christos     int flags;
     64       1.1  christos     struct smbdescriptint descript;
     65       1.1  christos };
     66       1.1  christos 
     67       1.1  christos #define DEFDESCRIPT	{ NULL, NULL, NULL, NULL, NULL }
     68       1.1  christos 
     69       1.1  christos #define FLG_CHAIN	(1 << 0)
     70       1.1  christos 
     71       1.4  christos static const struct smbfns *
     72       1.4  christos smbfind(int id, const struct smbfns *list)
     73       1.1  christos {
     74       1.1  christos     int sindex;
     75       1.1  christos 
     76       1.1  christos     for (sindex = 0; list[sindex].name; sindex++)
     77       1.1  christos 	if (list[sindex].id == id)
     78       1.1  christos 	    return(&list[sindex]);
     79       1.1  christos 
     80       1.1  christos     return(&list[0]);
     81       1.1  christos }
     82       1.1  christos 
     83       1.4  christos static const struct smbfnsint *
     84       1.4  christos smbfindint(int id, const struct smbfnsint *list)
     85       1.1  christos {
     86       1.1  christos     int sindex;
     87       1.1  christos 
     88       1.1  christos     for (sindex = 0; list[sindex].name; sindex++)
     89       1.1  christos 	if (list[sindex].id == id)
     90       1.1  christos 	    return(&list[sindex]);
     91       1.1  christos 
     92       1.1  christos     return(&list[0]);
     93       1.1  christos }
     94       1.1  christos 
     95       1.1  christos static void
     96       1.4  christos trans2_findfirst(netdissect_options *ndo,
     97       1.4  christos                  const u_char *param, const u_char *data, int pcnt, int dcnt)
     98       1.1  christos {
     99       1.1  christos     const char *fmt;
    100       1.1  christos 
    101       1.1  christos     if (request)
    102       1.1  christos 	fmt = "Attribute=[A]\nSearchCount=[d]\nFlags=[w]\nLevel=[dP4]\nFile=[S]\n";
    103       1.1  christos     else
    104       1.1  christos 	fmt = "Handle=[w]\nCount=[d]\nEOS=[w]\nEoffset=[d]\nLastNameOfs=[w]\n";
    105       1.1  christos 
    106       1.4  christos     smb_fdata(ndo, param, fmt, param + pcnt, unicodestr);
    107       1.1  christos     if (dcnt) {
    108       1.4  christos 	ND_PRINT((ndo, "data:\n"));
    109       1.6  christos 	smb_print_data(ndo, data, dcnt);
    110       1.1  christos     }
    111       1.1  christos }
    112       1.1  christos 
    113       1.1  christos static void
    114       1.4  christos trans2_qfsinfo(netdissect_options *ndo,
    115       1.4  christos                const u_char *param, const u_char *data, int pcnt, int dcnt)
    116       1.1  christos {
    117       1.1  christos     static int level = 0;
    118       1.1  christos     const char *fmt="";
    119       1.1  christos 
    120       1.1  christos     if (request) {
    121       1.4  christos 	ND_TCHECK2(*param, 2);
    122       1.1  christos 	level = EXTRACT_LE_16BITS(param);
    123       1.1  christos 	fmt = "InfoLevel=[d]\n";
    124       1.4  christos 	smb_fdata(ndo, param, fmt, param + pcnt, unicodestr);
    125       1.1  christos     } else {
    126       1.1  christos 	switch (level) {
    127       1.1  christos 	case 1:
    128       1.1  christos 	    fmt = "idFileSystem=[W]\nSectorUnit=[D]\nUnit=[D]\nAvail=[D]\nSectorSize=[d]\n";
    129       1.1  christos 	    break;
    130       1.1  christos 	case 2:
    131       1.1  christos 	    fmt = "CreationTime=[T2]VolNameLength=[lb]\nVolumeLabel=[c]\n";
    132       1.1  christos 	    break;
    133       1.1  christos 	case 0x105:
    134       1.1  christos 	    fmt = "Capabilities=[W]\nMaxFileLen=[D]\nVolNameLen=[lD]\nVolume=[C]\n";
    135       1.1  christos 	    break;
    136       1.1  christos 	default:
    137       1.1  christos 	    fmt = "UnknownLevel\n";
    138       1.1  christos 	    break;
    139       1.1  christos 	}
    140       1.4  christos 	smb_fdata(ndo, data, fmt, data + dcnt, unicodestr);
    141       1.1  christos     }
    142       1.1  christos     if (dcnt) {
    143       1.4  christos 	ND_PRINT((ndo, "data:\n"));
    144       1.6  christos 	smb_print_data(ndo, data, dcnt);
    145       1.1  christos     }
    146       1.1  christos     return;
    147       1.1  christos trunc:
    148       1.4  christos     ND_PRINT((ndo, "%s", tstr));
    149       1.1  christos }
    150       1.1  christos 
    151       1.4  christos static const struct smbfnsint trans2_fns[] = {
    152       1.1  christos     { 0, "TRANSACT2_OPEN", 0,
    153       1.1  christos 	{ "Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[D]\nRes=([w, w, w, w, w])\nPath=[S]",
    154       1.1  christos 	  NULL,
    155       1.1  christos 	  "Handle=[d]\nAttrib=[A]\nTime=[T2]\nSize=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nInode=[W]\nOffErr=[d]\n|EALength=[d]\n",
    156       1.1  christos 	  NULL, NULL }},
    157       1.1  christos     { 1, "TRANSACT2_FINDFIRST", 0,
    158       1.1  christos 	{ NULL, NULL, NULL, NULL, trans2_findfirst }},
    159       1.1  christos     { 2, "TRANSACT2_FINDNEXT", 0, DEFDESCRIPT },
    160       1.1  christos     { 3, "TRANSACT2_QFSINFO", 0,
    161       1.1  christos 	{ NULL, NULL, NULL, NULL, trans2_qfsinfo }},
    162       1.1  christos     { 4, "TRANSACT2_SETFSINFO", 0, DEFDESCRIPT },
    163       1.1  christos     { 5, "TRANSACT2_QPATHINFO", 0, DEFDESCRIPT },
    164       1.1  christos     { 6, "TRANSACT2_SETPATHINFO", 0, DEFDESCRIPT },
    165       1.1  christos     { 7, "TRANSACT2_QFILEINFO", 0, DEFDESCRIPT },
    166       1.1  christos     { 8, "TRANSACT2_SETFILEINFO", 0, DEFDESCRIPT },
    167       1.1  christos     { 9, "TRANSACT2_FSCTL", 0, DEFDESCRIPT },
    168       1.1  christos     { 10, "TRANSACT2_IOCTL", 0, DEFDESCRIPT },
    169       1.1  christos     { 11, "TRANSACT2_FINDNOTIFYFIRST", 0, DEFDESCRIPT },
    170       1.1  christos     { 12, "TRANSACT2_FINDNOTIFYNEXT", 0, DEFDESCRIPT },
    171       1.1  christos     { 13, "TRANSACT2_MKDIR", 0, DEFDESCRIPT },
    172       1.1  christos     { -1, NULL, 0, DEFDESCRIPT }
    173       1.1  christos };
    174       1.1  christos 
    175       1.1  christos 
    176       1.1  christos static void
    177       1.4  christos print_trans2(netdissect_options *ndo,
    178       1.4  christos              const u_char *words, const u_char *dat, const u_char *buf, const u_char *maxbuf)
    179       1.1  christos {
    180       1.1  christos     u_int bcc;
    181       1.4  christos     static const struct smbfnsint *fn = &trans2_fns[0];
    182       1.1  christos     const u_char *data, *param;
    183       1.1  christos     const u_char *w = words + 1;
    184       1.1  christos     const char *f1 = NULL, *f2 = NULL;
    185       1.1  christos     int pcnt, dcnt;
    186       1.1  christos 
    187       1.4  christos     ND_TCHECK(words[0]);
    188       1.1  christos     if (request) {
    189       1.4  christos 	ND_TCHECK2(w[14 * 2], 2);
    190       1.1  christos 	pcnt = EXTRACT_LE_16BITS(w + 9 * 2);
    191       1.1  christos 	param = buf + EXTRACT_LE_16BITS(w + 10 * 2);
    192       1.1  christos 	dcnt = EXTRACT_LE_16BITS(w + 11 * 2);
    193       1.1  christos 	data = buf + EXTRACT_LE_16BITS(w + 12 * 2);
    194       1.1  christos 	fn = smbfindint(EXTRACT_LE_16BITS(w + 14 * 2), trans2_fns);
    195       1.1  christos     } else {
    196       1.1  christos 	if (words[0] == 0) {
    197       1.4  christos 	    ND_PRINT((ndo, "%s\n", fn->name));
    198       1.4  christos 	    ND_PRINT((ndo, "Trans2Interim\n"));
    199       1.1  christos 	    return;
    200       1.1  christos 	}
    201       1.4  christos 	ND_TCHECK2(w[7 * 2], 2);
    202       1.1  christos 	pcnt = EXTRACT_LE_16BITS(w + 3 * 2);
    203       1.1  christos 	param = buf + EXTRACT_LE_16BITS(w + 4 * 2);
    204       1.1  christos 	dcnt = EXTRACT_LE_16BITS(w + 6 * 2);
    205       1.1  christos 	data = buf + EXTRACT_LE_16BITS(w + 7 * 2);
    206       1.1  christos     }
    207       1.1  christos 
    208       1.4  christos     ND_PRINT((ndo, "%s param_length=%d data_length=%d\n", fn->name, pcnt, dcnt));
    209       1.1  christos 
    210       1.1  christos     if (request) {
    211       1.1  christos 	if (words[0] == 8) {
    212       1.4  christos 	    smb_fdata(ndo, words + 1,
    213       1.1  christos 		"Trans2Secondary\nTotParam=[d]\nTotData=[d]\nParamCnt=[d]\nParamOff=[d]\nParamDisp=[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nHandle=[d]\n",
    214       1.1  christos 		maxbuf, unicodestr);
    215       1.1  christos 	    return;
    216       1.1  christos 	} else {
    217       1.4  christos 	    smb_fdata(ndo, words + 1,
    218       1.1  christos 		"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",
    219       1.1  christos 		words + 1 + 14 * 2, unicodestr);
    220       1.1  christos 	}
    221       1.1  christos 	f1 = fn->descript.req_f1;
    222       1.1  christos 	f2 = fn->descript.req_f2;
    223       1.1  christos     } else {
    224       1.4  christos 	smb_fdata(ndo, words + 1,
    225       1.1  christos 	    "TotParam=[d]\nTotData=[d]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nParamDisp[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nSetupCnt=[b][P1]\n",
    226       1.1  christos 	    words + 1 + 10 * 2, unicodestr);
    227       1.1  christos 	f1 = fn->descript.rep_f1;
    228       1.1  christos 	f2 = fn->descript.rep_f2;
    229       1.1  christos     }
    230       1.1  christos 
    231       1.4  christos     ND_TCHECK2(*dat, 2);
    232       1.1  christos     bcc = EXTRACT_LE_16BITS(dat);
    233       1.4  christos     ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
    234       1.1  christos     if (fn->descript.fn)
    235       1.4  christos 	(*fn->descript.fn)(ndo, param, data, pcnt, dcnt);
    236       1.1  christos     else {
    237       1.4  christos 	smb_fdata(ndo, param, f1 ? f1 : "Parameters=\n", param + pcnt, unicodestr);
    238       1.4  christos 	smb_fdata(ndo, data, f2 ? f2 : "Data=\n", data + dcnt, unicodestr);
    239       1.1  christos     }
    240       1.1  christos     return;
    241       1.1  christos trunc:
    242       1.4  christos     ND_PRINT((ndo, "%s", tstr));
    243       1.1  christos }
    244       1.1  christos 
    245       1.1  christos static void
    246       1.4  christos print_browse(netdissect_options *ndo,
    247       1.4  christos              const u_char *param, int paramlen, const u_char *data, int datalen)
    248       1.1  christos {
    249       1.1  christos     const u_char *maxbuf = data + datalen;
    250       1.1  christos     int command;
    251       1.1  christos 
    252       1.4  christos     ND_TCHECK(data[0]);
    253       1.1  christos     command = data[0];
    254       1.1  christos 
    255       1.4  christos     smb_fdata(ndo, param, "BROWSE PACKET\n|Param ", param+paramlen, unicodestr);
    256       1.1  christos 
    257       1.1  christos     switch (command) {
    258       1.1  christos     case 0xF:
    259       1.4  christos 	data = smb_fdata(ndo, data,
    260       1.1  christos 	    "BROWSE PACKET:\nType=[B] (LocalMasterAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
    261       1.1  christos 	    maxbuf, unicodestr);
    262       1.1  christos 	break;
    263       1.1  christos 
    264       1.1  christos     case 0x1:
    265       1.4  christos 	data = smb_fdata(ndo, data,
    266       1.1  christos 	    "BROWSE PACKET:\nType=[B] (HostAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
    267       1.1  christos 	    maxbuf, unicodestr);
    268       1.1  christos 	break;
    269       1.1  christos 
    270       1.1  christos     case 0x2:
    271       1.4  christos 	data = smb_fdata(ndo, data,
    272       1.1  christos 	    "BROWSE PACKET:\nType=[B] (AnnouncementRequest)\nFlags=[B]\nReplySystemName=[S]\n",
    273       1.1  christos 	    maxbuf, unicodestr);
    274       1.1  christos 	break;
    275       1.1  christos 
    276       1.1  christos     case 0xc:
    277       1.4  christos 	data = smb_fdata(ndo, data,
    278       1.1  christos 	    "BROWSE PACKET:\nType=[B] (WorkgroupAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nCommentPointer=[W]\nServerName=[S]\n",
    279       1.1  christos 	    maxbuf, unicodestr);
    280       1.1  christos 	break;
    281       1.1  christos 
    282       1.1  christos     case 0x8:
    283       1.4  christos 	data = smb_fdata(ndo, data,
    284       1.1  christos 	    "BROWSE PACKET:\nType=[B] (ElectionFrame)\nElectionVersion=[B]\nOSSummary=[W]\nUptime=[(W, W)]\nServerName=[S]\n",
    285       1.1  christos 	    maxbuf, unicodestr);
    286       1.1  christos 	break;
    287       1.1  christos 
    288       1.1  christos     case 0xb:
    289       1.4  christos 	data = smb_fdata(ndo, data,
    290       1.1  christos 	    "BROWSE PACKET:\nType=[B] (BecomeBackupBrowser)\nName=[S]\n",
    291       1.1  christos 	    maxbuf, unicodestr);
    292       1.1  christos 	break;
    293       1.1  christos 
    294       1.1  christos     case 0x9:
    295       1.4  christos 	data = smb_fdata(ndo, data,
    296       1.1  christos 	    "BROWSE PACKET:\nType=[B] (GetBackupList)\nListCount?=[B]\nToken=[W]\n",
    297       1.1  christos 	    maxbuf, unicodestr);
    298       1.1  christos 	break;
    299       1.1  christos 
    300       1.1  christos     case 0xa:
    301       1.4  christos 	data = smb_fdata(ndo, data,
    302       1.1  christos 	    "BROWSE PACKET:\nType=[B] (BackupListResponse)\nServerCount?=[B]\nToken=[W]\n*Name=[S]\n",
    303       1.1  christos 	    maxbuf, unicodestr);
    304       1.1  christos 	break;
    305       1.1  christos 
    306       1.1  christos     case 0xd:
    307       1.4  christos 	data = smb_fdata(ndo, data,
    308       1.1  christos 	    "BROWSE PACKET:\nType=[B] (MasterAnnouncement)\nMasterName=[S]\n",
    309       1.1  christos 	    maxbuf, unicodestr);
    310       1.1  christos 	break;
    311       1.1  christos 
    312       1.1  christos     case 0xe:
    313       1.4  christos 	data = smb_fdata(ndo, data,
    314       1.1  christos 	    "BROWSE PACKET:\nType=[B] (ResetBrowser)\nOptions=[B]\n", maxbuf, unicodestr);
    315       1.1  christos 	break;
    316       1.1  christos 
    317       1.1  christos     default:
    318       1.4  christos 	data = smb_fdata(ndo, data, "Unknown Browser Frame ", maxbuf, unicodestr);
    319       1.1  christos 	break;
    320       1.1  christos     }
    321       1.1  christos     return;
    322       1.1  christos trunc:
    323       1.4  christos     ND_PRINT((ndo, "%s", tstr));
    324       1.1  christos }
    325       1.1  christos 
    326       1.1  christos 
    327       1.1  christos static void
    328       1.4  christos print_ipc(netdissect_options *ndo,
    329       1.4  christos           const u_char *param, int paramlen, const u_char *data, int datalen)
    330       1.1  christos {
    331       1.1  christos     if (paramlen)
    332       1.4  christos 	smb_fdata(ndo, param, "Command=[w]\nStr1=[S]\nStr2=[S]\n", param + paramlen,
    333       1.1  christos 	    unicodestr);
    334       1.1  christos     if (datalen)
    335       1.4  christos 	smb_fdata(ndo, data, "IPC ", data + datalen, unicodestr);
    336       1.1  christos }
    337       1.1  christos 
    338       1.1  christos 
    339       1.1  christos static void
    340       1.4  christos print_trans(netdissect_options *ndo,
    341       1.4  christos             const u_char *words, const u_char *data1, const u_char *buf, const u_char *maxbuf)
    342       1.1  christos {
    343       1.1  christos     u_int bcc;
    344       1.1  christos     const char *f1, *f2, *f3, *f4;
    345       1.1  christos     const u_char *data, *param;
    346       1.1  christos     const u_char *w = words + 1;
    347       1.1  christos     int datalen, paramlen;
    348       1.1  christos 
    349       1.1  christos     if (request) {
    350       1.4  christos 	ND_TCHECK2(w[12 * 2], 2);
    351       1.1  christos 	paramlen = EXTRACT_LE_16BITS(w + 9 * 2);
    352       1.1  christos 	param = buf + EXTRACT_LE_16BITS(w + 10 * 2);
    353       1.1  christos 	datalen = EXTRACT_LE_16BITS(w + 11 * 2);
    354       1.1  christos 	data = buf + EXTRACT_LE_16BITS(w + 12 * 2);
    355       1.1  christos 	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";
    356       1.1  christos 	f2 = "|Name=[S]\n";
    357       1.1  christos 	f3 = "|Param ";
    358       1.1  christos 	f4 = "|Data ";
    359       1.1  christos     } else {
    360       1.4  christos 	ND_TCHECK2(w[7 * 2], 2);
    361       1.1  christos 	paramlen = EXTRACT_LE_16BITS(w + 3 * 2);
    362       1.1  christos 	param = buf + EXTRACT_LE_16BITS(w + 4 * 2);
    363       1.1  christos 	datalen = EXTRACT_LE_16BITS(w + 6 * 2);
    364       1.1  christos 	data = buf + EXTRACT_LE_16BITS(w + 7 * 2);
    365       1.1  christos 	f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nRes1=[d]\nParamCnt=[d] \nParamOff=[d] \nRes2=[d] \nDataCnt=[d] \nDataOff=[d] \nRes3=[d]\nLsetup=[d]\n";
    366       1.1  christos 	f2 = "|Unknown ";
    367       1.1  christos 	f3 = "|Param ";
    368       1.1  christos 	f4 = "|Data ";
    369       1.1  christos     }
    370       1.1  christos 
    371       1.4  christos     smb_fdata(ndo, words + 1, f1, min(words + 1 + 2 * words[0], maxbuf),
    372       1.1  christos         unicodestr);
    373       1.1  christos 
    374       1.4  christos     ND_TCHECK2(*data1, 2);
    375       1.1  christos     bcc = EXTRACT_LE_16BITS(data1);
    376       1.4  christos     ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
    377       1.1  christos     if (bcc > 0) {
    378       1.4  christos 	smb_fdata(ndo, data1 + 2, f2, maxbuf - (paramlen + datalen), unicodestr);
    379  1.7.12.1    martin #define MAILSLOT_BROWSE_STR "\\MAILSLOT\\BROWSE"
    380  1.7.12.1    martin 	ND_TCHECK2(*(data1 + 2), strlen(MAILSLOT_BROWSE_STR) + 1);
    381  1.7.12.1    martin 	if (strcmp((const char *)(data1 + 2), MAILSLOT_BROWSE_STR) == 0) {
    382       1.4  christos 	    print_browse(ndo, param, paramlen, data, datalen);
    383       1.1  christos 	    return;
    384       1.1  christos 	}
    385  1.7.12.1    martin #undef MAILSLOT_BROWSE_STR
    386       1.1  christos 
    387  1.7.12.1    martin #define PIPE_LANMAN_STR "\\PIPE\\LANMAN"
    388  1.7.12.1    martin 	ND_TCHECK2(*(data1 + 2), strlen(PIPE_LANMAN_STR) + 1);
    389  1.7.12.1    martin 	if (strcmp((const char *)(data1 + 2), PIPE_LANMAN_STR) == 0) {
    390       1.4  christos 	    print_ipc(ndo, param, paramlen, data, datalen);
    391       1.1  christos 	    return;
    392       1.1  christos 	}
    393  1.7.12.1    martin #undef PIPE_LANMAN_STR
    394       1.1  christos 
    395       1.1  christos 	if (paramlen)
    396       1.4  christos 	    smb_fdata(ndo, param, f3, min(param + paramlen, maxbuf), unicodestr);
    397       1.1  christos 	if (datalen)
    398       1.4  christos 	    smb_fdata(ndo, data, f4, min(data + datalen, maxbuf), unicodestr);
    399       1.1  christos     }
    400       1.1  christos     return;
    401       1.1  christos trunc:
    402       1.4  christos     ND_PRINT((ndo, "%s", tstr));
    403       1.1  christos }
    404       1.1  christos 
    405       1.1  christos 
    406       1.1  christos static void
    407       1.4  christos print_negprot(netdissect_options *ndo,
    408       1.4  christos               const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
    409       1.1  christos {
    410       1.1  christos     u_int wct, bcc;
    411       1.1  christos     const char *f1 = NULL, *f2 = NULL;
    412       1.1  christos 
    413       1.4  christos     ND_TCHECK(words[0]);
    414       1.1  christos     wct = words[0];
    415       1.1  christos     if (request)
    416       1.1  christos 	f2 = "*|Dialect=[Y]\n";
    417       1.1  christos     else {
    418       1.1  christos 	if (wct == 1)
    419       1.1  christos 	    f1 = "Core Protocol\nDialectIndex=[d]";
    420       1.1  christos 	else if (wct == 17)
    421       1.1  christos 	    f1 = "NT1 Protocol\nDialectIndex=[d]\nSecMode=[B]\nMaxMux=[d]\nNumVcs=[d]\nMaxBuffer=[D]\nRawSize=[D]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[d]\nCryptKey=";
    422       1.1  christos 	else if (wct == 13)
    423       1.1  christos 	    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=";
    424       1.1  christos     }
    425       1.1  christos 
    426       1.1  christos     if (f1)
    427       1.4  christos 	smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf),
    428       1.1  christos 	    unicodestr);
    429       1.1  christos     else
    430       1.6  christos 	smb_print_data(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
    431       1.1  christos 
    432       1.4  christos     ND_TCHECK2(*data, 2);
    433       1.1  christos     bcc = EXTRACT_LE_16BITS(data);
    434       1.4  christos     ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
    435       1.1  christos     if (bcc > 0) {
    436       1.1  christos 	if (f2)
    437       1.4  christos 	    smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data),
    438       1.1  christos 		maxbuf), unicodestr);
    439       1.1  christos 	else
    440       1.6  christos 	    smb_print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
    441       1.1  christos     }
    442       1.1  christos     return;
    443       1.1  christos trunc:
    444       1.4  christos     ND_PRINT((ndo, "%s", tstr));
    445       1.1  christos }
    446       1.1  christos 
    447       1.1  christos static void
    448       1.4  christos print_sesssetup(netdissect_options *ndo,
    449       1.4  christos                 const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
    450       1.1  christos {
    451       1.1  christos     u_int wct, bcc;
    452       1.1  christos     const char *f1 = NULL, *f2 = NULL;
    453       1.1  christos 
    454       1.4  christos     ND_TCHECK(words[0]);
    455       1.1  christos     wct = words[0];
    456       1.1  christos     if (request) {
    457       1.1  christos 	if (wct == 10)
    458       1.1  christos 	    f1 = "Com2=[w]\nOff2=[d]\nBufSize=[d]\nMpxMax=[d]\nVcNum=[d]\nSessionKey=[W]\nPassLen=[d]\nCryptLen=[d]\nCryptOff=[d]\nPass&Name=\n";
    459       1.1  christos 	else
    460       1.1  christos 	    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";
    461       1.1  christos     } else {
    462       1.1  christos 	if (wct == 3) {
    463       1.1  christos 	    f1 = "Com2=[w]\nOff2=[d]\nAction=[w]\n";
    464       1.1  christos 	} else if (wct == 13) {
    465       1.1  christos 	    f1 = "Com2=[B]\nRes=[B]\nOff2=[d]\nAction=[w]\n";
    466       1.1  christos 	    f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n";
    467       1.1  christos 	}
    468       1.1  christos     }
    469       1.1  christos 
    470       1.1  christos     if (f1)
    471       1.4  christos 	smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf),
    472       1.1  christos 	    unicodestr);
    473       1.1  christos     else
    474       1.6  christos 	smb_print_data(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
    475       1.1  christos 
    476       1.4  christos     ND_TCHECK2(*data, 2);
    477       1.1  christos     bcc = EXTRACT_LE_16BITS(data);
    478       1.4  christos     ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
    479       1.1  christos     if (bcc > 0) {
    480       1.1  christos 	if (f2)
    481       1.4  christos 	    smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data),
    482       1.1  christos 		maxbuf), unicodestr);
    483       1.1  christos 	else
    484       1.6  christos 	    smb_print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
    485       1.1  christos     }
    486       1.1  christos     return;
    487       1.1  christos trunc:
    488       1.4  christos     ND_PRINT((ndo, "%s", tstr));
    489       1.1  christos }
    490       1.1  christos 
    491       1.1  christos static void
    492       1.4  christos print_lockingandx(netdissect_options *ndo,
    493       1.4  christos                   const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
    494       1.1  christos {
    495       1.1  christos     u_int wct, bcc;
    496       1.1  christos     const u_char *maxwords;
    497       1.1  christos     const char *f1 = NULL, *f2 = NULL;
    498       1.1  christos 
    499       1.4  christos     ND_TCHECK(words[0]);
    500       1.1  christos     wct = words[0];
    501       1.1  christos     if (request) {
    502       1.1  christos 	f1 = "Com2=[w]\nOff2=[d]\nHandle=[d]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[d]\nLockCount=[d]\n";
    503       1.4  christos 	ND_TCHECK(words[7]);
    504       1.1  christos 	if (words[7] & 0x10)
    505       1.1  christos 	    f2 = "*Process=[d]\n[P2]Offset=[M]\nLength=[M]\n";
    506       1.1  christos 	else
    507       1.1  christos 	    f2 = "*Process=[d]\nOffset=[D]\nLength=[D]\n";
    508       1.1  christos     } else {
    509       1.1  christos 	f1 = "Com2=[w]\nOff2=[d]\n";
    510       1.1  christos     }
    511       1.1  christos 
    512       1.4  christos     maxwords = min(words + 1 + wct * 2, maxbuf);
    513       1.1  christos     if (wct)
    514       1.4  christos 	smb_fdata(ndo, words + 1, f1, maxwords, unicodestr);
    515       1.1  christos 
    516       1.4  christos     ND_TCHECK2(*data, 2);
    517       1.1  christos     bcc = EXTRACT_LE_16BITS(data);
    518       1.4  christos     ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
    519       1.1  christos     if (bcc > 0) {
    520       1.1  christos 	if (f2)
    521       1.4  christos 	    smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data),
    522       1.1  christos 		maxbuf), unicodestr);
    523       1.1  christos 	else
    524       1.6  christos 	    smb_print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
    525       1.1  christos     }
    526       1.1  christos     return;
    527       1.1  christos trunc:
    528       1.4  christos     ND_PRINT((ndo, "%s", tstr));
    529       1.1  christos }
    530       1.1  christos 
    531       1.1  christos 
    532       1.4  christos static const struct smbfns smb_fns[] = {
    533       1.1  christos     { -1, "SMBunknown", 0, DEFDESCRIPT },
    534       1.1  christos 
    535       1.1  christos     { SMBtcon, "SMBtcon", 0,
    536       1.1  christos 	{ NULL, "Path=[Z]\nPassword=[Z]\nDevice=[Z]\n",
    537       1.1  christos 	  "MaxXmit=[d]\nTreeId=[d]\n", NULL,
    538       1.1  christos 	  NULL } },
    539       1.1  christos 
    540       1.1  christos     { SMBtdis, "SMBtdis", 0, DEFDESCRIPT },
    541       1.1  christos     { SMBexit,  "SMBexit", 0, DEFDESCRIPT },
    542       1.1  christos     { SMBioctl, "SMBioctl", 0, DEFDESCRIPT },
    543       1.1  christos 
    544       1.1  christos     { SMBecho, "SMBecho", 0,
    545       1.1  christos 	{ "ReverbCount=[d]\n", NULL,
    546       1.1  christos 	  "SequenceNum=[d]\n", NULL,
    547       1.1  christos 	  NULL } },
    548       1.1  christos 
    549       1.1  christos     { SMBulogoffX, "SMBulogoffX", FLG_CHAIN, DEFDESCRIPT },
    550       1.1  christos 
    551       1.1  christos     { SMBgetatr, "SMBgetatr", 0,
    552       1.1  christos 	{ NULL, "Path=[Z]\n",
    553       1.1  christos 	  "Attribute=[A]\nTime=[T2]Size=[D]\nRes=([w,w,w,w,w])\n", NULL,
    554       1.1  christos 	  NULL } },
    555       1.1  christos 
    556       1.1  christos     { SMBsetatr, "SMBsetatr", 0,
    557       1.1  christos 	{ "Attribute=[A]\nTime=[T2]Res=([w,w,w,w,w])\n", "Path=[Z]\n",
    558       1.1  christos 	  NULL, NULL, NULL } },
    559       1.1  christos 
    560       1.1  christos     { SMBchkpth, "SMBchkpth", 0,
    561       1.1  christos        { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
    562       1.1  christos 
    563       1.1  christos     { SMBsearch, "SMBsearch", 0,
    564       1.1  christos 	{ "Count=[d]\nAttrib=[A]\n",
    565       1.1  christos 	  "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\n",
    566       1.1  christos 	  "Count=[d]\n",
    567       1.1  christos 	  "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",
    568       1.1  christos 	  NULL } },
    569       1.1  christos 
    570       1.1  christos     { SMBopen, "SMBopen", 0,
    571       1.1  christos 	{ "Mode=[w]\nAttribute=[A]\n", "Path=[Z]\n",
    572       1.1  christos 	  "Handle=[d]\nOAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\n",
    573       1.1  christos 	  NULL, NULL } },
    574       1.1  christos 
    575       1.1  christos     { SMBcreate, "SMBcreate", 0,
    576       1.1  christos 	{ "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } },
    577       1.1  christos 
    578       1.1  christos     { SMBmknew, "SMBmknew", 0,
    579       1.1  christos 	{ "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } },
    580       1.1  christos 
    581       1.1  christos     { SMBunlink, "SMBunlink", 0,
    582       1.1  christos 	{ "Attrib=[A]\n", "Path=[Z]\n", NULL, NULL, NULL } },
    583       1.1  christos 
    584       1.1  christos     { SMBread, "SMBread", 0,
    585       1.1  christos 	{ "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
    586       1.1  christos 	  "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } },
    587       1.1  christos 
    588       1.1  christos     { SMBwrite, "SMBwrite", 0,
    589       1.1  christos 	{ "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
    590       1.1  christos 	  "Count=[d]\n", NULL, NULL } },
    591       1.1  christos 
    592       1.1  christos     { SMBclose, "SMBclose", 0,
    593       1.1  christos 	{ "Handle=[d]\nTime=[T2]", NULL, NULL, NULL, NULL } },
    594       1.1  christos 
    595       1.1  christos     { SMBmkdir, "SMBmkdir", 0,
    596       1.1  christos 	{ NULL, "Path=[Z]\n", NULL, NULL, NULL } },
    597       1.1  christos 
    598       1.1  christos     { SMBrmdir, "SMBrmdir", 0,
    599       1.1  christos 	{ NULL, "Path=[Z]\n", NULL, NULL, NULL } },
    600       1.1  christos 
    601       1.1  christos     { SMBdskattr, "SMBdskattr", 0,
    602       1.1  christos 	{ NULL, NULL,
    603       1.1  christos 	  "TotalUnits=[d]\nBlocksPerUnit=[d]\nBlockSize=[d]\nFreeUnits=[d]\nMedia=[w]\n",
    604       1.1  christos 	  NULL, NULL } },
    605       1.1  christos 
    606       1.1  christos     { SMBmv, "SMBmv", 0,
    607       1.1  christos 	{ "Attrib=[A]\n", "OldPath=[Z]\nNewPath=[Z]\n", NULL, NULL, NULL } },
    608       1.1  christos 
    609       1.1  christos     /*
    610       1.1  christos      * this is a Pathworks specific call, allowing the
    611       1.1  christos      * changing of the root path
    612       1.1  christos      */
    613       1.1  christos     { pSETDIR, "SMBsetdir", 0, { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
    614       1.1  christos 
    615       1.1  christos     { SMBlseek, "SMBlseek", 0,
    616       1.1  christos 	{ "Handle=[d]\nMode=[w]\nOffset=[D]\n", "Offset=[D]\n", NULL, NULL, NULL } },
    617       1.1  christos 
    618       1.1  christos     { SMBflush, "SMBflush", 0, { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
    619       1.1  christos 
    620       1.1  christos     { SMBsplopen, "SMBsplopen", 0,
    621       1.1  christos 	{ "SetupLen=[d]\nMode=[w]\n", "Ident=[Z]\n", "Handle=[d]\n",
    622       1.1  christos 	  NULL, NULL } },
    623       1.1  christos 
    624       1.1  christos     { SMBsplclose, "SMBsplclose", 0,
    625       1.1  christos 	{ "Handle=[d]\n", NULL, NULL, NULL, NULL } },
    626       1.1  christos 
    627       1.1  christos     { SMBsplretq, "SMBsplretq", 0,
    628       1.1  christos 	{ "MaxCount=[d]\nStartIndex=[d]\n", NULL,
    629       1.1  christos 	  "Count=[d]\nIndex=[d]\n",
    630       1.1  christos 	  "*Time=[T2]Status=[B]\nJobID=[d]\nSize=[D]\nRes=[B]Name=[s16]\n",
    631       1.1  christos 	  NULL } },
    632       1.1  christos 
    633       1.1  christos     { SMBsplwr, "SMBsplwr", 0,
    634       1.1  christos 	{ "Handle=[d]\n", NULL, NULL, NULL, NULL } },
    635       1.1  christos 
    636       1.1  christos     { SMBlock, "SMBlock", 0,
    637       1.1  christos 	{ "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
    638       1.1  christos 
    639       1.1  christos     { SMBunlock, "SMBunlock", 0,
    640       1.1  christos 	{ "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
    641       1.1  christos 
    642       1.1  christos     /* CORE+ PROTOCOL FOLLOWS */
    643       1.1  christos 
    644       1.1  christos     { SMBreadbraw, "SMBreadbraw", 0,
    645       1.1  christos 	{ "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[d]\n",
    646       1.1  christos 	  NULL, NULL, NULL, NULL } },
    647       1.1  christos 
    648       1.1  christos     { SMBwritebraw, "SMBwritebraw", 0,
    649       1.1  christos 	{ "Handle=[d]\nTotalCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\n|DataSize=[d]\nDataOff=[d]\n",
    650       1.1  christos 	  NULL, "WriteRawAck", NULL, NULL } },
    651       1.1  christos 
    652       1.1  christos     { SMBwritec, "SMBwritec", 0,
    653       1.1  christos 	{ NULL, NULL, "Count=[d]\n", NULL, NULL } },
    654       1.1  christos 
    655       1.1  christos     { SMBwriteclose, "SMBwriteclose", 0,
    656       1.1  christos 	{ "Handle=[d]\nCount=[d]\nOffset=[D]\nTime=[T2]Res=([w,w,w,w,w,w])",
    657       1.1  christos 	  NULL, "Count=[d]\n", NULL, NULL } },
    658       1.1  christos 
    659       1.1  christos     { SMBlockread, "SMBlockread", 0,
    660       1.1  christos 	{ "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
    661       1.1  christos 	  "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } },
    662       1.1  christos 
    663       1.1  christos     { SMBwriteunlock, "SMBwriteunlock", 0,
    664       1.1  christos 	{ "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
    665       1.1  christos 	  "Count=[d]\n", NULL, NULL } },
    666       1.1  christos 
    667       1.1  christos     { SMBreadBmpx, "SMBreadBmpx", 0,
    668       1.1  christos 	{ "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[w]\n",
    669       1.1  christos 	  NULL,
    670       1.1  christos 	  "Offset=[D]\nTotCount=[d]\nRemaining=[d]\nRes=([w,w])\nDataSize=[d]\nDataOff=[d]\n",
    671       1.1  christos 	  NULL, NULL } },
    672       1.1  christos 
    673       1.1  christos     { SMBwriteBmpx, "SMBwriteBmpx", 0,
    674       1.1  christos 	{ "Handle=[d]\nTotCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\nDataSize=[d]\nDataOff=[d]\n", NULL,
    675       1.1  christos 	  "Remaining=[d]\n", NULL, NULL } },
    676       1.1  christos 
    677       1.1  christos     { SMBwriteBs, "SMBwriteBs", 0,
    678       1.1  christos 	{ "Handle=[d]\nTotCount=[d]\nOffset=[D]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\n",
    679       1.1  christos 	  NULL, "Count=[d]\n", NULL, NULL } },
    680       1.1  christos 
    681       1.1  christos     { SMBsetattrE, "SMBsetattrE", 0,
    682       1.1  christos 	{ "Handle=[d]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]", NULL,
    683       1.1  christos 	  NULL, NULL, NULL } },
    684       1.1  christos 
    685       1.1  christos     { SMBgetattrE, "SMBgetattrE", 0,
    686       1.1  christos 	{ "Handle=[d]\n", NULL,
    687       1.1  christos 	  "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D]\nAllocSize=[D]\nAttribute=[A]\n",
    688       1.1  christos 	  NULL, NULL } },
    689       1.1  christos 
    690       1.1  christos     { SMBtranss, "SMBtranss", 0, DEFDESCRIPT },
    691       1.1  christos     { SMBioctls, "SMBioctls", 0, DEFDESCRIPT },
    692       1.1  christos 
    693       1.1  christos     { SMBcopy, "SMBcopy", 0,
    694       1.1  christos 	{ "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
    695       1.1  christos 	  "CopyCount=[d]\n",  "|ErrStr=[S]\n",  NULL } },
    696       1.1  christos 
    697       1.1  christos     { SMBmove, "SMBmove", 0,
    698       1.1  christos 	{ "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
    699       1.1  christos 	  "MoveCount=[d]\n",  "|ErrStr=[S]\n",  NULL } },
    700       1.1  christos 
    701       1.1  christos     { SMBopenX, "SMBopenX", FLG_CHAIN,
    702       1.1  christos 	{ "Com2=[w]\nOff2=[d]\nFlags=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]OFun=[w]\nSize=[D]\nTimeOut=[D]\nRes=[W]\n",
    703       1.1  christos 	  "Path=[S]\n",
    704       1.1  christos 	  "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",
    705       1.1  christos 	  NULL, NULL } },
    706       1.1  christos 
    707       1.1  christos     { SMBreadX, "SMBreadX", FLG_CHAIN,
    708       1.1  christos 	{ "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nCountLeft=[d]\n",
    709       1.1  christos 	  NULL,
    710       1.1  christos 	  "Com2=[w]\nOff2=[d]\nRemaining=[d]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\nRes=([w,w,w,w])\n",
    711       1.1  christos 	  NULL, NULL } },
    712       1.1  christos 
    713       1.1  christos     { SMBwriteX, "SMBwriteX", FLG_CHAIN,
    714       1.1  christos 	{ "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nCountLeft=[d]\nRes=[w]\nDataSize=[d]\nDataOff=[d]\n",
    715       1.1  christos 	  NULL,
    716       1.1  christos 	  "Com2=[w]\nOff2=[d]\nCount=[d]\nRemaining=[d]\nRes=[W]\n",
    717       1.1  christos 	  NULL, NULL } },
    718       1.1  christos 
    719       1.1  christos     { SMBffirst, "SMBffirst", 0,
    720       1.1  christos 	{ "Count=[d]\nAttrib=[A]\n",
    721       1.1  christos 	  "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
    722       1.1  christos 	  "Count=[d]\n",
    723       1.1  christos 	  "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",
    724       1.1  christos 	  NULL } },
    725       1.1  christos 
    726       1.1  christos     { SMBfunique, "SMBfunique", 0,
    727       1.1  christos 	{ "Count=[d]\nAttrib=[A]\n",
    728       1.1  christos 	  "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
    729       1.1  christos 	  "Count=[d]\n",
    730       1.1  christos 	  "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",
    731       1.1  christos 	  NULL } },
    732       1.1  christos 
    733       1.1  christos     { SMBfclose, "SMBfclose", 0,
    734       1.1  christos 	{ "Count=[d]\nAttrib=[A]\n",
    735       1.1  christos 	  "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
    736       1.1  christos 	  "Count=[d]\n",
    737       1.1  christos 	  "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",
    738       1.1  christos 	  NULL } },
    739       1.1  christos 
    740       1.1  christos     { SMBfindnclose, "SMBfindnclose", 0,
    741       1.1  christos 	{ "Handle=[d]\n", NULL, NULL, NULL, NULL } },
    742       1.1  christos 
    743       1.1  christos     { SMBfindclose, "SMBfindclose", 0,
    744       1.1  christos 	{ "Handle=[d]\n", NULL, NULL, NULL, NULL } },
    745       1.1  christos 
    746       1.1  christos     { SMBsends, "SMBsends", 0,
    747       1.1  christos 	{ NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
    748       1.1  christos 
    749       1.1  christos     { SMBsendstrt, "SMBsendstrt", 0,
    750       1.1  christos 	{ NULL, "Source=[Z]\nDest=[Z]\n", "GroupID=[d]\n", NULL, NULL } },
    751       1.1  christos 
    752       1.1  christos     { SMBsendend, "SMBsendend", 0,
    753       1.1  christos 	{ "GroupID=[d]\n", NULL, NULL, NULL, NULL } },
    754       1.1  christos 
    755       1.1  christos     { SMBsendtxt, "SMBsendtxt", 0,
    756       1.1  christos 	{ "GroupID=[d]\n", NULL, NULL, NULL, NULL } },
    757       1.1  christos 
    758       1.1  christos     { SMBsendb, "SMBsendb", 0,
    759       1.1  christos 	{ NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
    760       1.1  christos 
    761       1.1  christos     { SMBfwdname, "SMBfwdname", 0, DEFDESCRIPT },
    762       1.1  christos     { SMBcancelf, "SMBcancelf", 0, DEFDESCRIPT },
    763       1.1  christos     { SMBgetmac, "SMBgetmac", 0, DEFDESCRIPT },
    764       1.1  christos 
    765       1.1  christos     { SMBnegprot, "SMBnegprot", 0,
    766       1.1  christos 	{ NULL, NULL, NULL, NULL, print_negprot } },
    767       1.1  christos 
    768       1.1  christos     { SMBsesssetupX, "SMBsesssetupX", FLG_CHAIN,
    769       1.1  christos 	{ NULL, NULL, NULL, NULL, print_sesssetup } },
    770       1.1  christos 
    771       1.1  christos     { SMBtconX, "SMBtconX", FLG_CHAIN,
    772       1.1  christos 	{ "Com2=[w]\nOff2=[d]\nFlags=[w]\nPassLen=[d]\nPasswd&Path&Device=\n",
    773       1.1  christos 	  NULL, "Com2=[w]\nOff2=[d]\n", "ServiceType=[R]\n", NULL } },
    774       1.1  christos 
    775       1.1  christos     { SMBlockingX, "SMBlockingX", FLG_CHAIN,
    776       1.1  christos 	{ NULL, NULL, NULL, NULL, print_lockingandx } },
    777       1.1  christos 
    778       1.1  christos     { SMBtrans2, "SMBtrans2", 0, { NULL, NULL, NULL, NULL, print_trans2 } },
    779       1.1  christos 
    780       1.1  christos     { SMBtranss2, "SMBtranss2", 0, DEFDESCRIPT },
    781       1.1  christos     { SMBctemp, "SMBctemp", 0, DEFDESCRIPT },
    782       1.1  christos     { SMBreadBs, "SMBreadBs", 0, DEFDESCRIPT },
    783       1.1  christos     { SMBtrans, "SMBtrans", 0, { NULL, NULL, NULL, NULL, print_trans } },
    784       1.1  christos 
    785       1.1  christos     { SMBnttrans, "SMBnttrans", 0, DEFDESCRIPT },
    786       1.1  christos     { SMBnttranss, "SMBnttranss", 0, DEFDESCRIPT },
    787       1.1  christos 
    788       1.1  christos     { SMBntcreateX, "SMBntcreateX", FLG_CHAIN,
    789       1.1  christos 	{ "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",
    790       1.1  christos 	  "Path=[C]\n",
    791       1.1  christos 	  "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",
    792       1.1  christos 	  NULL, NULL } },
    793       1.1  christos 
    794       1.1  christos     { SMBntcancel, "SMBntcancel", 0, DEFDESCRIPT },
    795       1.1  christos 
    796       1.1  christos     { -1, NULL, 0, DEFDESCRIPT }
    797       1.1  christos };
    798       1.1  christos 
    799       1.1  christos 
    800       1.1  christos /*
    801       1.1  christos  * print a SMB message
    802       1.1  christos  */
    803       1.1  christos static void
    804       1.4  christos print_smb(netdissect_options *ndo,
    805       1.4  christos           const u_char *buf, const u_char *maxbuf)
    806       1.1  christos {
    807       1.4  christos     uint16_t flags2;
    808       1.1  christos     int nterrcodes;
    809       1.1  christos     int command;
    810       1.4  christos     uint32_t nterror;
    811       1.1  christos     const u_char *words, *maxwords, *data;
    812       1.4  christos     const struct smbfns *fn;
    813       1.1  christos     const char *fmt_smbheader =
    814       1.1  christos         "[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";
    815       1.1  christos     int smboffset;
    816       1.1  christos 
    817       1.4  christos     ND_TCHECK(buf[9]);
    818       1.1  christos     request = (buf[9] & 0x80) ? 0 : 1;
    819       1.1  christos     startbuf = buf;
    820       1.1  christos 
    821       1.1  christos     command = buf[4];
    822       1.1  christos 
    823       1.1  christos     fn = smbfind(command, smb_fns);
    824       1.1  christos 
    825       1.4  christos     if (ndo->ndo_vflag > 1)
    826       1.4  christos 	ND_PRINT((ndo, "\n"));
    827       1.1  christos 
    828       1.4  christos     ND_PRINT((ndo, "SMB PACKET: %s (%s)\n", fn->name, request ? "REQUEST" : "REPLY"));
    829       1.1  christos 
    830       1.4  christos     if (ndo->ndo_vflag < 2)
    831       1.1  christos 	return;
    832       1.1  christos 
    833       1.7       spz     ND_TCHECK_16BITS(&buf[10]);
    834       1.7       spz     flags2 = EXTRACT_LE_16BITS(&buf[10]);
    835       1.7       spz     unicodestr = flags2 & 0x8000;
    836       1.7       spz     nterrcodes = flags2 & 0x4000;
    837       1.7       spz 
    838       1.1  christos     /* print out the header */
    839       1.4  christos     smb_fdata(ndo, buf, fmt_smbheader, buf + 33, unicodestr);
    840       1.1  christos 
    841       1.1  christos     if (nterrcodes) {
    842       1.1  christos     	nterror = EXTRACT_LE_32BITS(&buf[5]);
    843       1.1  christos 	if (nterror)
    844       1.4  christos 	    ND_PRINT((ndo, "NTError = %s\n", nt_errstr(nterror)));
    845       1.1  christos     } else {
    846       1.1  christos 	if (buf[5])
    847       1.4  christos 	    ND_PRINT((ndo, "SMBError = %s\n", smb_errstr(buf[5], EXTRACT_LE_16BITS(&buf[7]))));
    848       1.1  christos     }
    849       1.1  christos 
    850       1.1  christos     smboffset = 32;
    851       1.1  christos 
    852       1.1  christos     for (;;) {
    853       1.1  christos 	const char *f1, *f2;
    854       1.1  christos 	int wct;
    855       1.1  christos 	u_int bcc;
    856       1.1  christos 	int newsmboffset;
    857       1.1  christos 
    858       1.1  christos 	words = buf + smboffset;
    859       1.4  christos 	ND_TCHECK(words[0]);
    860       1.1  christos 	wct = words[0];
    861       1.1  christos 	data = words + 1 + wct * 2;
    862       1.4  christos 	maxwords = min(data, maxbuf);
    863       1.1  christos 
    864       1.1  christos 	if (request) {
    865       1.1  christos 	    f1 = fn->descript.req_f1;
    866       1.1  christos 	    f2 = fn->descript.req_f2;
    867       1.1  christos 	} else {
    868       1.1  christos 	    f1 = fn->descript.rep_f1;
    869       1.1  christos 	    f2 = fn->descript.rep_f2;
    870       1.1  christos 	}
    871       1.1  christos 
    872       1.1  christos 	if (fn->descript.fn)
    873       1.4  christos 	    (*fn->descript.fn)(ndo, words, data, buf, maxbuf);
    874       1.1  christos 	else {
    875       1.1  christos 	    if (wct) {
    876       1.1  christos 		if (f1)
    877       1.4  christos 		    smb_fdata(ndo, words + 1, f1, words + 1 + wct * 2, unicodestr);
    878       1.1  christos 		else {
    879       1.1  christos 		    int i;
    880       1.1  christos 		    int v;
    881       1.1  christos 
    882       1.1  christos 		    for (i = 0; &words[1 + 2 * i] < maxwords; i++) {
    883       1.4  christos 			ND_TCHECK2(words[1 + 2 * i], 2);
    884       1.1  christos 			v = EXTRACT_LE_16BITS(words + 1 + 2 * i);
    885       1.4  christos 			ND_PRINT((ndo, "smb_vwv[%d]=%d (0x%X)\n", i, v, v));
    886       1.1  christos 		    }
    887       1.1  christos 		}
    888       1.1  christos 	    }
    889       1.1  christos 
    890       1.4  christos 	    ND_TCHECK2(*data, 2);
    891       1.1  christos 	    bcc = EXTRACT_LE_16BITS(data);
    892       1.4  christos 	    ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
    893       1.1  christos 	    if (f2) {
    894       1.1  christos 		if (bcc > 0)
    895       1.4  christos 		    smb_fdata(ndo, data + 2, f2, data + 2 + bcc, unicodestr);
    896       1.1  christos 	    } else {
    897       1.1  christos 		if (bcc > 0) {
    898       1.4  christos 		    ND_PRINT((ndo, "smb_buf[]=\n"));
    899       1.6  christos 		    smb_print_data(ndo, data + 2, min(bcc, PTR_DIFF(maxbuf, data + 2)));
    900       1.1  christos 		}
    901       1.1  christos 	    }
    902       1.1  christos 	}
    903       1.1  christos 
    904       1.1  christos 	if ((fn->flags & FLG_CHAIN) == 0)
    905       1.1  christos 	    break;
    906       1.1  christos 	if (wct == 0)
    907       1.1  christos 	    break;
    908       1.4  christos 	ND_TCHECK(words[1]);
    909       1.1  christos 	command = words[1];
    910       1.1  christos 	if (command == 0xFF)
    911       1.1  christos 	    break;
    912       1.4  christos 	ND_TCHECK2(words[3], 2);
    913       1.4  christos 	newsmboffset = EXTRACT_LE_16BITS(words + 3);
    914       1.1  christos 
    915       1.1  christos 	fn = smbfind(command, smb_fns);
    916       1.1  christos 
    917       1.4  christos 	ND_PRINT((ndo, "\nSMB PACKET: %s (%s) (CHAINED)\n",
    918       1.4  christos 	    fn->name, request ? "REQUEST" : "REPLY"));
    919       1.1  christos 	if (newsmboffset <= smboffset) {
    920       1.4  christos 	    ND_PRINT((ndo, "Bad andX offset: %u <= %u\n", newsmboffset, smboffset));
    921       1.1  christos 	    break;
    922       1.1  christos 	}
    923       1.1  christos 	smboffset = newsmboffset;
    924       1.1  christos     }
    925       1.1  christos 
    926       1.4  christos     ND_PRINT((ndo, "\n"));
    927       1.1  christos     return;
    928       1.1  christos trunc:
    929       1.4  christos     ND_PRINT((ndo, "%s", tstr));
    930       1.1  christos }
    931       1.1  christos 
    932       1.1  christos 
    933       1.1  christos /*
    934       1.1  christos  * print a NBT packet received across tcp on port 139
    935       1.1  christos  */
    936       1.1  christos void
    937       1.4  christos nbt_tcp_print(netdissect_options *ndo,
    938       1.4  christos               const u_char *data, int length)
    939       1.1  christos {
    940       1.1  christos     int caplen;
    941       1.1  christos     int type;
    942       1.1  christos     u_int nbt_len;
    943       1.1  christos     const u_char *maxbuf;
    944       1.1  christos 
    945       1.1  christos     if (length < 4)
    946       1.1  christos 	goto trunc;
    947       1.4  christos     if (ndo->ndo_snapend < data)
    948       1.1  christos 	goto trunc;
    949       1.4  christos     caplen = ndo->ndo_snapend - data;
    950       1.1  christos     if (caplen < 4)
    951       1.1  christos 	goto trunc;
    952       1.1  christos     maxbuf = data + caplen;
    953  1.7.12.1    martin     ND_TCHECK_8BITS(data);
    954       1.1  christos     type = data[0];
    955  1.7.12.1    martin     ND_TCHECK_16BITS(data + 2);
    956       1.1  christos     nbt_len = EXTRACT_16BITS(data + 2);
    957       1.1  christos     length -= 4;
    958       1.1  christos     caplen -= 4;
    959       1.1  christos 
    960       1.1  christos     startbuf = data;
    961       1.1  christos 
    962       1.4  christos     if (ndo->ndo_vflag < 2) {
    963       1.4  christos 	ND_PRINT((ndo, " NBT Session Packet: "));
    964       1.1  christos 	switch (type) {
    965       1.1  christos 	case 0x00:
    966       1.4  christos 	    ND_PRINT((ndo, "Session Message"));
    967       1.1  christos 	    break;
    968       1.1  christos 
    969       1.1  christos 	case 0x81:
    970       1.4  christos 	    ND_PRINT((ndo, "Session Request"));
    971       1.1  christos 	    break;
    972       1.1  christos 
    973       1.1  christos 	case 0x82:
    974       1.4  christos 	    ND_PRINT((ndo, "Session Granted"));
    975       1.1  christos 	    break;
    976       1.1  christos 
    977       1.1  christos 	case 0x83:
    978       1.1  christos 	  {
    979       1.1  christos 	    int ecode;
    980       1.1  christos 
    981       1.1  christos 	    if (nbt_len < 4)
    982       1.1  christos 		goto trunc;
    983       1.1  christos 	    if (length < 4)
    984       1.1  christos 		goto trunc;
    985       1.1  christos 	    if (caplen < 4)
    986       1.1  christos 		goto trunc;
    987       1.1  christos 	    ecode = data[4];
    988       1.1  christos 
    989       1.4  christos 	    ND_PRINT((ndo, "Session Reject, "));
    990       1.1  christos 	    switch (ecode) {
    991       1.1  christos 	    case 0x80:
    992       1.4  christos 		ND_PRINT((ndo, "Not listening on called name"));
    993       1.1  christos 		break;
    994       1.1  christos 	    case 0x81:
    995       1.4  christos 		ND_PRINT((ndo, "Not listening for calling name"));
    996       1.1  christos 		break;
    997       1.1  christos 	    case 0x82:
    998       1.4  christos 		ND_PRINT((ndo, "Called name not present"));
    999       1.1  christos 		break;
   1000       1.1  christos 	    case 0x83:
   1001       1.4  christos 		ND_PRINT((ndo, "Called name present, but insufficient resources"));
   1002       1.1  christos 		break;
   1003       1.1  christos 	    default:
   1004       1.4  christos 		ND_PRINT((ndo, "Unspecified error 0x%X", ecode));
   1005       1.1  christos 		break;
   1006       1.1  christos 	    }
   1007       1.1  christos 	  }
   1008       1.1  christos 	    break;
   1009       1.1  christos 
   1010       1.1  christos 	case 0x85:
   1011       1.4  christos 	    ND_PRINT((ndo, "Session Keepalive"));
   1012       1.1  christos 	    break;
   1013       1.1  christos 
   1014       1.1  christos 	default:
   1015       1.4  christos 	    data = smb_fdata(ndo, data, "Unknown packet type [rB]", maxbuf, 0);
   1016       1.1  christos 	    break;
   1017       1.1  christos 	}
   1018       1.1  christos     } else {
   1019       1.4  christos 	ND_PRINT((ndo, "\n>>> NBT Session Packet\n"));
   1020       1.1  christos 	switch (type) {
   1021       1.1  christos 	case 0x00:
   1022       1.4  christos 	    data = smb_fdata(ndo, data, "[P1]NBT Session Message\nFlags=[B]\nLength=[rd]\n",
   1023       1.1  christos 		data + 4, 0);
   1024       1.1  christos 	    if (data == NULL)
   1025       1.1  christos 		break;
   1026       1.1  christos 	    if (nbt_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) {
   1027       1.1  christos 		if ((int)nbt_len > caplen) {
   1028       1.1  christos 		    if ((int)nbt_len > length)
   1029       1.4  christos 			ND_PRINT((ndo, "WARNING: Packet is continued in later TCP segments\n"));
   1030       1.1  christos 		    else
   1031       1.4  christos 			ND_PRINT((ndo, "WARNING: Short packet. Try increasing the snap length by %d\n",
   1032       1.4  christos 			    nbt_len - caplen));
   1033       1.1  christos 		}
   1034       1.4  christos 		print_smb(ndo, data, maxbuf > data + nbt_len ? data + nbt_len : maxbuf);
   1035       1.1  christos 	    } else
   1036       1.4  christos 		ND_PRINT((ndo, "Session packet:(raw data or continuation?)\n"));
   1037       1.1  christos 	    break;
   1038       1.1  christos 
   1039       1.1  christos 	case 0x81:
   1040       1.4  christos 	    data = smb_fdata(ndo, data,
   1041       1.1  christos 		"[P1]NBT Session Request\nFlags=[B]\nLength=[rd]\nDestination=[n1]\nSource=[n1]\n",
   1042       1.1  christos 		maxbuf, 0);
   1043       1.1  christos 	    break;
   1044       1.1  christos 
   1045       1.1  christos 	case 0x82:
   1046       1.4  christos 	    data = smb_fdata(ndo, data, "[P1]NBT Session Granted\nFlags=[B]\nLength=[rd]\n", maxbuf, 0);
   1047       1.1  christos 	    break;
   1048       1.1  christos 
   1049       1.1  christos 	case 0x83:
   1050       1.1  christos 	  {
   1051       1.1  christos 	    const u_char *origdata;
   1052       1.1  christos 	    int ecode;
   1053       1.1  christos 
   1054       1.1  christos 	    origdata = data;
   1055       1.4  christos 	    data = smb_fdata(ndo, data, "[P1]NBT SessionReject\nFlags=[B]\nLength=[rd]\nReason=[B]\n",
   1056       1.1  christos 		maxbuf, 0);
   1057       1.1  christos 	    if (data == NULL)
   1058       1.1  christos 		break;
   1059       1.1  christos 	    if (nbt_len >= 1 && caplen >= 1) {
   1060       1.1  christos 		ecode = origdata[4];
   1061       1.1  christos 		switch (ecode) {
   1062       1.1  christos 		case 0x80:
   1063       1.4  christos 		    ND_PRINT((ndo, "Not listening on called name\n"));
   1064       1.1  christos 		    break;
   1065       1.1  christos 		case 0x81:
   1066       1.4  christos 		    ND_PRINT((ndo, "Not listening for calling name\n"));
   1067       1.1  christos 		    break;
   1068       1.1  christos 		case 0x82:
   1069       1.4  christos 		    ND_PRINT((ndo, "Called name not present\n"));
   1070       1.1  christos 		    break;
   1071       1.1  christos 		case 0x83:
   1072       1.4  christos 		    ND_PRINT((ndo, "Called name present, but insufficient resources\n"));
   1073       1.1  christos 		    break;
   1074       1.1  christos 		default:
   1075       1.4  christos 		    ND_PRINT((ndo, "Unspecified error 0x%X\n", ecode));
   1076       1.1  christos 		    break;
   1077       1.1  christos 		}
   1078       1.1  christos 	    }
   1079       1.1  christos 	  }
   1080       1.1  christos 	    break;
   1081       1.1  christos 
   1082       1.1  christos 	case 0x85:
   1083       1.4  christos 	    data = smb_fdata(ndo, data, "[P1]NBT Session Keepalive\nFlags=[B]\nLength=[rd]\n", maxbuf, 0);
   1084       1.1  christos 	    break;
   1085       1.1  christos 
   1086       1.1  christos 	default:
   1087       1.4  christos 	    data = smb_fdata(ndo, data, "NBT - Unknown packet type\nType=[B]\n", maxbuf, 0);
   1088       1.1  christos 	    break;
   1089       1.1  christos 	}
   1090       1.4  christos 	ND_PRINT((ndo, "\n"));
   1091       1.1  christos     }
   1092       1.1  christos     return;
   1093       1.1  christos trunc:
   1094       1.4  christos     ND_PRINT((ndo, "%s", tstr));
   1095       1.1  christos }
   1096       1.1  christos 
   1097       1.4  christos static const struct tok opcode_str[] = {
   1098       1.4  christos 	{ 0,  "QUERY"                   },
   1099       1.4  christos 	{ 5,  "REGISTRATION"            },
   1100       1.4  christos 	{ 6,  "RELEASE"                 },
   1101       1.4  christos 	{ 7,  "WACK"                    },
   1102       1.4  christos 	{ 8,  "REFRESH(8)"              },
   1103       1.4  christos 	{ 9,  "REFRESH"                 },
   1104       1.4  christos 	{ 15, "MULTIHOMED REGISTRATION" },
   1105       1.4  christos 	{ 0, NULL }
   1106       1.4  christos };
   1107       1.1  christos 
   1108       1.1  christos /*
   1109       1.1  christos  * print a NBT packet received across udp on port 137
   1110       1.1  christos  */
   1111       1.1  christos void
   1112       1.4  christos nbt_udp137_print(netdissect_options *ndo,
   1113       1.4  christos                  const u_char *data, int length)
   1114       1.1  christos {
   1115       1.1  christos     const u_char *maxbuf = data + length;
   1116       1.1  christos     int name_trn_id, response, opcode, nm_flags, rcode;
   1117       1.1  christos     int qdcount, ancount, nscount, arcount;
   1118       1.1  christos     const u_char *p;
   1119       1.1  christos     int total, i;
   1120       1.1  christos 
   1121       1.4  christos     ND_TCHECK2(data[10], 2);
   1122       1.1  christos     name_trn_id = EXTRACT_16BITS(data);
   1123       1.1  christos     response = (data[2] >> 7);
   1124       1.1  christos     opcode = (data[2] >> 3) & 0xF;
   1125       1.1  christos     nm_flags = ((data[2] & 0x7) << 4) + (data[3] >> 4);
   1126       1.1  christos     rcode = data[3] & 0xF;
   1127       1.1  christos     qdcount = EXTRACT_16BITS(data + 4);
   1128       1.1  christos     ancount = EXTRACT_16BITS(data + 6);
   1129       1.1  christos     nscount = EXTRACT_16BITS(data + 8);
   1130       1.1  christos     arcount = EXTRACT_16BITS(data + 10);
   1131       1.1  christos     startbuf = data;
   1132       1.1  christos 
   1133       1.1  christos     if (maxbuf <= data)
   1134       1.1  christos 	return;
   1135       1.1  christos 
   1136       1.4  christos     if (ndo->ndo_vflag > 1)
   1137       1.4  christos 	ND_PRINT((ndo, "\n>>> "));
   1138       1.1  christos 
   1139       1.4  christos     ND_PRINT((ndo, "NBT UDP PACKET(137): %s", tok2str(opcode_str, "OPUNKNOWN", opcode)));
   1140       1.1  christos     if (response) {
   1141       1.4  christos         ND_PRINT((ndo, "; %s", rcode ? "NEGATIVE" : "POSITIVE"));
   1142       1.1  christos     }
   1143       1.4  christos     ND_PRINT((ndo, "; %s; %s", response ? "RESPONSE" : "REQUEST",
   1144       1.4  christos               (nm_flags & 1) ? "BROADCAST" : "UNICAST"));
   1145       1.1  christos 
   1146       1.4  christos     if (ndo->ndo_vflag < 2)
   1147       1.1  christos 	return;
   1148       1.1  christos 
   1149       1.4  christos     ND_PRINT((ndo, "\nTrnID=0x%X\nOpCode=%d\nNmFlags=0x%X\nRcode=%d\nQueryCount=%d\nAnswerCount=%d\nAuthorityCount=%d\nAddressRecCount=%d\n",
   1150       1.1  christos 	name_trn_id, opcode, nm_flags, rcode, qdcount, ancount, nscount,
   1151       1.4  christos 	arcount));
   1152       1.1  christos 
   1153       1.1  christos     p = data + 12;
   1154       1.1  christos 
   1155       1.1  christos     total = ancount + nscount + arcount;
   1156       1.1  christos 
   1157       1.1  christos     if (qdcount > 100 || total > 100) {
   1158       1.4  christos 	ND_PRINT((ndo, "Corrupt packet??\n"));
   1159       1.1  christos 	return;
   1160       1.1  christos     }
   1161       1.1  christos 
   1162       1.1  christos     if (qdcount) {
   1163       1.4  christos 	ND_PRINT((ndo, "QuestionRecords:\n"));
   1164       1.1  christos 	for (i = 0; i < qdcount; i++) {
   1165       1.4  christos 	    p = smb_fdata(ndo, p,
   1166       1.1  christos 		"|Name=[n1]\nQuestionType=[rw]\nQuestionClass=[rw]\n#",
   1167       1.1  christos 		maxbuf, 0);
   1168       1.1  christos 	    if (p == NULL)
   1169       1.1  christos 		goto out;
   1170       1.1  christos 	}
   1171       1.1  christos     }
   1172       1.1  christos 
   1173       1.1  christos     if (total) {
   1174       1.4  christos 	ND_PRINT((ndo, "\nResourceRecords:\n"));
   1175       1.1  christos 	for (i = 0; i < total; i++) {
   1176       1.1  christos 	    int rdlen;
   1177       1.1  christos 	    int restype;
   1178       1.1  christos 
   1179       1.4  christos 	    p = smb_fdata(ndo, p, "Name=[n1]\n#", maxbuf, 0);
   1180       1.1  christos 	    if (p == NULL)
   1181       1.1  christos 		goto out;
   1182       1.7       spz 	    ND_TCHECK_16BITS(p);
   1183       1.1  christos 	    restype = EXTRACT_16BITS(p);
   1184       1.4  christos 	    p = smb_fdata(ndo, p, "ResType=[rw]\nResClass=[rw]\nTTL=[rD]\n", p + 8, 0);
   1185       1.1  christos 	    if (p == NULL)
   1186       1.1  christos 		goto out;
   1187       1.7       spz 	    ND_TCHECK_16BITS(p);
   1188       1.1  christos 	    rdlen = EXTRACT_16BITS(p);
   1189       1.4  christos 	    ND_PRINT((ndo, "ResourceLength=%d\nResourceData=\n", rdlen));
   1190       1.1  christos 	    p += 2;
   1191       1.1  christos 	    if (rdlen == 6) {
   1192       1.4  christos 		p = smb_fdata(ndo, p, "AddrType=[rw]\nAddress=[b.b.b.b]\n", p + rdlen, 0);
   1193       1.1  christos 		if (p == NULL)
   1194       1.1  christos 		    goto out;
   1195       1.1  christos 	    } else {
   1196       1.1  christos 		if (restype == 0x21) {
   1197       1.1  christos 		    int numnames;
   1198       1.1  christos 
   1199       1.4  christos 		    ND_TCHECK(*p);
   1200       1.1  christos 		    numnames = p[0];
   1201       1.4  christos 		    p = smb_fdata(ndo, p, "NumNames=[B]\n", p + 1, 0);
   1202       1.1  christos 		    if (p == NULL)
   1203       1.1  christos 			goto out;
   1204       1.1  christos 		    while (numnames--) {
   1205       1.4  christos 			p = smb_fdata(ndo, p, "Name=[n2]\t#", maxbuf, 0);
   1206       1.1  christos 			if (p == NULL)
   1207       1.1  christos 			    goto out;
   1208       1.4  christos 			ND_TCHECK(*p);
   1209       1.1  christos 			if (p[0] & 0x80)
   1210       1.4  christos 			    ND_PRINT((ndo, "<GROUP> "));
   1211       1.1  christos 			switch (p[0] & 0x60) {
   1212       1.4  christos 			case 0x00: ND_PRINT((ndo, "B ")); break;
   1213       1.4  christos 			case 0x20: ND_PRINT((ndo, "P ")); break;
   1214       1.4  christos 			case 0x40: ND_PRINT((ndo, "M ")); break;
   1215       1.4  christos 			case 0x60: ND_PRINT((ndo, "_ ")); break;
   1216       1.1  christos 			}
   1217       1.1  christos 			if (p[0] & 0x10)
   1218       1.4  christos 			    ND_PRINT((ndo, "<DEREGISTERING> "));
   1219       1.1  christos 			if (p[0] & 0x08)
   1220       1.4  christos 			    ND_PRINT((ndo, "<CONFLICT> "));
   1221       1.1  christos 			if (p[0] & 0x04)
   1222       1.4  christos 			    ND_PRINT((ndo, "<ACTIVE> "));
   1223       1.1  christos 			if (p[0] & 0x02)
   1224       1.4  christos 			    ND_PRINT((ndo, "<PERMANENT> "));
   1225       1.4  christos 			ND_PRINT((ndo, "\n"));
   1226       1.1  christos 			p += 2;
   1227       1.1  christos 		    }
   1228       1.1  christos 		} else {
   1229       1.6  christos 		    smb_print_data(ndo, p, min(rdlen, length - (p - data)));
   1230       1.1  christos 		    p += rdlen;
   1231       1.1  christos 		}
   1232       1.1  christos 	    }
   1233       1.1  christos 	}
   1234       1.1  christos     }
   1235       1.1  christos 
   1236       1.1  christos     if (p < maxbuf)
   1237       1.4  christos 	smb_fdata(ndo, p, "AdditionalData:\n", maxbuf, 0);
   1238       1.1  christos 
   1239       1.1  christos out:
   1240       1.4  christos     ND_PRINT((ndo, "\n"));
   1241       1.1  christos     return;
   1242       1.1  christos trunc:
   1243       1.4  christos     ND_PRINT((ndo, "%s", tstr));
   1244       1.1  christos }
   1245       1.1  christos 
   1246       1.1  christos /*
   1247       1.1  christos  * Print an SMB-over-TCP packet received across tcp on port 445
   1248       1.1  christos  */
   1249       1.1  christos void
   1250       1.4  christos smb_tcp_print(netdissect_options *ndo,
   1251       1.4  christos               const u_char * data, int length)
   1252       1.1  christos {
   1253       1.1  christos     int caplen;
   1254       1.1  christos     u_int smb_len;
   1255       1.1  christos     const u_char *maxbuf;
   1256       1.1  christos 
   1257       1.1  christos     if (length < 4)
   1258       1.1  christos 	goto trunc;
   1259       1.4  christos     if (ndo->ndo_snapend < data)
   1260       1.1  christos 	goto trunc;
   1261       1.4  christos     caplen = ndo->ndo_snapend - data;
   1262       1.1  christos     if (caplen < 4)
   1263       1.1  christos 	goto trunc;
   1264       1.1  christos     maxbuf = data + caplen;
   1265       1.1  christos     smb_len = EXTRACT_24BITS(data + 1);
   1266       1.1  christos     length -= 4;
   1267       1.1  christos     caplen -= 4;
   1268       1.1  christos 
   1269       1.1  christos     startbuf = data;
   1270       1.1  christos     data += 4;
   1271       1.1  christos 
   1272       1.1  christos     if (smb_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) {
   1273       1.1  christos 	if ((int)smb_len > caplen) {
   1274       1.1  christos 	    if ((int)smb_len > length)
   1275       1.5  christos 		ND_PRINT((ndo, " WARNING: Packet is continued in later TCP segments\n"));
   1276       1.1  christos 	    else
   1277       1.5  christos 		ND_PRINT((ndo, " WARNING: Short packet. Try increasing the snap length by %d\n",
   1278       1.4  christos 		    smb_len - caplen));
   1279       1.5  christos 	} else
   1280       1.5  christos 	    ND_PRINT((ndo, " "));
   1281       1.4  christos 	print_smb(ndo, data, maxbuf > data + smb_len ? data + smb_len : maxbuf);
   1282       1.1  christos     } else
   1283       1.5  christos 	ND_PRINT((ndo, " SMB-over-TCP packet:(raw data or continuation?)\n"));
   1284       1.1  christos     return;
   1285       1.1  christos trunc:
   1286       1.4  christos     ND_PRINT((ndo, "%s", tstr));
   1287       1.1  christos }
   1288       1.1  christos 
   1289       1.1  christos /*
   1290       1.1  christos  * print a NBT packet received across udp on port 138
   1291       1.1  christos  */
   1292       1.1  christos void
   1293       1.4  christos nbt_udp138_print(netdissect_options *ndo,
   1294       1.4  christos                  const u_char *data, int length)
   1295       1.1  christos {
   1296       1.1  christos     const u_char *maxbuf = data + length;
   1297       1.1  christos 
   1298       1.4  christos     if (maxbuf > ndo->ndo_snapend)
   1299       1.4  christos 	maxbuf = ndo->ndo_snapend;
   1300       1.1  christos     if (maxbuf <= data)
   1301       1.1  christos 	return;
   1302       1.1  christos     startbuf = data;
   1303       1.1  christos 
   1304       1.4  christos     if (ndo->ndo_vflag < 2) {
   1305       1.4  christos 	ND_PRINT((ndo, "NBT UDP PACKET(138)"));
   1306       1.1  christos 	return;
   1307       1.1  christos     }
   1308       1.1  christos 
   1309       1.4  christos     data = smb_fdata(ndo, data,
   1310       1.1  christos 	"\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#",
   1311       1.1  christos 	maxbuf, 0);
   1312       1.1  christos 
   1313       1.1  christos     if (data != NULL) {
   1314       1.1  christos 	/* If there isn't enough data for "\377SMB", don't check for it. */
   1315       1.1  christos 	if (&data[3] >= maxbuf)
   1316       1.1  christos 	    goto out;
   1317       1.1  christos 
   1318       1.1  christos 	if (memcmp(data, "\377SMB",4) == 0)
   1319       1.4  christos 	    print_smb(ndo, data, maxbuf);
   1320       1.1  christos     }
   1321       1.1  christos out:
   1322       1.4  christos     ND_PRINT((ndo, "\n"));
   1323       1.1  christos }
   1324       1.1  christos 
   1325       1.1  christos 
   1326       1.1  christos /*
   1327       1.1  christos    print netbeui frames
   1328       1.1  christos */
   1329       1.7       spz static struct nbf_strings {
   1330       1.1  christos 	const char	*name;
   1331       1.1  christos 	const char	*nonverbose;
   1332       1.1  christos 	const char	*verbose;
   1333       1.1  christos } nbf_strings[0x20] = {
   1334       1.1  christos 	{ "Add Group Name Query", ", [P23]Name to add=[n2]#",
   1335       1.1  christos 	  "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" },
   1336       1.1  christos 	{ "Add Name Query", ", [P23]Name to add=[n2]#",
   1337       1.1  christos 	  "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" },
   1338       1.1  christos 	{ "Name In Conflict", NULL, NULL },
   1339       1.1  christos 	{ "Status Query", NULL, NULL },
   1340       1.1  christos 	{ NULL, NULL, NULL },	/* not used */
   1341       1.1  christos 	{ NULL, NULL, NULL },	/* not used */
   1342       1.1  christos 	{ NULL, NULL, NULL },	/* not used */
   1343       1.1  christos 	{ "Terminate Trace", NULL, NULL },
   1344       1.1  christos 	{ "Datagram", NULL,
   1345       1.1  christos 	  "[P7]Destination=[n2]\nSource=[n2]\n" },
   1346       1.1  christos 	{ "Broadcast Datagram", NULL,
   1347       1.1  christos 	  "[P7]Destination=[n2]\nSource=[n2]\n" },
   1348       1.1  christos 	{ "Name Query", ", [P7]Name=[n2]#",
   1349       1.1  christos 	  "[P1]SessionNumber=[B]\nNameType=[B][P2]\nResponseCorrelator=[w]\nName=[n2]\nName of sender=[n2]\n" },
   1350       1.1  christos 	{ NULL, NULL, NULL },	/* not used */
   1351       1.1  christos 	{ NULL, NULL, NULL },	/* not used */
   1352       1.1  christos 	{ "Add Name Response", ", [P1]GroupName=[w] [P4]Destination=[n2] Source=[n2]#",
   1353       1.1  christos 	  "AddNameInProcess=[B]\nGroupName=[w]\nTransmitCorrelator=[w][P2]\nDestination=[n2]\nSource=[n2]\n" },
   1354       1.1  christos 	{ "Name Recognized", NULL,
   1355       1.1  christos 	  "[P1]Data2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nDestination=[n2]\nSource=[n2]\n" },
   1356       1.1  christos 	{ "Status Response", NULL, NULL },
   1357       1.1  christos 	{ NULL, NULL, NULL },	/* not used */
   1358       1.1  christos 	{ NULL, NULL, NULL },	/* not used */
   1359       1.1  christos 	{ NULL, NULL, NULL },	/* not used */
   1360       1.1  christos 	{ "Terminate Trace", NULL, NULL },
   1361       1.1  christos 	{ "Data Ack", NULL,
   1362       1.1  christos 	  "[P3]TransmitCorrelator=[w][P2]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1363       1.1  christos 	{ "Data First/Middle", NULL,
   1364       1.1  christos 	  "Flags=[{RECEIVE_CONTINUE|NO_ACK||PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1365       1.1  christos 	{ "Data Only/Last", NULL,
   1366       1.1  christos 	  "Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1367       1.1  christos 	{ "Session Confirm", NULL,
   1368       1.1  christos 	  "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1369       1.1  christos 	{ "Session End", NULL,
   1370       1.1  christos 	  "[P1]Data2=[w][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1371       1.1  christos 	{ "Session Initialize", NULL,
   1372       1.1  christos 	  "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1373       1.1  christos 	{ "No Receive", NULL,
   1374       1.1  christos 	  "Flags=[{|SEND_NO_ACK}]\nDataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1375       1.1  christos 	{ "Receive Outstanding", NULL,
   1376       1.1  christos 	  "[P1]DataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1377       1.1  christos 	{ "Receive Continue", NULL,
   1378       1.1  christos 	  "[P2]TransmitCorrelator=[w]\n[P2]RemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1379       1.1  christos 	{ NULL, NULL, NULL },	/* not used */
   1380       1.1  christos 	{ NULL, NULL, NULL },	/* not used */
   1381       1.1  christos 	{ "Session Alive", NULL, NULL }
   1382       1.1  christos };
   1383       1.1  christos 
   1384       1.1  christos void
   1385       1.4  christos netbeui_print(netdissect_options *ndo,
   1386       1.4  christos               u_short control, const u_char *data, int length)
   1387       1.1  christos {
   1388       1.1  christos     const u_char *maxbuf = data + length;
   1389       1.1  christos     int len;
   1390       1.1  christos     int command;
   1391       1.1  christos     const u_char *data2;
   1392       1.1  christos     int is_truncated = 0;
   1393       1.1  christos 
   1394       1.4  christos     if (maxbuf > ndo->ndo_snapend)
   1395       1.4  christos 	maxbuf = ndo->ndo_snapend;
   1396       1.4  christos     ND_TCHECK(data[4]);
   1397       1.1  christos     len = EXTRACT_LE_16BITS(data);
   1398       1.1  christos     command = data[4];
   1399       1.1  christos     data2 = data + len;
   1400       1.1  christos     if (data2 >= maxbuf) {
   1401       1.1  christos 	data2 = maxbuf;
   1402       1.1  christos 	is_truncated = 1;
   1403       1.1  christos     }
   1404       1.1  christos 
   1405       1.1  christos     startbuf = data;
   1406       1.1  christos 
   1407       1.4  christos     if (ndo->ndo_vflag < 2) {
   1408       1.4  christos 	ND_PRINT((ndo, "NBF Packet: "));
   1409       1.4  christos 	data = smb_fdata(ndo, data, "[P5]#", maxbuf, 0);
   1410       1.1  christos     } else {
   1411       1.4  christos 	ND_PRINT((ndo, "\n>>> NBF Packet\nType=0x%X ", control));
   1412       1.4  christos 	data = smb_fdata(ndo, data, "Length=[d] Signature=[w] Command=[B]\n#", maxbuf, 0);
   1413       1.1  christos     }
   1414       1.1  christos     if (data == NULL)
   1415       1.1  christos 	goto out;
   1416       1.1  christos 
   1417       1.1  christos     if (command > 0x1f || nbf_strings[command].name == NULL) {
   1418       1.4  christos 	if (ndo->ndo_vflag < 2)
   1419       1.4  christos 	    data = smb_fdata(ndo, data, "Unknown NBF Command#", data2, 0);
   1420       1.1  christos 	else
   1421       1.4  christos 	    data = smb_fdata(ndo, data, "Unknown NBF Command\n", data2, 0);
   1422       1.1  christos     } else {
   1423       1.4  christos 	if (ndo->ndo_vflag < 2) {
   1424       1.4  christos 	    ND_PRINT((ndo, "%s", nbf_strings[command].name));
   1425       1.1  christos 	    if (nbf_strings[command].nonverbose != NULL)
   1426       1.4  christos 		data = smb_fdata(ndo, data, nbf_strings[command].nonverbose, data2, 0);
   1427       1.1  christos 	} else {
   1428       1.4  christos 	    ND_PRINT((ndo, "%s:\n", nbf_strings[command].name));
   1429       1.1  christos 	    if (nbf_strings[command].verbose != NULL)
   1430       1.4  christos 		data = smb_fdata(ndo, data, nbf_strings[command].verbose, data2, 0);
   1431       1.1  christos 	    else
   1432       1.4  christos 		ND_PRINT((ndo, "\n"));
   1433       1.1  christos 	}
   1434       1.1  christos     }
   1435       1.1  christos 
   1436       1.4  christos     if (ndo->ndo_vflag < 2)
   1437       1.1  christos 	return;
   1438       1.1  christos 
   1439       1.1  christos     if (data == NULL)
   1440       1.1  christos 	goto out;
   1441       1.1  christos 
   1442       1.1  christos     if (is_truncated) {
   1443       1.1  christos 	/* data2 was past the end of the buffer */
   1444       1.1  christos 	goto out;
   1445       1.1  christos     }
   1446       1.1  christos 
   1447       1.1  christos     /* If this isn't a command that would contain an SMB message, quit. */
   1448       1.1  christos     if (command != 0x08 && command != 0x09 && command != 0x15 &&
   1449       1.1  christos         command != 0x16)
   1450       1.1  christos 	goto out;
   1451       1.1  christos 
   1452       1.1  christos     /* If there isn't enough data for "\377SMB", don't look for it. */
   1453       1.1  christos     if (&data2[3] >= maxbuf)
   1454       1.1  christos 	goto out;
   1455       1.1  christos 
   1456       1.1  christos     if (memcmp(data2, "\377SMB",4) == 0)
   1457       1.4  christos 	print_smb(ndo, data2, maxbuf);
   1458       1.1  christos     else {
   1459       1.1  christos 	int i;
   1460       1.1  christos 	for (i = 0; i < 128; i++) {
   1461       1.1  christos 	    if (&data2[i + 3] >= maxbuf)
   1462       1.1  christos 		break;
   1463       1.1  christos 	    if (memcmp(&data2[i], "\377SMB", 4) == 0) {
   1464       1.4  christos 		ND_PRINT((ndo, "found SMB packet at %d\n", i));
   1465       1.4  christos 		print_smb(ndo, &data2[i], maxbuf);
   1466       1.1  christos 		break;
   1467       1.1  christos 	    }
   1468       1.1  christos 	}
   1469       1.1  christos     }
   1470       1.1  christos 
   1471       1.1  christos out:
   1472       1.4  christos     ND_PRINT((ndo, "\n"));
   1473       1.1  christos     return;
   1474       1.1  christos trunc:
   1475       1.4  christos     ND_PRINT((ndo, "%s", tstr));
   1476       1.1  christos }
   1477       1.1  christos 
   1478       1.1  christos 
   1479       1.1  christos /*
   1480       1.1  christos  * print IPX-Netbios frames
   1481       1.1  christos  */
   1482       1.1  christos void
   1483       1.4  christos ipx_netbios_print(netdissect_options *ndo,
   1484       1.4  christos                   const u_char *data, u_int length)
   1485       1.1  christos {
   1486       1.1  christos     /*
   1487       1.1  christos      * this is a hack till I work out how to parse the rest of the
   1488       1.1  christos      * NetBIOS-over-IPX stuff
   1489       1.1  christos      */
   1490       1.1  christos     int i;
   1491       1.1  christos     const u_char *maxbuf;
   1492       1.1  christos 
   1493       1.1  christos     maxbuf = data + length;
   1494       1.1  christos     /* Don't go past the end of the captured data in the packet. */
   1495       1.4  christos     if (maxbuf > ndo->ndo_snapend)
   1496       1.4  christos 	maxbuf = ndo->ndo_snapend;
   1497       1.1  christos     startbuf = data;
   1498       1.1  christos     for (i = 0; i < 128; i++) {
   1499       1.1  christos 	if (&data[i + 4] > maxbuf)
   1500       1.1  christos 	    break;
   1501       1.1  christos 	if (memcmp(&data[i], "\377SMB", 4) == 0) {
   1502       1.4  christos 	    smb_fdata(ndo, data, "\n>>> IPX transport ", &data[i], 0);
   1503       1.4  christos 	    print_smb(ndo, &data[i], maxbuf);
   1504       1.4  christos 	    ND_PRINT((ndo, "\n"));
   1505       1.1  christos 	    break;
   1506       1.1  christos 	}
   1507       1.1  christos     }
   1508       1.1  christos     if (i == 128)
   1509       1.4  christos 	smb_fdata(ndo, data, "\n>>> Unknown IPX ", maxbuf, 0);
   1510       1.1  christos }
   1511