]>
The Tcpdump Group git mirrors - tcpdump/blob - print-smb.c
2 * Copyright (C) Andrew Tridgell 1995-1999
4 * This software may be distributed either under the terms of the
5 * BSD-style license that accompanies tcpdump or the GNU GPL version 2
13 #include <netdissect-stdinc.h>
17 #include "netdissect.h"
21 static const char tstr
[] = "[|SMB]" ;
23 static int request
= 0 ;
24 static int unicodestr
= 0 ;
26 const u_char
* startbuf
= NULL
;
33 void (* fn
)( netdissect_options
*, const u_char
*, const u_char
*, const u_char
*, const u_char
*);
36 struct smbdescriptint
{
41 void (* fn
)( netdissect_options
*, const u_char
*, const u_char
*, int , int );
49 struct smbdescript descript
;
57 struct smbdescriptint descript
;
60 #define DEFDESCRIPT { NULL, NULL, NULL, NULL, NULL }
62 #define FLG_CHAIN (1 << 0)
64 static const struct smbfns
*
65 smbfind ( int id
, const struct smbfns
* list
)
69 for ( sindex
= 0 ; list
[ sindex
]. name
; sindex
++)
70 if ( list
[ sindex
]. id
== id
)
71 return (& list
[ sindex
]);
76 static const struct smbfnsint
*
77 smbfindint ( int id
, const struct smbfnsint
* list
)
81 for ( sindex
= 0 ; list
[ sindex
]. name
; sindex
++)
82 if ( list
[ sindex
]. id
== id
)
83 return (& list
[ sindex
]);
89 trans2_findfirst ( netdissect_options
* ndo
,
90 const u_char
* param
, const u_char
* data
, int pcnt
, int dcnt
)
95 fmt
= "Attribute=[A] \n SearchCount=[d] \n Flags=[w] \n Level=[dP4] \n File=[S] \n " ;
97 fmt
= "Handle=[w] \n Count=[d] \n EOS=[w] \n Eoffset=[d] \n LastNameOfs=[w] \n " ;
99 smb_fdata ( ndo
, param
, fmt
, param
+ pcnt
, unicodestr
);
101 ND_PRINT (( ndo
, "data: \n " ));
102 smb_print_data ( ndo
, data
, dcnt
);
107 trans2_qfsinfo ( netdissect_options
* ndo
,
108 const u_char
* param
, const u_char
* data
, int pcnt
, int dcnt
)
110 static int level
= 0 ;
114 ND_TCHECK2 (* param
, 2 );
115 level
= EXTRACT_LE_16BITS ( param
);
116 fmt
= "InfoLevel=[d] \n " ;
117 smb_fdata ( ndo
, param
, fmt
, param
+ pcnt
, unicodestr
);
121 fmt
= "idFileSystem=[W] \n SectorUnit=[D] \n Unit=[D] \n Avail=[D] \n SectorSize=[d] \n " ;
124 fmt
= "CreationTime=[T2]VolNameLength=[lb] \n VolumeLabel=[c] \n " ;
127 fmt
= "Capabilities=[W] \n MaxFileLen=[D] \n VolNameLen=[lD] \n Volume=[C] \n " ;
130 fmt
= "UnknownLevel \n " ;
133 smb_fdata ( ndo
, data
, fmt
, data
+ dcnt
, unicodestr
);
136 ND_PRINT (( ndo
, "data: \n " ));
137 smb_print_data ( ndo
, data
, dcnt
);
141 ND_PRINT (( ndo
, "%s" , tstr
));
144 static const struct smbfnsint trans2_fns
[] = {
145 { 0 , "TRANSACT2_OPEN" , 0 ,
146 { "Flags2=[w] \n Mode=[w] \n SearchAttrib=[A] \n Attrib=[A] \n Time=[T2] \n OFun=[w] \n Size=[D] \n Res=([w, w, w, w, w]) \n Path=[S]" ,
148 "Handle=[d] \n Attrib=[A] \n Time=[T2] \n Size=[D] \n Access=[w] \n Type=[w] \n State=[w] \n Action=[w] \n Inode=[W] \n OffErr=[d] \n |EALength=[d] \n " ,
150 { 1 , "TRANSACT2_FINDFIRST" , 0 ,
151 { NULL
, NULL
, NULL
, NULL
, trans2_findfirst
}},
152 { 2 , "TRANSACT2_FINDNEXT" , 0 , DEFDESCRIPT
},
153 { 3 , "TRANSACT2_QFSINFO" , 0 ,
154 { NULL
, NULL
, NULL
, NULL
, trans2_qfsinfo
}},
155 { 4 , "TRANSACT2_SETFSINFO" , 0 , DEFDESCRIPT
},
156 { 5 , "TRANSACT2_QPATHINFO" , 0 , DEFDESCRIPT
},
157 { 6 , "TRANSACT2_SETPATHINFO" , 0 , DEFDESCRIPT
},
158 { 7 , "TRANSACT2_QFILEINFO" , 0 , DEFDESCRIPT
},
159 { 8 , "TRANSACT2_SETFILEINFO" , 0 , DEFDESCRIPT
},
160 { 9 , "TRANSACT2_FSCTL" , 0 , DEFDESCRIPT
},
161 { 10 , "TRANSACT2_IOCTL" , 0 , DEFDESCRIPT
},
162 { 11 , "TRANSACT2_FINDNOTIFYFIRST" , 0 , DEFDESCRIPT
},
163 { 12 , "TRANSACT2_FINDNOTIFYNEXT" , 0 , DEFDESCRIPT
},
164 { 13 , "TRANSACT2_MKDIR" , 0 , DEFDESCRIPT
},
165 { - 1 , NULL
, 0 , DEFDESCRIPT
}
170 print_trans2 ( netdissect_options
* ndo
,
171 const u_char
* words
, const u_char
* dat
, const u_char
* buf
, const u_char
* maxbuf
)
174 static const struct smbfnsint
* fn
= & trans2_fns
[ 0 ];
175 const u_char
* data
, * param
;
176 const u_char
* w
= words
+ 1 ;
177 const char * f1
= NULL
, * f2
= NULL
;
182 ND_TCHECK2 ( w
[ 14 * 2 ], 2 );
183 pcnt
= EXTRACT_LE_16BITS ( w
+ 9 * 2 );
184 param
= buf
+ EXTRACT_LE_16BITS ( w
+ 10 * 2 );
185 dcnt
= EXTRACT_LE_16BITS ( w
+ 11 * 2 );
186 data
= buf
+ EXTRACT_LE_16BITS ( w
+ 12 * 2 );
187 fn
= smbfindint ( EXTRACT_LE_16BITS ( w
+ 14 * 2 ), trans2_fns
);
190 ND_PRINT (( ndo
, "%s \n " , fn
-> name
));
191 ND_PRINT (( ndo
, "Trans2Interim \n " ));
194 ND_TCHECK2 ( w
[ 7 * 2 ], 2 );
195 pcnt
= EXTRACT_LE_16BITS ( w
+ 3 * 2 );
196 param
= buf
+ EXTRACT_LE_16BITS ( w
+ 4 * 2 );
197 dcnt
= EXTRACT_LE_16BITS ( w
+ 6 * 2 );
198 data
= buf
+ EXTRACT_LE_16BITS ( w
+ 7 * 2 );
201 ND_PRINT (( ndo
, "%s param_length=%d data_length=%d \n " , fn
-> name
, pcnt
, dcnt
));
205 smb_fdata ( ndo
, words
+ 1 ,
206 "Trans2Secondary \n TotParam=[d] \n TotData=[d] \n ParamCnt=[d] \n ParamOff=[d] \n ParamDisp=[d] \n DataCnt=[d] \n DataOff=[d] \n DataDisp=[d] \n Handle=[d] \n " ,
210 smb_fdata ( ndo
, words
+ 1 ,
211 "TotParam=[d] \n TotData=[d] \n MaxParam=[d] \n MaxData=[d] \n MaxSetup=[b][P1] \n Flags=[w] \n TimeOut=[D] \n Res1=[w] \n ParamCnt=[d] \n ParamOff=[d] \n DataCnt=[d] \n DataOff=[d] \n SetupCnt=[b][P1] \n " ,
212 words
+ 1 + 14 * 2 , unicodestr
);
214 f1
= fn
-> descript
. req_f1
;
215 f2
= fn
-> descript
. req_f2
;
217 smb_fdata ( ndo
, words
+ 1 ,
218 "TotParam=[d] \n TotData=[d] \n Res1=[w] \n ParamCnt=[d] \n ParamOff=[d] \n ParamDisp[d] \n DataCnt=[d] \n DataOff=[d] \n DataDisp=[d] \n SetupCnt=[b][P1] \n " ,
219 words
+ 1 + 10 * 2 , unicodestr
);
220 f1
= fn
-> descript
. rep_f1
;
221 f2
= fn
-> descript
. rep_f2
;
225 bcc
= EXTRACT_LE_16BITS ( dat
);
226 ND_PRINT (( ndo
, "smb_bcc=%u \n " , bcc
));
228 (* fn
-> descript
. fn
)( ndo
, param
, data
, pcnt
, dcnt
);
230 smb_fdata ( ndo
, param
, f1
? f1
: "Parameters= \n " , param
+ pcnt
, unicodestr
);
231 smb_fdata ( ndo
, data
, f2
? f2
: "Data= \n " , data
+ dcnt
, unicodestr
);
235 ND_PRINT (( ndo
, "%s" , tstr
));
239 print_browse ( netdissect_options
* ndo
,
240 const u_char
* param
, int paramlen
, const u_char
* data
, int datalen
)
242 const u_char
* maxbuf
= data
+ datalen
;
248 smb_fdata ( ndo
, param
, "BROWSE PACKET \n |Param " , param
+ paramlen
, unicodestr
);
252 data
= smb_fdata ( ndo
, data
,
253 "BROWSE PACKET: \n Type=[B] (LocalMasterAnnouncement) \n UpdateCount=[w] \n Res1=[B] \n AnnounceInterval=[d] \n Name=[n2] \n MajorVersion=[B] \n MinorVersion=[B] \n ServerType=[W] \n ElectionVersion=[w] \n BrowserConstant=[w] \n " ,
258 data
= smb_fdata ( ndo
, data
,
259 "BROWSE PACKET: \n Type=[B] (HostAnnouncement) \n UpdateCount=[w] \n Res1=[B] \n AnnounceInterval=[d] \n Name=[n2] \n MajorVersion=[B] \n MinorVersion=[B] \n ServerType=[W] \n ElectionVersion=[w] \n BrowserConstant=[w] \n " ,
264 data
= smb_fdata ( ndo
, data
,
265 "BROWSE PACKET: \n Type=[B] (AnnouncementRequest) \n Flags=[B] \n ReplySystemName=[S] \n " ,
270 data
= smb_fdata ( ndo
, data
,
271 "BROWSE PACKET: \n Type=[B] (WorkgroupAnnouncement) \n UpdateCount=[w] \n Res1=[B] \n AnnounceInterval=[d] \n Name=[n2] \n MajorVersion=[B] \n MinorVersion=[B] \n ServerType=[W] \n CommentPointer=[W] \n ServerName=[S] \n " ,
276 data
= smb_fdata ( ndo
, data
,
277 "BROWSE PACKET: \n Type=[B] (ElectionFrame) \n ElectionVersion=[B] \n OSSummary=[W] \n Uptime=[(W, W)] \n ServerName=[S] \n " ,
282 data
= smb_fdata ( ndo
, data
,
283 "BROWSE PACKET: \n Type=[B] (BecomeBackupBrowser) \n Name=[S] \n " ,
288 data
= smb_fdata ( ndo
, data
,
289 "BROWSE PACKET: \n Type=[B] (GetBackupList) \n ListCount?=[B] \n Token=[W] \n " ,
294 data
= smb_fdata ( ndo
, data
,
295 "BROWSE PACKET: \n Type=[B] (BackupListResponse) \n ServerCount?=[B] \n Token=[W] \n *Name=[S] \n " ,
300 data
= smb_fdata ( ndo
, data
,
301 "BROWSE PACKET: \n Type=[B] (MasterAnnouncement) \n MasterName=[S] \n " ,
306 data
= smb_fdata ( ndo
, data
,
307 "BROWSE PACKET: \n Type=[B] (ResetBrowser) \n Options=[B] \n " , maxbuf
, unicodestr
);
311 data
= smb_fdata ( ndo
, data
, "Unknown Browser Frame " , maxbuf
, unicodestr
);
316 ND_PRINT (( ndo
, "%s" , tstr
));
321 print_ipc ( netdissect_options
* ndo
,
322 const u_char
* param
, int paramlen
, const u_char
* data
, int datalen
)
325 smb_fdata ( ndo
, param
, "Command=[w] \n Str1=[S] \n Str2=[S] \n " , param
+ paramlen
,
328 smb_fdata ( ndo
, data
, "IPC " , data
+ datalen
, unicodestr
);
333 print_trans ( netdissect_options
* ndo
,
334 const u_char
* words
, const u_char
* data1
, const u_char
* buf
, const u_char
* maxbuf
)
337 const char * f1
, * f2
, * f3
, * f4
;
338 const u_char
* data
, * param
;
339 const u_char
* w
= words
+ 1 ;
340 int datalen
, paramlen
;
343 ND_TCHECK2 ( w
[ 12 * 2 ], 2 );
344 paramlen
= EXTRACT_LE_16BITS ( w
+ 9 * 2 );
345 param
= buf
+ EXTRACT_LE_16BITS ( w
+ 10 * 2 );
346 datalen
= EXTRACT_LE_16BITS ( w
+ 11 * 2 );
347 data
= buf
+ EXTRACT_LE_16BITS ( w
+ 12 * 2 );
348 f1
= "TotParamCnt=[d] \n TotDataCnt=[d] \n MaxParmCnt=[d] \n MaxDataCnt=[d] \n MaxSCnt=[d] \n TransFlags=[w] \n Res1=[w] \n Res2=[w] \n Res3=[w] \n ParamCnt=[d] \n ParamOff=[d] \n DataCnt=[d] \n DataOff=[d] \n SUCnt=[d] \n " ;
353 ND_TCHECK2 ( w
[ 7 * 2 ], 2 );
354 paramlen
= EXTRACT_LE_16BITS ( w
+ 3 * 2 );
355 param
= buf
+ EXTRACT_LE_16BITS ( w
+ 4 * 2 );
356 datalen
= EXTRACT_LE_16BITS ( w
+ 6 * 2 );
357 data
= buf
+ EXTRACT_LE_16BITS ( w
+ 7 * 2 );
358 f1
= "TotParamCnt=[d] \n TotDataCnt=[d] \n Res1=[d] \n ParamCnt=[d] \n ParamOff=[d] \n Res2=[d] \n DataCnt=[d] \n DataOff=[d] \n Res3=[d] \n Lsetup=[d] \n " ;
364 smb_fdata ( ndo
, words
+ 1 , f1
, min ( words
+ 1 + 2 * words
[ 0 ], maxbuf
),
367 ND_TCHECK2 (* data1
, 2 );
368 bcc
= EXTRACT_LE_16BITS ( data1
);
369 ND_PRINT (( ndo
, "smb_bcc=%u \n " , bcc
));
371 smb_fdata ( ndo
, data1
+ 2 , f2
, maxbuf
- ( paramlen
+ datalen
), unicodestr
);
373 if ( strcmp (( const char *)( data1
+ 2 ), " \\ MAILSLOT \\ BROWSE" ) == 0 ) {
374 print_browse ( ndo
, param
, paramlen
, data
, datalen
);
378 if ( strcmp (( const char *)( data1
+ 2 ), " \\ PIPE \\ LANMAN" ) == 0 ) {
379 print_ipc ( ndo
, param
, paramlen
, data
, datalen
);
384 smb_fdata ( ndo
, param
, f3
, min ( param
+ paramlen
, maxbuf
), unicodestr
);
386 smb_fdata ( ndo
, data
, f4
, min ( data
+ datalen
, maxbuf
), unicodestr
);
390 ND_PRINT (( ndo
, "%s" , tstr
));
395 print_negprot ( netdissect_options
* ndo
,
396 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
399 const char * f1
= NULL
, * f2
= NULL
;
404 f2
= "*|Dialect=[Y] \n " ;
407 f1
= "Core Protocol \n DialectIndex=[d]" ;
409 f1
= "NT1 Protocol \n DialectIndex=[d] \n SecMode=[B] \n MaxMux=[d] \n NumVcs=[d] \n MaxBuffer=[D] \n RawSize=[D] \n SessionKey=[W] \n Capabilities=[W] \n ServerTime=[T3]TimeZone=[d] \n CryptKey=" ;
411 f1
= "Coreplus/Lanman1/Lanman2 Protocol \n DialectIndex=[d] \n SecMode=[w] \n MaxXMit=[d] \n MaxMux=[d] \n MaxVcs=[d] \n BlkMode=[w] \n SessionKey=[W] \n ServerTime=[T1]TimeZone=[d] \n Res=[W] \n CryptKey=" ;
415 smb_fdata ( ndo
, words
+ 1 , f1
, min ( words
+ 1 + wct
* 2 , maxbuf
),
418 smb_print_data ( ndo
, words
+ 1 , min ( wct
* 2 , PTR_DIFF ( maxbuf
, words
+ 1 )));
420 ND_TCHECK2 (* data
, 2 );
421 bcc
= EXTRACT_LE_16BITS ( data
);
422 ND_PRINT (( ndo
, "smb_bcc=%u \n " , bcc
));
425 smb_fdata ( ndo
, data
+ 2 , f2
, min ( data
+ 2 + EXTRACT_LE_16BITS ( data
),
426 maxbuf
), unicodestr
);
428 smb_print_data ( ndo
, data
+ 2 , min ( EXTRACT_LE_16BITS ( data
), PTR_DIFF ( maxbuf
, data
+ 2 )));
432 ND_PRINT (( ndo
, "%s" , tstr
));
436 print_sesssetup ( netdissect_options
* ndo
,
437 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
440 const char * f1
= NULL
, * f2
= NULL
;
446 f1
= "Com2=[w] \n Off2=[d] \n BufSize=[d] \n MpxMax=[d] \n VcNum=[d] \n SessionKey=[W] \n PassLen=[d] \n CryptLen=[d] \n CryptOff=[d] \n Pass&Name= \n " ;
448 f1
= "Com2=[B] \n Res1=[B] \n Off2=[d] \n MaxBuffer=[d] \n MaxMpx=[d] \n VcNumber=[d] \n SessionKey=[W] \n CaseInsensitivePasswordLength=[d] \n CaseSensitivePasswordLength=[d] \n Res=[W] \n Capabilities=[W] \n Pass1&Pass2&Account&Domain&OS&LanMan= \n " ;
451 f1
= "Com2=[w] \n Off2=[d] \n Action=[w] \n " ;
452 } else if ( wct
== 13 ) {
453 f1
= "Com2=[B] \n Res=[B] \n Off2=[d] \n Action=[w] \n " ;
454 f2
= "NativeOS=[S] \n NativeLanMan=[S] \n PrimaryDomain=[S] \n " ;
459 smb_fdata ( ndo
, words
+ 1 , f1
, min ( words
+ 1 + wct
* 2 , maxbuf
),
462 smb_print_data ( ndo
, words
+ 1 , min ( wct
* 2 , PTR_DIFF ( maxbuf
, words
+ 1 )));
464 ND_TCHECK2 (* data
, 2 );
465 bcc
= EXTRACT_LE_16BITS ( data
);
466 ND_PRINT (( ndo
, "smb_bcc=%u \n " , bcc
));
469 smb_fdata ( ndo
, data
+ 2 , f2
, min ( data
+ 2 + EXTRACT_LE_16BITS ( data
),
470 maxbuf
), unicodestr
);
472 smb_print_data ( ndo
, data
+ 2 , min ( EXTRACT_LE_16BITS ( data
), PTR_DIFF ( maxbuf
, data
+ 2 )));
476 ND_PRINT (( ndo
, "%s" , tstr
));
480 print_lockingandx ( netdissect_options
* ndo
,
481 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
484 const u_char
* maxwords
;
485 const char * f1
= NULL
, * f2
= NULL
;
490 f1
= "Com2=[w] \n Off2=[d] \n Handle=[d] \n LockType=[w] \n TimeOut=[D] \n UnlockCount=[d] \n LockCount=[d] \n " ;
493 f2
= "*Process=[d] \n [P2]Offset=[M] \n Length=[M] \n " ;
495 f2
= "*Process=[d] \n Offset=[D] \n Length=[D] \n " ;
497 f1
= "Com2=[w] \n Off2=[d] \n " ;
500 maxwords
= min ( words
+ 1 + wct
* 2 , maxbuf
);
502 smb_fdata ( ndo
, words
+ 1 , f1
, maxwords
, unicodestr
);
504 ND_TCHECK2 (* data
, 2 );
505 bcc
= EXTRACT_LE_16BITS ( data
);
506 ND_PRINT (( ndo
, "smb_bcc=%u \n " , bcc
));
509 smb_fdata ( ndo
, data
+ 2 , f2
, min ( data
+ 2 + EXTRACT_LE_16BITS ( data
),
510 maxbuf
), unicodestr
);
512 smb_print_data ( ndo
, data
+ 2 , min ( EXTRACT_LE_16BITS ( data
), PTR_DIFF ( maxbuf
, data
+ 2 )));
516 ND_PRINT (( ndo
, "%s" , tstr
));
520 static const struct smbfns smb_fns
[] = {
521 { - 1 , "SMBunknown" , 0 , DEFDESCRIPT
},
523 { SMBtcon
, "SMBtcon" , 0 ,
524 { NULL
, "Path=[Z] \n Password=[Z] \n Device=[Z] \n " ,
525 "MaxXmit=[d] \n TreeId=[d] \n " , NULL
,
528 { SMBtdis
, "SMBtdis" , 0 , DEFDESCRIPT
},
529 { SMBexit
, "SMBexit" , 0 , DEFDESCRIPT
},
530 { SMBioctl
, "SMBioctl" , 0 , DEFDESCRIPT
},
532 { SMBecho
, "SMBecho" , 0 ,
533 { "ReverbCount=[d] \n " , NULL
,
534 "SequenceNum=[d] \n " , NULL
,
537 { SMBulogoffX
, "SMBulogoffX" , FLG_CHAIN
, DEFDESCRIPT
},
539 { SMBgetatr
, "SMBgetatr" , 0 ,
540 { NULL
, "Path=[Z] \n " ,
541 "Attribute=[A] \n Time=[T2]Size=[D] \n Res=([w,w,w,w,w]) \n " , NULL
,
544 { SMBsetatr
, "SMBsetatr" , 0 ,
545 { "Attribute=[A] \n Time=[T2]Res=([w,w,w,w,w]) \n " , "Path=[Z] \n " ,
546 NULL
, NULL
, NULL
} },
548 { SMBchkpth
, "SMBchkpth" , 0 ,
549 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
551 { SMBsearch
, "SMBsearch" , 0 ,
552 { "Count=[d] \n Attrib=[A] \n " ,
553 "Path=[Z] \n BlkType=[B] \n BlkLen=[d] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n Res2=[W] \n " ,
555 "BlkType=[B] \n BlkLen=[d] \n * \n Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n Res2=[W] \n Attrib=[a] \n Time=[T1]Size=[D] \n Name=[s13] \n " ,
558 { SMBopen
, "SMBopen" , 0 ,
559 { "Mode=[w] \n Attribute=[A] \n " , "Path=[Z] \n " ,
560 "Handle=[d] \n OAttrib=[A] \n Time=[T2]Size=[D] \n Access=[w] \n " ,
563 { SMBcreate
, "SMBcreate" , 0 ,
564 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " , "Handle=[d] \n " , NULL
, NULL
} },
566 { SMBmknew
, "SMBmknew" , 0 ,
567 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " , "Handle=[d] \n " , NULL
, NULL
} },
569 { SMBunlink
, "SMBunlink" , 0 ,
570 { "Attrib=[A] \n " , "Path=[Z] \n " , NULL
, NULL
, NULL
} },
572 { SMBread
, "SMBread" , 0 ,
573 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
574 "Count=[d] \n Res=([w,w,w,w]) \n " , NULL
, NULL
} },
576 { SMBwrite
, "SMBwrite" , 0 ,
577 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
578 "Count=[d] \n " , NULL
, NULL
} },
580 { SMBclose
, "SMBclose" , 0 ,
581 { "Handle=[d] \n Time=[T2]" , NULL
, NULL
, NULL
, NULL
} },
583 { SMBmkdir
, "SMBmkdir" , 0 ,
584 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
586 { SMBrmdir
, "SMBrmdir" , 0 ,
587 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
589 { SMBdskattr
, "SMBdskattr" , 0 ,
591 "TotalUnits=[d] \n BlocksPerUnit=[d] \n BlockSize=[d] \n FreeUnits=[d] \n Media=[w] \n " ,
595 { "Attrib=[A] \n " , "OldPath=[Z] \n NewPath=[Z] \n " , NULL
, NULL
, NULL
} },
598 * this is a Pathworks specific call, allowing the
599 * changing of the root path
601 { pSETDIR
, "SMBsetdir" , 0 , { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
603 { SMBlseek
, "SMBlseek" , 0 ,
604 { "Handle=[d] \n Mode=[w] \n Offset=[D] \n " , "Offset=[D] \n " , NULL
, NULL
, NULL
} },
606 { SMBflush
, "SMBflush" , 0 , { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
608 { SMBsplopen
, "SMBsplopen" , 0 ,
609 { "SetupLen=[d] \n Mode=[w] \n " , "Ident=[Z] \n " , "Handle=[d] \n " ,
612 { SMBsplclose
, "SMBsplclose" , 0 ,
613 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
615 { SMBsplretq
, "SMBsplretq" , 0 ,
616 { "MaxCount=[d] \n StartIndex=[d] \n " , NULL
,
617 "Count=[d] \n Index=[d] \n " ,
618 "*Time=[T2]Status=[B] \n JobID=[d] \n Size=[D] \n Res=[B]Name=[s16] \n " ,
621 { SMBsplwr
, "SMBsplwr" , 0 ,
622 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
624 { SMBlock
, "SMBlock" , 0 ,
625 { "Handle=[d] \n Count=[D] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
} },
627 { SMBunlock
, "SMBunlock" , 0 ,
628 { "Handle=[d] \n Count=[D] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
} },
630 /* CORE+ PROTOCOL FOLLOWS */
632 { SMBreadbraw
, "SMBreadbraw" , 0 ,
633 { "Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n Res=[d] \n " ,
634 NULL
, NULL
, NULL
, NULL
} },
636 { SMBwritebraw
, "SMBwritebraw" , 0 ,
637 { "Handle=[d] \n TotalCount=[d] \n Res=[w] \n Offset=[D] \n TimeOut=[D] \n WMode=[w] \n Res2=[W] \n |DataSize=[d] \n DataOff=[d] \n " ,
638 NULL
, "WriteRawAck" , NULL
, NULL
} },
640 { SMBwritec
, "SMBwritec" , 0 ,
641 { NULL
, NULL
, "Count=[d] \n " , NULL
, NULL
} },
643 { SMBwriteclose
, "SMBwriteclose" , 0 ,
644 { "Handle=[d] \n Count=[d] \n Offset=[D] \n Time=[T2]Res=([w,w,w,w,w,w])" ,
645 NULL
, "Count=[d] \n " , NULL
, NULL
} },
647 { SMBlockread
, "SMBlockread" , 0 ,
648 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
649 "Count=[d] \n Res=([w,w,w,w]) \n " , NULL
, NULL
} },
651 { SMBwriteunlock
, "SMBwriteunlock" , 0 ,
652 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
653 "Count=[d] \n " , NULL
, NULL
} },
655 { SMBreadBmpx
, "SMBreadBmpx" , 0 ,
656 { "Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n Res=[w] \n " ,
658 "Offset=[D] \n TotCount=[d] \n Remaining=[d] \n Res=([w,w]) \n DataSize=[d] \n DataOff=[d] \n " ,
661 { SMBwriteBmpx
, "SMBwriteBmpx" , 0 ,
662 { "Handle=[d] \n TotCount=[d] \n Res=[w] \n Offset=[D] \n TimeOut=[D] \n WMode=[w] \n Res2=[W] \n DataSize=[d] \n DataOff=[d] \n " , NULL
,
663 "Remaining=[d] \n " , NULL
, NULL
} },
665 { SMBwriteBs
, "SMBwriteBs" , 0 ,
666 { "Handle=[d] \n TotCount=[d] \n Offset=[D] \n Res=[W] \n DataSize=[d] \n DataOff=[d] \n " ,
667 NULL
, "Count=[d] \n " , NULL
, NULL
} },
669 { SMBsetattrE
, "SMBsetattrE" , 0 ,
670 { "Handle=[d] \n CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]" , NULL
,
671 NULL
, NULL
, NULL
} },
673 { SMBgetattrE
, "SMBgetattrE" , 0 ,
674 { "Handle=[d] \n " , NULL
,
675 "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D] \n AllocSize=[D] \n Attribute=[A] \n " ,
678 { SMBtranss
, "SMBtranss" , 0 , DEFDESCRIPT
},
679 { SMBioctls
, "SMBioctls" , 0 , DEFDESCRIPT
},
681 { SMBcopy
, "SMBcopy" , 0 ,
682 { "TreeID2=[d] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
683 "CopyCount=[d] \n " , "|ErrStr=[S] \n " , NULL
} },
685 { SMBmove
, "SMBmove" , 0 ,
686 { "TreeID2=[d] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
687 "MoveCount=[d] \n " , "|ErrStr=[S] \n " , NULL
} },
689 { SMBopenX
, "SMBopenX" , FLG_CHAIN
,
690 { "Com2=[w] \n Off2=[d] \n Flags=[w] \n Mode=[w] \n SearchAttrib=[A] \n Attrib=[A] \n Time=[T2]OFun=[w] \n Size=[D] \n TimeOut=[D] \n Res=[W] \n " ,
692 "Com2=[w] \n Off2=[d] \n Handle=[d] \n Attrib=[A] \n Time=[T2]Size=[D] \n Access=[w] \n Type=[w] \n State=[w] \n Action=[w] \n FileID=[W] \n Res=[w] \n " ,
695 { SMBreadX
, "SMBreadX" , FLG_CHAIN
,
696 { "Com2=[w] \n Off2=[d] \n Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n CountLeft=[d] \n " ,
698 "Com2=[w] \n Off2=[d] \n Remaining=[d] \n Res=[W] \n DataSize=[d] \n DataOff=[d] \n Res=([w,w,w,w]) \n " ,
701 { SMBwriteX
, "SMBwriteX" , FLG_CHAIN
,
702 { "Com2=[w] \n Off2=[d] \n Handle=[d] \n Offset=[D] \n TimeOut=[D] \n WMode=[w] \n CountLeft=[d] \n Res=[w] \n DataSize=[d] \n DataOff=[d] \n " ,
704 "Com2=[w] \n Off2=[d] \n Count=[d] \n Remaining=[d] \n Res=[W] \n " ,
707 { SMBffirst
, "SMBffirst" , 0 ,
708 { "Count=[d] \n Attrib=[A] \n " ,
709 "Path=[Z] \n BlkType=[B] \n BlkLen=[d] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n " ,
711 "BlkType=[B] \n BlkLen=[d] \n * \n Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n Res2=[W] \n Attrib=[a] \n Time=[T1]Size=[D] \n Name=[s13] \n " ,
714 { SMBfunique
, "SMBfunique" , 0 ,
715 { "Count=[d] \n Attrib=[A] \n " ,
716 "Path=[Z] \n BlkType=[B] \n BlkLen=[d] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n " ,
718 "BlkType=[B] \n BlkLen=[d] \n * \n Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n Res2=[W] \n Attrib=[a] \n Time=[T1]Size=[D] \n Name=[s13] \n " ,
721 { SMBfclose
, "SMBfclose" , 0 ,
722 { "Count=[d] \n Attrib=[A] \n " ,
723 "Path=[Z] \n BlkType=[B] \n BlkLen=[d] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n " ,
725 "BlkType=[B] \n BlkLen=[d] \n * \n Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n Res2=[W] \n Attrib=[a] \n Time=[T1]Size=[D] \n Name=[s13] \n " ,
728 { SMBfindnclose
, "SMBfindnclose" , 0 ,
729 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
731 { SMBfindclose
, "SMBfindclose" , 0 ,
732 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
734 { SMBsends
, "SMBsends" , 0 ,
735 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
} },
737 { SMBsendstrt
, "SMBsendstrt" , 0 ,
738 { NULL
, "Source=[Z] \n Dest=[Z] \n " , "GroupID=[d] \n " , NULL
, NULL
} },
740 { SMBsendend
, "SMBsendend" , 0 ,
741 { "GroupID=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
743 { SMBsendtxt
, "SMBsendtxt" , 0 ,
744 { "GroupID=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
746 { SMBsendb
, "SMBsendb" , 0 ,
747 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
} },
749 { SMBfwdname
, "SMBfwdname" , 0 , DEFDESCRIPT
},
750 { SMBcancelf
, "SMBcancelf" , 0 , DEFDESCRIPT
},
751 { SMBgetmac
, "SMBgetmac" , 0 , DEFDESCRIPT
},
753 { SMBnegprot
, "SMBnegprot" , 0 ,
754 { NULL
, NULL
, NULL
, NULL
, print_negprot
} },
756 { SMBsesssetupX
, "SMBsesssetupX" , FLG_CHAIN
,
757 { NULL
, NULL
, NULL
, NULL
, print_sesssetup
} },
759 { SMBtconX
, "SMBtconX" , FLG_CHAIN
,
760 { "Com2=[w] \n Off2=[d] \n Flags=[w] \n PassLen=[d] \n Passwd&Path&Device= \n " ,
761 NULL
, "Com2=[w] \n Off2=[d] \n " , "ServiceType=[R] \n " , NULL
} },
763 { SMBlockingX
, "SMBlockingX" , FLG_CHAIN
,
764 { NULL
, NULL
, NULL
, NULL
, print_lockingandx
} },
766 { SMBtrans2
, "SMBtrans2" , 0 , { NULL
, NULL
, NULL
, NULL
, print_trans2
} },
768 { SMBtranss2
, "SMBtranss2" , 0 , DEFDESCRIPT
},
769 { SMBctemp
, "SMBctemp" , 0 , DEFDESCRIPT
},
770 { SMBreadBs
, "SMBreadBs" , 0 , DEFDESCRIPT
},
771 { SMBtrans
, "SMBtrans" , 0 , { NULL
, NULL
, NULL
, NULL
, print_trans
} },
773 { SMBnttrans
, "SMBnttrans" , 0 , DEFDESCRIPT
},
774 { SMBnttranss
, "SMBnttranss" , 0 , DEFDESCRIPT
},
776 { SMBntcreateX
, "SMBntcreateX" , FLG_CHAIN
,
777 { "Com2=[w] \n Off2=[d] \n Res=[b] \n NameLen=[ld] \n Flags=[W] \n RootDirectoryFid=[D] \n AccessMask=[W] \n AllocationSize=[L] \n ExtFileAttributes=[W] \n ShareAccess=[W] \n CreateDisposition=[W] \n CreateOptions=[W] \n ImpersonationLevel=[W] \n SecurityFlags=[b] \n " ,
779 "Com2=[w] \n Off2=[d] \n OplockLevel=[b] \n Fid=[d] \n CreateAction=[W] \n CreateTime=[T3]LastAccessTime=[T3]LastWriteTime=[T3]ChangeTime=[T3]ExtFileAttributes=[W] \n AllocationSize=[L] \n EndOfFile=[L] \n FileType=[w] \n DeviceState=[w] \n Directory=[b] \n " ,
782 { SMBntcancel
, "SMBntcancel" , 0 , DEFDESCRIPT
},
784 { - 1 , NULL
, 0 , DEFDESCRIPT
}
789 * print a SMB message
792 print_smb ( netdissect_options
* ndo
,
793 const u_char
* buf
, const u_char
* maxbuf
)
799 const u_char
* words
, * maxwords
, * data
;
800 const struct smbfns
* fn
;
801 const char * fmt_smbheader
=
802 "[P4]SMB Command = [B] \n Error class = [BP1] \n Error code = [d] \n Flags1 = [B] \n Flags2 = [B][P13] \n Tree ID = [d] \n Proc ID = [d] \n UID = [d] \n MID = [d] \n Word Count = [b] \n " ;
806 request
= ( buf
[ 9 ] & 0x80 ) ? 0 : 1 ;
807 flags2
= EXTRACT_LE_16BITS (& buf
[ 10 ]);
808 unicodestr
= flags2
& 0x8000 ;
809 nterrcodes
= flags2
& 0x4000 ;
814 fn
= smbfind ( command
, smb_fns
);
816 if ( ndo
-> ndo_vflag
> 1 )
817 ND_PRINT (( ndo
, " \n " ));
819 ND_PRINT (( ndo
, "SMB PACKET: %s (%s) \n " , fn
-> name
, request
? "REQUEST" : "REPLY" ));
821 if ( ndo
-> ndo_vflag
< 2 )
824 /* print out the header */
825 smb_fdata ( ndo
, buf
, fmt_smbheader
, buf
+ 33 , unicodestr
);
828 nterror
= EXTRACT_LE_32BITS (& buf
[ 5 ]);
830 ND_PRINT (( ndo
, "NTError = %s \n " , nt_errstr ( nterror
)));
833 ND_PRINT (( ndo
, "SMBError = %s \n " , smb_errstr ( buf
[ 5 ], EXTRACT_LE_16BITS (& buf
[ 7 ]))));
844 words
= buf
+ smboffset
;
847 data
= words
+ 1 + wct
* 2 ;
848 maxwords
= min ( data
, maxbuf
);
851 f1
= fn
-> descript
. req_f1
;
852 f2
= fn
-> descript
. req_f2
;
854 f1
= fn
-> descript
. rep_f1
;
855 f2
= fn
-> descript
. rep_f2
;
859 (* fn
-> descript
. fn
)( ndo
, words
, data
, buf
, maxbuf
);
863 smb_fdata ( ndo
, words
+ 1 , f1
, words
+ 1 + wct
* 2 , unicodestr
);
868 for ( i
= 0 ; & words
[ 1 + 2 * i
] < maxwords
; i
++) {
869 ND_TCHECK2 ( words
[ 1 + 2 * i
], 2 );
870 v
= EXTRACT_LE_16BITS ( words
+ 1 + 2 * i
);
871 ND_PRINT (( ndo
, "smb_vwv[%d]=%d (0x%X) \n " , i
, v
, v
));
876 ND_TCHECK2 (* data
, 2 );
877 bcc
= EXTRACT_LE_16BITS ( data
);
878 ND_PRINT (( ndo
, "smb_bcc=%u \n " , bcc
));
881 smb_fdata ( ndo
, data
+ 2 , f2
, data
+ 2 + bcc
, unicodestr
);
884 ND_PRINT (( ndo
, "smb_buf[]= \n " ));
885 smb_print_data ( ndo
, data
+ 2 , min ( bcc
, PTR_DIFF ( maxbuf
, data
+ 2 )));
890 if (( fn
-> flags
& FLG_CHAIN
) == 0 )
898 ND_TCHECK2 ( words
[ 3 ], 2 );
899 newsmboffset
= EXTRACT_LE_16BITS ( words
+ 3 );
901 fn
= smbfind ( command
, smb_fns
);
903 ND_PRINT (( ndo
, " \n SMB PACKET: %s (%s) (CHAINED) \n " ,
904 fn
-> name
, request
? "REQUEST" : "REPLY" ));
905 if ( newsmboffset
<= smboffset
) {
906 ND_PRINT (( ndo
, "Bad andX offset: %u <= %u \n " , newsmboffset
, smboffset
));
909 smboffset
= newsmboffset
;
912 ND_PRINT (( ndo
, " \n " ));
915 ND_PRINT (( ndo
, "%s" , tstr
));
920 * print a NBT packet received across tcp on port 139
923 nbt_tcp_print ( netdissect_options
* ndo
,
924 const u_char
* data
, int length
)
929 const u_char
* maxbuf
;
933 if ( ndo
-> ndo_snapend
< data
)
935 caplen
= ndo
-> ndo_snapend
- data
;
938 maxbuf
= data
+ caplen
;
940 nbt_len
= EXTRACT_16BITS ( data
+ 2 );
946 if ( ndo
-> ndo_vflag
< 2 ) {
947 ND_PRINT (( ndo
, " NBT Session Packet: " ));
950 ND_PRINT (( ndo
, "Session Message" ));
954 ND_PRINT (( ndo
, "Session Request" ));
958 ND_PRINT (( ndo
, "Session Granted" ));
973 ND_PRINT (( ndo
, "Session Reject, " ));
976 ND_PRINT (( ndo
, "Not listening on called name" ));
979 ND_PRINT (( ndo
, "Not listening for calling name" ));
982 ND_PRINT (( ndo
, "Called name not present" ));
985 ND_PRINT (( ndo
, "Called name present, but insufficient resources" ));
988 ND_PRINT (( ndo
, "Unspecified error 0x%X" , ecode
));
995 ND_PRINT (( ndo
, "Session Keepalive" ));
999 data
= smb_fdata ( ndo
, data
, "Unknown packet type [rB]" , maxbuf
, 0 );
1003 ND_PRINT (( ndo
, " \n >>> NBT Session Packet \n " ));
1006 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Message \n Flags=[B] \n Length=[rd] \n " ,
1010 if ( nbt_len
>= 4 && caplen
>= 4 && memcmp ( data
, " \377 SMB" , 4 ) == 0 ) {
1011 if (( int ) nbt_len
> caplen
) {
1012 if (( int ) nbt_len
> length
)
1013 ND_PRINT (( ndo
, "WARNING: Packet is continued in later TCP segments \n " ));
1015 ND_PRINT (( ndo
, "WARNING: Short packet. Try increasing the snap length by %d \n " ,
1018 print_smb ( ndo
, data
, maxbuf
> data
+ nbt_len
? data
+ nbt_len
: maxbuf
);
1020 ND_PRINT (( ndo
, "Session packet:(raw data or continuation?) \n " ));
1024 data
= smb_fdata ( ndo
, data
,
1025 "[P1]NBT Session Request \n Flags=[B] \n Length=[rd] \n Destination=[n1] \n Source=[n1] \n " ,
1030 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Granted \n Flags=[B] \n Length=[rd] \n " , maxbuf
, 0 );
1035 const u_char
* origdata
;
1039 data
= smb_fdata ( ndo
, data
, "[P1]NBT SessionReject \n Flags=[B] \n Length=[rd] \n Reason=[B] \n " ,
1043 if ( nbt_len
>= 1 && caplen
>= 1 ) {
1044 ecode
= origdata
[ 4 ];
1047 ND_PRINT (( ndo
, "Not listening on called name \n " ));
1050 ND_PRINT (( ndo
, "Not listening for calling name \n " ));
1053 ND_PRINT (( ndo
, "Called name not present \n " ));
1056 ND_PRINT (( ndo
, "Called name present, but insufficient resources \n " ));
1059 ND_PRINT (( ndo
, "Unspecified error 0x%X \n " , ecode
));
1067 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Keepalive \n Flags=[B] \n Length=[rd] \n " , maxbuf
, 0 );
1071 data
= smb_fdata ( ndo
, data
, "NBT - Unknown packet type \n Type=[B] \n " , maxbuf
, 0 );
1074 ND_PRINT (( ndo
, " \n " ));
1078 ND_PRINT (( ndo
, "%s" , tstr
));
1081 static const struct tok opcode_str
[] = {
1083 { 5 , "REGISTRATION" },
1086 { 8 , "REFRESH(8)" },
1088 { 15 , "MULTIHOMED REGISTRATION" },
1093 * print a NBT packet received across udp on port 137
1096 nbt_udp137_print ( netdissect_options
* ndo
,
1097 const u_char
* data
, int length
)
1099 const u_char
* maxbuf
= data
+ length
;
1100 int name_trn_id
, response
, opcode
, nm_flags
, rcode
;
1101 int qdcount
, ancount
, nscount
, arcount
;
1105 ND_TCHECK2 ( data
[ 10 ], 2 );
1106 name_trn_id
= EXTRACT_16BITS ( data
);
1107 response
= ( data
[ 2 ] >> 7 );
1108 opcode
= ( data
[ 2 ] >> 3 ) & 0xF ;
1109 nm_flags
= (( data
[ 2 ] & 0x7 ) << 4 ) + ( data
[ 3 ] >> 4 );
1110 rcode
= data
[ 3 ] & 0xF ;
1111 qdcount
= EXTRACT_16BITS ( data
+ 4 );
1112 ancount
= EXTRACT_16BITS ( data
+ 6 );
1113 nscount
= EXTRACT_16BITS ( data
+ 8 );
1114 arcount
= EXTRACT_16BITS ( data
+ 10 );
1120 if ( ndo
-> ndo_vflag
> 1 )
1121 ND_PRINT (( ndo
, " \n >>> " ));
1123 ND_PRINT (( ndo
, "NBT UDP PACKET(137): %s" , tok2str ( opcode_str
, "OPUNKNOWN" , opcode
)));
1125 ND_PRINT (( ndo
, "; %s" , rcode
? "NEGATIVE" : "POSITIVE" ));
1127 ND_PRINT (( ndo
, "; %s; %s" , response
? "RESPONSE" : "REQUEST" ,
1128 ( nm_flags
& 1 ) ? "BROADCAST" : "UNICAST" ));
1130 if ( ndo
-> ndo_vflag
< 2 )
1133 ND_PRINT (( ndo
, " \n TrnID=0x%X \n OpCode=%d \n NmFlags=0x%X \n Rcode=%d \n QueryCount=%d \n AnswerCount=%d \n AuthorityCount=%d \n AddressRecCount=%d \n " ,
1134 name_trn_id
, opcode
, nm_flags
, rcode
, qdcount
, ancount
, nscount
,
1139 total
= ancount
+ nscount
+ arcount
;
1141 if ( qdcount
> 100 || total
> 100 ) {
1142 ND_PRINT (( ndo
, "Corrupt packet?? \n " ));
1147 ND_PRINT (( ndo
, "QuestionRecords: \n " ));
1148 for ( i
= 0 ; i
< qdcount
; i
++) {
1149 p
= smb_fdata ( ndo
, p
,
1150 "|Name=[n1] \n QuestionType=[rw] \n QuestionClass=[rw] \n #" ,
1158 ND_PRINT (( ndo
, " \n ResourceRecords: \n " ));
1159 for ( i
= 0 ; i
< total
; i
++) {
1163 p
= smb_fdata ( ndo
, p
, "Name=[n1] \n #" , maxbuf
, 0 );
1166 restype
= EXTRACT_16BITS ( p
);
1167 p
= smb_fdata ( ndo
, p
, "ResType=[rw] \n ResClass=[rw] \n TTL=[rD] \n " , p
+ 8 , 0 );
1170 rdlen
= EXTRACT_16BITS ( p
);
1171 ND_PRINT (( ndo
, "ResourceLength=%d \n ResourceData= \n " , rdlen
));
1174 p
= smb_fdata ( ndo
, p
, "AddrType=[rw] \n Address=[b.b.b.b] \n " , p
+ rdlen
, 0 );
1178 if ( restype
== 0x21 ) {
1183 p
= smb_fdata ( ndo
, p
, "NumNames=[B] \n " , p
+ 1 , 0 );
1186 while ( numnames
--) {
1187 p
= smb_fdata ( ndo
, p
, "Name=[n2] \t #" , maxbuf
, 0 );
1192 ND_PRINT (( ndo
, "<GROUP> " ));
1193 switch ( p
[ 0 ] & 0x60 ) {
1194 case 0x00 : ND_PRINT (( ndo
, "B " )); break ;
1195 case 0x20 : ND_PRINT (( ndo
, "P " )); break ;
1196 case 0x40 : ND_PRINT (( ndo
, "M " )); break ;
1197 case 0x60 : ND_PRINT (( ndo
, "_ " )); break ;
1200 ND_PRINT (( ndo
, "<DEREGISTERING> " ));
1202 ND_PRINT (( ndo
, "<CONFLICT> " ));
1204 ND_PRINT (( ndo
, "<ACTIVE> " ));
1206 ND_PRINT (( ndo
, "<PERMANENT> " ));
1207 ND_PRINT (( ndo
, " \n " ));
1211 smb_print_data ( ndo
, p
, min ( rdlen
, length
- ( p
- data
)));
1219 smb_fdata ( ndo
, p
, "AdditionalData: \n " , maxbuf
, 0 );
1222 ND_PRINT (( ndo
, " \n " ));
1225 ND_PRINT (( ndo
, "%s" , tstr
));
1229 * Print an SMB-over-TCP packet received across tcp on port 445
1232 smb_tcp_print ( netdissect_options
* ndo
,
1233 const u_char
* data
, int length
)
1237 const u_char
* maxbuf
;
1241 if ( ndo
-> ndo_snapend
< data
)
1243 caplen
= ndo
-> ndo_snapend
- data
;
1246 maxbuf
= data
+ caplen
;
1247 smb_len
= EXTRACT_24BITS ( data
+ 1 );
1254 if ( smb_len
>= 4 && caplen
>= 4 && memcmp ( data
, " \377 SMB" , 4 ) == 0 ) {
1255 if (( int ) smb_len
> caplen
) {
1256 if (( int ) smb_len
> length
)
1257 ND_PRINT (( ndo
, " WARNING: Packet is continued in later TCP segments \n " ));
1259 ND_PRINT (( ndo
, " WARNING: Short packet. Try increasing the snap length by %d \n " ,
1262 ND_PRINT (( ndo
, " " ));
1263 print_smb ( ndo
, data
, maxbuf
> data
+ smb_len
? data
+ smb_len
: maxbuf
);
1265 ND_PRINT (( ndo
, " SMB-over-TCP packet:(raw data or continuation?) \n " ));
1268 ND_PRINT (( ndo
, "%s" , tstr
));
1272 * print a NBT packet received across udp on port 138
1275 nbt_udp138_print ( netdissect_options
* ndo
,
1276 const u_char
* data
, int length
)
1278 const u_char
* maxbuf
= data
+ length
;
1280 if ( maxbuf
> ndo
-> ndo_snapend
)
1281 maxbuf
= ndo
-> ndo_snapend
;
1286 if ( ndo
-> ndo_vflag
< 2 ) {
1287 ND_PRINT (( ndo
, "NBT UDP PACKET(138)" ));
1291 data
= smb_fdata ( ndo
, data
,
1292 " \n >>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[rd] Length=[rd] Res2=[rw] \n SourceName=[n1] \n DestName=[n1] \n #" ,
1296 /* If there isn't enough data for "\377SMB", don't check for it. */
1297 if (& data
[ 3 ] >= maxbuf
)
1300 if ( memcmp ( data
, " \377 SMB" , 4 ) == 0 )
1301 print_smb ( ndo
, data
, maxbuf
);
1304 ND_PRINT (( ndo
, " \n " ));
1309 print netbeui frames
1311 struct nbf_strings
{
1313 const char * nonverbose
;
1314 const char * verbose
;
1315 } nbf_strings
[ 0x20 ] = {
1316 { "Add Group Name Query" , ", [P23]Name to add=[n2]#" ,
1317 "[P5]ResponseCorrelator=[w] \n [P16]Name to add=[n2] \n " },
1318 { "Add Name Query" , ", [P23]Name to add=[n2]#" ,
1319 "[P5]ResponseCorrelator=[w] \n [P16]Name to add=[n2] \n " },
1320 { "Name In Conflict" , NULL
, NULL
},
1321 { "Status Query" , NULL
, NULL
},
1322 { NULL
, NULL
, NULL
}, /* not used */
1323 { NULL
, NULL
, NULL
}, /* not used */
1324 { NULL
, NULL
, NULL
}, /* not used */
1325 { "Terminate Trace" , NULL
, NULL
},
1327 "[P7]Destination=[n2] \n Source=[n2] \n " },
1328 { "Broadcast Datagram" , NULL
,
1329 "[P7]Destination=[n2] \n Source=[n2] \n " },
1330 { "Name Query" , ", [P7]Name=[n2]#" ,
1331 "[P1]SessionNumber=[B] \n NameType=[B][P2] \n ResponseCorrelator=[w] \n Name=[n2] \n Name of sender=[n2] \n " },
1332 { NULL
, NULL
, NULL
}, /* not used */
1333 { NULL
, NULL
, NULL
}, /* not used */
1334 { "Add Name Response" , ", [P1]GroupName=[w] [P4]Destination=[n2] Source=[n2]#" ,
1335 "AddNameInProcess=[B] \n GroupName=[w] \n TransmitCorrelator=[w][P2] \n Destination=[n2] \n Source=[n2] \n " },
1336 { "Name Recognized" , NULL
,
1337 "[P1]Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n Destination=[n2] \n Source=[n2] \n " },
1338 { "Status Response" , NULL
, NULL
},
1339 { NULL
, NULL
, NULL
}, /* not used */
1340 { NULL
, NULL
, NULL
}, /* not used */
1341 { NULL
, NULL
, NULL
}, /* not used */
1342 { "Terminate Trace" , NULL
, NULL
},
1344 "[P3]TransmitCorrelator=[w][P2] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1345 { "Data First/Middle" , NULL
,
1346 "Flags=[{RECEIVE_CONTINUE|NO_ACK||PIGGYBACK_ACK_INCLUDED|}] \n ResyncIndicator=[w][P2] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1347 { "Data Only/Last" , NULL
,
1348 "Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}] \n ResyncIndicator=[w][P2] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1349 { "Session Confirm" , NULL
,
1350 "Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1351 { "Session End" , NULL
,
1352 "[P1]Data2=[w][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1353 { "Session Initialize" , NULL
,
1354 "Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1355 { "No Receive" , NULL
,
1356 "Flags=[{|SEND_NO_ACK}] \n DataBytesAccepted=[b][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1357 { "Receive Outstanding" , NULL
,
1358 "[P1]DataBytesAccepted=[b][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1359 { "Receive Continue" , NULL
,
1360 "[P2]TransmitCorrelator=[w] \n [P2]RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1361 { NULL
, NULL
, NULL
}, /* not used */
1362 { NULL
, NULL
, NULL
}, /* not used */
1363 { "Session Alive" , NULL
, NULL
}
1367 netbeui_print ( netdissect_options
* ndo
,
1368 u_short control
, const u_char
* data
, int length
)
1370 const u_char
* maxbuf
= data
+ length
;
1373 const u_char
* data2
;
1374 int is_truncated
= 0 ;
1376 if ( maxbuf
> ndo
-> ndo_snapend
)
1377 maxbuf
= ndo
-> ndo_snapend
;
1379 len
= EXTRACT_LE_16BITS ( data
);
1382 if ( data2
>= maxbuf
) {
1389 if ( ndo
-> ndo_vflag
< 2 ) {
1390 ND_PRINT (( ndo
, "NBF Packet: " ));
1391 data
= smb_fdata ( ndo
, data
, "[P5]#" , maxbuf
, 0 );
1393 ND_PRINT (( ndo
, " \n >>> NBF Packet \n Type=0x%X " , control
));
1394 data
= smb_fdata ( ndo
, data
, "Length=[d] Signature=[w] Command=[B] \n #" , maxbuf
, 0 );
1399 if ( command
> 0x1f || nbf_strings
[ command
]. name
== NULL
) {
1400 if ( ndo
-> ndo_vflag
< 2 )
1401 data
= smb_fdata ( ndo
, data
, "Unknown NBF Command#" , data2
, 0 );
1403 data
= smb_fdata ( ndo
, data
, "Unknown NBF Command \n " , data2
, 0 );
1405 if ( ndo
-> ndo_vflag
< 2 ) {
1406 ND_PRINT (( ndo
, "%s" , nbf_strings
[ command
]. name
));
1407 if ( nbf_strings
[ command
]. nonverbose
!= NULL
)
1408 data
= smb_fdata ( ndo
, data
, nbf_strings
[ command
]. nonverbose
, data2
, 0 );
1410 ND_PRINT (( ndo
, "%s: \n " , nbf_strings
[ command
]. name
));
1411 if ( nbf_strings
[ command
]. verbose
!= NULL
)
1412 data
= smb_fdata ( ndo
, data
, nbf_strings
[ command
]. verbose
, data2
, 0 );
1414 ND_PRINT (( ndo
, " \n " ));
1418 if ( ndo
-> ndo_vflag
< 2 )
1425 /* data2 was past the end of the buffer */
1429 /* If this isn't a command that would contain an SMB message, quit. */
1430 if ( command
!= 0x08 && command
!= 0x09 && command
!= 0x15 &&
1434 /* If there isn't enough data for "\377SMB", don't look for it. */
1435 if (& data2
[ 3 ] >= maxbuf
)
1438 if ( memcmp ( data2
, " \377 SMB" , 4 ) == 0 )
1439 print_smb ( ndo
, data2
, maxbuf
);
1442 for ( i
= 0 ; i
< 128 ; i
++) {
1443 if (& data2
[ i
+ 3 ] >= maxbuf
)
1445 if ( memcmp (& data2
[ i
], " \377 SMB" , 4 ) == 0 ) {
1446 ND_PRINT (( ndo
, "found SMB packet at %d \n " , i
));
1447 print_smb ( ndo
, & data2
[ i
], maxbuf
);
1454 ND_PRINT (( ndo
, " \n " ));
1457 ND_PRINT (( ndo
, "%s" , tstr
));
1462 * print IPX-Netbios frames
1465 ipx_netbios_print ( netdissect_options
* ndo
,
1466 const u_char
* data
, u_int length
)
1469 * this is a hack till I work out how to parse the rest of the
1470 * NetBIOS-over-IPX stuff
1473 const u_char
* maxbuf
;
1475 maxbuf
= data
+ length
;
1476 /* Don't go past the end of the captured data in the packet. */
1477 if ( maxbuf
> ndo
-> ndo_snapend
)
1478 maxbuf
= ndo
-> ndo_snapend
;
1480 for ( i
= 0 ; i
< 128 ; i
++) {
1481 if (& data
[ i
+ 4 ] > maxbuf
)
1483 if ( memcmp (& data
[ i
], " \377 SMB" , 4 ) == 0 ) {
1484 smb_fdata ( ndo
, data
, " \n >>> IPX transport " , & data
[ i
], 0 );
1485 print_smb ( ndo
, & data
[ i
], maxbuf
);
1486 ND_PRINT (( ndo
, " \n " ));
1491 smb_fdata ( ndo
, data
, " \n >>> Unknown IPX " , maxbuf
, 0 );