]>
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
9 /* \summary: SMB/CIFS printer */
15 #include <netdissect-stdinc.h>
19 #include "netdissect.h"
23 static const char tstr
[] = "[|SMB]" ;
25 static int request
= 0 ;
26 static int unicodestr
= 0 ;
28 const u_char
* startbuf
= NULL
;
35 void (* fn
)( netdissect_options
*, const u_char
*, const u_char
*, const u_char
*, const u_char
*);
38 struct smbdescriptint
{
43 void (* fn
)( netdissect_options
*, const u_char
*, const u_char
*, int , int );
51 struct smbdescript descript
;
59 struct smbdescriptint descript
;
62 #define DEFDESCRIPT { NULL, NULL, NULL, NULL, NULL }
64 #define FLG_CHAIN (1 << 0)
66 static const struct smbfns
*
67 smbfind ( int id
, const struct smbfns
* list
)
71 for ( sindex
= 0 ; list
[ sindex
]. name
; sindex
++)
72 if ( list
[ sindex
]. id
== id
)
73 return (& list
[ sindex
]);
78 static const struct smbfnsint
*
79 smbfindint ( int id
, const struct smbfnsint
* list
)
83 for ( sindex
= 0 ; list
[ sindex
]. name
; sindex
++)
84 if ( list
[ sindex
]. id
== id
)
85 return (& list
[ sindex
]);
91 trans2_findfirst ( netdissect_options
* ndo
,
92 const u_char
* param
, const u_char
* data
, int pcnt
, int dcnt
)
97 fmt
= "Attribute=[A] \n SearchCount=[d] \n Flags=[w] \n Level=[dP4] \n File=[S] \n " ;
99 fmt
= "Handle=[w] \n Count=[d] \n EOS=[w] \n Eoffset=[d] \n LastNameOfs=[w] \n " ;
101 smb_fdata ( ndo
, param
, fmt
, param
+ pcnt
, unicodestr
);
103 ND_PRINT (( ndo
, "data: \n " ));
104 smb_print_data ( ndo
, data
, dcnt
);
109 trans2_qfsinfo ( netdissect_options
* ndo
,
110 const u_char
* param
, const u_char
* data
, int pcnt
, int dcnt
)
112 static int level
= 0 ;
116 ND_TCHECK2 (* param
, 2 );
117 level
= EXTRACT_LE_16BITS ( param
);
118 fmt
= "InfoLevel=[d] \n " ;
119 smb_fdata ( ndo
, param
, fmt
, param
+ pcnt
, unicodestr
);
123 fmt
= "idFileSystem=[W] \n SectorUnit=[D] \n Unit=[D] \n Avail=[D] \n SectorSize=[d] \n " ;
126 fmt
= "CreationTime=[T2]VolNameLength=[lb] \n VolumeLabel=[c] \n " ;
129 fmt
= "Capabilities=[W] \n MaxFileLen=[D] \n VolNameLen=[lD] \n Volume=[C] \n " ;
132 fmt
= "UnknownLevel \n " ;
135 smb_fdata ( ndo
, data
, fmt
, data
+ dcnt
, unicodestr
);
138 ND_PRINT (( ndo
, "data: \n " ));
139 smb_print_data ( ndo
, data
, dcnt
);
143 ND_PRINT (( ndo
, "%s" , tstr
));
146 static const struct smbfnsint trans2_fns
[] = {
147 { 0 , "TRANSACT2_OPEN" , 0 ,
148 { "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]" ,
150 "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 " ,
152 { 1 , "TRANSACT2_FINDFIRST" , 0 ,
153 { NULL
, NULL
, NULL
, NULL
, trans2_findfirst
}},
154 { 2 , "TRANSACT2_FINDNEXT" , 0 , DEFDESCRIPT
},
155 { 3 , "TRANSACT2_QFSINFO" , 0 ,
156 { NULL
, NULL
, NULL
, NULL
, trans2_qfsinfo
}},
157 { 4 , "TRANSACT2_SETFSINFO" , 0 , DEFDESCRIPT
},
158 { 5 , "TRANSACT2_QPATHINFO" , 0 , DEFDESCRIPT
},
159 { 6 , "TRANSACT2_SETPATHINFO" , 0 , DEFDESCRIPT
},
160 { 7 , "TRANSACT2_QFILEINFO" , 0 , DEFDESCRIPT
},
161 { 8 , "TRANSACT2_SETFILEINFO" , 0 , DEFDESCRIPT
},
162 { 9 , "TRANSACT2_FSCTL" , 0 , DEFDESCRIPT
},
163 { 10 , "TRANSACT2_IOCTL" , 0 , DEFDESCRIPT
},
164 { 11 , "TRANSACT2_FINDNOTIFYFIRST" , 0 , DEFDESCRIPT
},
165 { 12 , "TRANSACT2_FINDNOTIFYNEXT" , 0 , DEFDESCRIPT
},
166 { 13 , "TRANSACT2_MKDIR" , 0 , DEFDESCRIPT
},
167 { - 1 , NULL
, 0 , DEFDESCRIPT
}
172 print_trans2 ( netdissect_options
* ndo
,
173 const u_char
* words
, const u_char
* dat
, const u_char
* buf
, const u_char
* maxbuf
)
176 static const struct smbfnsint
* fn
= & trans2_fns
[ 0 ];
177 const u_char
* data
, * param
;
178 const u_char
* w
= words
+ 1 ;
179 const char * f1
= NULL
, * f2
= NULL
;
184 ND_TCHECK2 ( w
[ 14 * 2 ], 2 );
185 pcnt
= EXTRACT_LE_16BITS ( w
+ 9 * 2 );
186 param
= buf
+ EXTRACT_LE_16BITS ( w
+ 10 * 2 );
187 dcnt
= EXTRACT_LE_16BITS ( w
+ 11 * 2 );
188 data
= buf
+ EXTRACT_LE_16BITS ( w
+ 12 * 2 );
189 fn
= smbfindint ( EXTRACT_LE_16BITS ( w
+ 14 * 2 ), trans2_fns
);
192 ND_PRINT (( ndo
, "%s \n " , fn
-> name
));
193 ND_PRINT (( ndo
, "Trans2Interim \n " ));
196 ND_TCHECK2 ( w
[ 7 * 2 ], 2 );
197 pcnt
= EXTRACT_LE_16BITS ( w
+ 3 * 2 );
198 param
= buf
+ EXTRACT_LE_16BITS ( w
+ 4 * 2 );
199 dcnt
= EXTRACT_LE_16BITS ( w
+ 6 * 2 );
200 data
= buf
+ EXTRACT_LE_16BITS ( w
+ 7 * 2 );
203 ND_PRINT (( ndo
, "%s param_length=%d data_length=%d \n " , fn
-> name
, pcnt
, dcnt
));
207 smb_fdata ( ndo
, words
+ 1 ,
208 "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 " ,
212 smb_fdata ( ndo
, words
+ 1 ,
213 "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 " ,
214 words
+ 1 + 14 * 2 , unicodestr
);
216 f1
= fn
-> descript
. req_f1
;
217 f2
= fn
-> descript
. req_f2
;
219 smb_fdata ( ndo
, words
+ 1 ,
220 "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 " ,
221 words
+ 1 + 10 * 2 , unicodestr
);
222 f1
= fn
-> descript
. rep_f1
;
223 f2
= fn
-> descript
. rep_f2
;
227 bcc
= EXTRACT_LE_16BITS ( dat
);
228 ND_PRINT (( ndo
, "smb_bcc=%u \n " , bcc
));
230 (* fn
-> descript
. fn
)( ndo
, param
, data
, pcnt
, dcnt
);
232 smb_fdata ( ndo
, param
, f1
? f1
: "Parameters= \n " , param
+ pcnt
, unicodestr
);
233 smb_fdata ( ndo
, data
, f2
? f2
: "Data= \n " , data
+ dcnt
, unicodestr
);
237 ND_PRINT (( ndo
, "%s" , tstr
));
241 print_browse ( netdissect_options
* ndo
,
242 const u_char
* param
, int paramlen
, const u_char
* data
, int datalen
)
244 const u_char
* maxbuf
= data
+ datalen
;
250 smb_fdata ( ndo
, param
, "BROWSE PACKET \n |Param " , param
+ paramlen
, unicodestr
);
254 data
= smb_fdata ( ndo
, data
,
255 "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 " ,
260 data
= smb_fdata ( ndo
, data
,
261 "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 " ,
266 data
= smb_fdata ( ndo
, data
,
267 "BROWSE PACKET: \n Type=[B] (AnnouncementRequest) \n Flags=[B] \n ReplySystemName=[S] \n " ,
272 data
= smb_fdata ( ndo
, data
,
273 "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 " ,
278 data
= smb_fdata ( ndo
, data
,
279 "BROWSE PACKET: \n Type=[B] (ElectionFrame) \n ElectionVersion=[B] \n OSSummary=[W] \n Uptime=[(W, W)] \n ServerName=[S] \n " ,
284 data
= smb_fdata ( ndo
, data
,
285 "BROWSE PACKET: \n Type=[B] (BecomeBackupBrowser) \n Name=[S] \n " ,
290 data
= smb_fdata ( ndo
, data
,
291 "BROWSE PACKET: \n Type=[B] (GetBackupList) \n ListCount?=[B] \n Token=[W] \n " ,
296 data
= smb_fdata ( ndo
, data
,
297 "BROWSE PACKET: \n Type=[B] (BackupListResponse) \n ServerCount?=[B] \n Token=[W] \n *Name=[S] \n " ,
302 data
= smb_fdata ( ndo
, data
,
303 "BROWSE PACKET: \n Type=[B] (MasterAnnouncement) \n MasterName=[S] \n " ,
308 data
= smb_fdata ( ndo
, data
,
309 "BROWSE PACKET: \n Type=[B] (ResetBrowser) \n Options=[B] \n " , maxbuf
, unicodestr
);
313 data
= smb_fdata ( ndo
, data
, "Unknown Browser Frame " , maxbuf
, unicodestr
);
318 ND_PRINT (( ndo
, "%s" , tstr
));
323 print_ipc ( netdissect_options
* ndo
,
324 const u_char
* param
, int paramlen
, const u_char
* data
, int datalen
)
327 smb_fdata ( ndo
, param
, "Command=[w] \n Str1=[S] \n Str2=[S] \n " , param
+ paramlen
,
330 smb_fdata ( ndo
, data
, "IPC " , data
+ datalen
, unicodestr
);
335 print_trans ( netdissect_options
* ndo
,
336 const u_char
* words
, const u_char
* data1
, const u_char
* buf
, const u_char
* maxbuf
)
339 const char * f1
, * f2
, * f3
, * f4
;
340 const u_char
* data
, * param
;
341 const u_char
* w
= words
+ 1 ;
342 int datalen
, paramlen
;
345 ND_TCHECK2 ( w
[ 12 * 2 ], 2 );
346 paramlen
= EXTRACT_LE_16BITS ( w
+ 9 * 2 );
347 param
= buf
+ EXTRACT_LE_16BITS ( w
+ 10 * 2 );
348 datalen
= EXTRACT_LE_16BITS ( w
+ 11 * 2 );
349 data
= buf
+ EXTRACT_LE_16BITS ( w
+ 12 * 2 );
350 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 " ;
355 ND_TCHECK2 ( w
[ 7 * 2 ], 2 );
356 paramlen
= EXTRACT_LE_16BITS ( w
+ 3 * 2 );
357 param
= buf
+ EXTRACT_LE_16BITS ( w
+ 4 * 2 );
358 datalen
= EXTRACT_LE_16BITS ( w
+ 6 * 2 );
359 data
= buf
+ EXTRACT_LE_16BITS ( w
+ 7 * 2 );
360 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 " ;
366 smb_fdata ( ndo
, words
+ 1 , f1
, min ( words
+ 1 + 2 * words
[ 0 ], maxbuf
),
369 ND_TCHECK2 (* data1
, 2 );
370 bcc
= EXTRACT_LE_16BITS ( data1
);
371 ND_PRINT (( ndo
, "smb_bcc=%u \n " , bcc
));
373 smb_fdata ( ndo
, data1
+ 2 , f2
, maxbuf
- ( paramlen
+ datalen
), unicodestr
);
374 #define MAILSLOT_BROWSE_STR " \\ MAILSLOT \\ BROWSE"
375 ND_TCHECK2 (*( data1
+ 2 ), strlen ( MAILSLOT_BROWSE_STR
) + 1 );
376 if ( strcmp (( const char *)( data1
+ 2 ), MAILSLOT_BROWSE_STR
) == 0 ) {
377 print_browse ( ndo
, param
, paramlen
, data
, datalen
);
380 #undef MAILSLOT_BROWSE_STR
382 #define PIPE_LANMAN_STR " \\ PIPE \\ LANMAN"
383 ND_TCHECK2 (*( data1
+ 2 ), strlen ( PIPE_LANMAN_STR
) + 1 );
384 if ( strcmp (( const char *)( data1
+ 2 ), PIPE_LANMAN_STR
) == 0 ) {
385 print_ipc ( ndo
, param
, paramlen
, data
, datalen
);
388 #undef PIPE_LANMAN_STR
391 smb_fdata ( ndo
, param
, f3
, min ( param
+ paramlen
, maxbuf
), unicodestr
);
393 smb_fdata ( ndo
, data
, f4
, min ( data
+ datalen
, maxbuf
), unicodestr
);
397 ND_PRINT (( ndo
, "%s" , tstr
));
402 print_negprot ( netdissect_options
* ndo
,
403 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
406 const char * f1
= NULL
, * f2
= NULL
;
411 f2
= "*|Dialect=[Y] \n " ;
414 f1
= "Core Protocol \n DialectIndex=[d]" ;
416 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=" ;
418 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=" ;
422 smb_fdata ( ndo
, words
+ 1 , f1
, min ( words
+ 1 + wct
* 2 , maxbuf
),
425 smb_print_data ( ndo
, words
+ 1 , min ( wct
* 2 , PTR_DIFF ( maxbuf
, words
+ 1 )));
427 ND_TCHECK2 (* data
, 2 );
428 bcc
= EXTRACT_LE_16BITS ( data
);
429 ND_PRINT (( ndo
, "smb_bcc=%u \n " , bcc
));
432 smb_fdata ( ndo
, data
+ 2 , f2
, min ( data
+ 2 + EXTRACT_LE_16BITS ( data
),
433 maxbuf
), unicodestr
);
435 smb_print_data ( ndo
, data
+ 2 , min ( EXTRACT_LE_16BITS ( data
), PTR_DIFF ( maxbuf
, data
+ 2 )));
439 ND_PRINT (( ndo
, "%s" , tstr
));
443 print_sesssetup ( netdissect_options
* ndo
,
444 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
447 const char * f1
= NULL
, * f2
= NULL
;
453 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 " ;
455 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 " ;
458 f1
= "Com2=[w] \n Off2=[d] \n Action=[w] \n " ;
459 } else if ( wct
== 13 ) {
460 f1
= "Com2=[B] \n Res=[B] \n Off2=[d] \n Action=[w] \n " ;
461 f2
= "NativeOS=[S] \n NativeLanMan=[S] \n PrimaryDomain=[S] \n " ;
466 smb_fdata ( ndo
, words
+ 1 , f1
, min ( words
+ 1 + wct
* 2 , maxbuf
),
469 smb_print_data ( ndo
, words
+ 1 , min ( wct
* 2 , PTR_DIFF ( maxbuf
, words
+ 1 )));
471 ND_TCHECK2 (* data
, 2 );
472 bcc
= EXTRACT_LE_16BITS ( data
);
473 ND_PRINT (( ndo
, "smb_bcc=%u \n " , bcc
));
476 smb_fdata ( ndo
, data
+ 2 , f2
, min ( data
+ 2 + EXTRACT_LE_16BITS ( data
),
477 maxbuf
), unicodestr
);
479 smb_print_data ( ndo
, data
+ 2 , min ( EXTRACT_LE_16BITS ( data
), PTR_DIFF ( maxbuf
, data
+ 2 )));
483 ND_PRINT (( ndo
, "%s" , tstr
));
487 print_lockingandx ( netdissect_options
* ndo
,
488 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
491 const u_char
* maxwords
;
492 const char * f1
= NULL
, * f2
= NULL
;
497 f1
= "Com2=[w] \n Off2=[d] \n Handle=[d] \n LockType=[w] \n TimeOut=[D] \n UnlockCount=[d] \n LockCount=[d] \n " ;
500 f2
= "*Process=[d] \n [P2]Offset=[M] \n Length=[M] \n " ;
502 f2
= "*Process=[d] \n Offset=[D] \n Length=[D] \n " ;
504 f1
= "Com2=[w] \n Off2=[d] \n " ;
507 maxwords
= min ( words
+ 1 + wct
* 2 , maxbuf
);
509 smb_fdata ( ndo
, words
+ 1 , f1
, maxwords
, unicodestr
);
511 ND_TCHECK2 (* data
, 2 );
512 bcc
= EXTRACT_LE_16BITS ( data
);
513 ND_PRINT (( ndo
, "smb_bcc=%u \n " , bcc
));
516 smb_fdata ( ndo
, data
+ 2 , f2
, min ( data
+ 2 + EXTRACT_LE_16BITS ( data
),
517 maxbuf
), unicodestr
);
519 smb_print_data ( ndo
, data
+ 2 , min ( EXTRACT_LE_16BITS ( data
), PTR_DIFF ( maxbuf
, data
+ 2 )));
523 ND_PRINT (( ndo
, "%s" , tstr
));
527 static const struct smbfns smb_fns
[] = {
528 { - 1 , "SMBunknown" , 0 , DEFDESCRIPT
},
530 { SMBtcon
, "SMBtcon" , 0 ,
531 { NULL
, "Path=[Z] \n Password=[Z] \n Device=[Z] \n " ,
532 "MaxXmit=[d] \n TreeId=[d] \n " , NULL
,
535 { SMBtdis
, "SMBtdis" , 0 , DEFDESCRIPT
},
536 { SMBexit
, "SMBexit" , 0 , DEFDESCRIPT
},
537 { SMBioctl
, "SMBioctl" , 0 , DEFDESCRIPT
},
539 { SMBecho
, "SMBecho" , 0 ,
540 { "ReverbCount=[d] \n " , NULL
,
541 "SequenceNum=[d] \n " , NULL
,
544 { SMBulogoffX
, "SMBulogoffX" , FLG_CHAIN
, DEFDESCRIPT
},
546 { SMBgetatr
, "SMBgetatr" , 0 ,
547 { NULL
, "Path=[Z] \n " ,
548 "Attribute=[A] \n Time=[T2]Size=[D] \n Res=([w,w,w,w,w]) \n " , NULL
,
551 { SMBsetatr
, "SMBsetatr" , 0 ,
552 { "Attribute=[A] \n Time=[T2]Res=([w,w,w,w,w]) \n " , "Path=[Z] \n " ,
553 NULL
, NULL
, NULL
} },
555 { SMBchkpth
, "SMBchkpth" , 0 ,
556 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
558 { SMBsearch
, "SMBsearch" , 0 ,
559 { "Count=[d] \n Attrib=[A] \n " ,
560 "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 " ,
562 "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 " ,
565 { SMBopen
, "SMBopen" , 0 ,
566 { "Mode=[w] \n Attribute=[A] \n " , "Path=[Z] \n " ,
567 "Handle=[d] \n OAttrib=[A] \n Time=[T2]Size=[D] \n Access=[w] \n " ,
570 { SMBcreate
, "SMBcreate" , 0 ,
571 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " , "Handle=[d] \n " , NULL
, NULL
} },
573 { SMBmknew
, "SMBmknew" , 0 ,
574 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " , "Handle=[d] \n " , NULL
, NULL
} },
576 { SMBunlink
, "SMBunlink" , 0 ,
577 { "Attrib=[A] \n " , "Path=[Z] \n " , NULL
, NULL
, NULL
} },
579 { SMBread
, "SMBread" , 0 ,
580 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
581 "Count=[d] \n Res=([w,w,w,w]) \n " , NULL
, NULL
} },
583 { SMBwrite
, "SMBwrite" , 0 ,
584 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
585 "Count=[d] \n " , NULL
, NULL
} },
587 { SMBclose
, "SMBclose" , 0 ,
588 { "Handle=[d] \n Time=[T2]" , NULL
, NULL
, NULL
, NULL
} },
590 { SMBmkdir
, "SMBmkdir" , 0 ,
591 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
593 { SMBrmdir
, "SMBrmdir" , 0 ,
594 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
596 { SMBdskattr
, "SMBdskattr" , 0 ,
598 "TotalUnits=[d] \n BlocksPerUnit=[d] \n BlockSize=[d] \n FreeUnits=[d] \n Media=[w] \n " ,
602 { "Attrib=[A] \n " , "OldPath=[Z] \n NewPath=[Z] \n " , NULL
, NULL
, NULL
} },
605 * this is a Pathworks specific call, allowing the
606 * changing of the root path
608 { pSETDIR
, "SMBsetdir" , 0 , { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
610 { SMBlseek
, "SMBlseek" , 0 ,
611 { "Handle=[d] \n Mode=[w] \n Offset=[D] \n " , "Offset=[D] \n " , NULL
, NULL
, NULL
} },
613 { SMBflush
, "SMBflush" , 0 , { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
615 { SMBsplopen
, "SMBsplopen" , 0 ,
616 { "SetupLen=[d] \n Mode=[w] \n " , "Ident=[Z] \n " , "Handle=[d] \n " ,
619 { SMBsplclose
, "SMBsplclose" , 0 ,
620 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
622 { SMBsplretq
, "SMBsplretq" , 0 ,
623 { "MaxCount=[d] \n StartIndex=[d] \n " , NULL
,
624 "Count=[d] \n Index=[d] \n " ,
625 "*Time=[T2]Status=[B] \n JobID=[d] \n Size=[D] \n Res=[B]Name=[s16] \n " ,
628 { SMBsplwr
, "SMBsplwr" , 0 ,
629 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
631 { SMBlock
, "SMBlock" , 0 ,
632 { "Handle=[d] \n Count=[D] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
} },
634 { SMBunlock
, "SMBunlock" , 0 ,
635 { "Handle=[d] \n Count=[D] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
} },
637 /* CORE+ PROTOCOL FOLLOWS */
639 { SMBreadbraw
, "SMBreadbraw" , 0 ,
640 { "Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n Res=[d] \n " ,
641 NULL
, NULL
, NULL
, NULL
} },
643 { SMBwritebraw
, "SMBwritebraw" , 0 ,
644 { "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 " ,
645 NULL
, "WriteRawAck" , NULL
, NULL
} },
647 { SMBwritec
, "SMBwritec" , 0 ,
648 { NULL
, NULL
, "Count=[d] \n " , NULL
, NULL
} },
650 { SMBwriteclose
, "SMBwriteclose" , 0 ,
651 { "Handle=[d] \n Count=[d] \n Offset=[D] \n Time=[T2]Res=([w,w,w,w,w,w])" ,
652 NULL
, "Count=[d] \n " , NULL
, NULL
} },
654 { SMBlockread
, "SMBlockread" , 0 ,
655 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
656 "Count=[d] \n Res=([w,w,w,w]) \n " , NULL
, NULL
} },
658 { SMBwriteunlock
, "SMBwriteunlock" , 0 ,
659 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
660 "Count=[d] \n " , NULL
, NULL
} },
662 { SMBreadBmpx
, "SMBreadBmpx" , 0 ,
663 { "Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n Res=[w] \n " ,
665 "Offset=[D] \n TotCount=[d] \n Remaining=[d] \n Res=([w,w]) \n DataSize=[d] \n DataOff=[d] \n " ,
668 { SMBwriteBmpx
, "SMBwriteBmpx" , 0 ,
669 { "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
,
670 "Remaining=[d] \n " , NULL
, NULL
} },
672 { SMBwriteBs
, "SMBwriteBs" , 0 ,
673 { "Handle=[d] \n TotCount=[d] \n Offset=[D] \n Res=[W] \n DataSize=[d] \n DataOff=[d] \n " ,
674 NULL
, "Count=[d] \n " , NULL
, NULL
} },
676 { SMBsetattrE
, "SMBsetattrE" , 0 ,
677 { "Handle=[d] \n CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]" , NULL
,
678 NULL
, NULL
, NULL
} },
680 { SMBgetattrE
, "SMBgetattrE" , 0 ,
681 { "Handle=[d] \n " , NULL
,
682 "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D] \n AllocSize=[D] \n Attribute=[A] \n " ,
685 { SMBtranss
, "SMBtranss" , 0 , DEFDESCRIPT
},
686 { SMBioctls
, "SMBioctls" , 0 , DEFDESCRIPT
},
688 { SMBcopy
, "SMBcopy" , 0 ,
689 { "TreeID2=[d] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
690 "CopyCount=[d] \n " , "|ErrStr=[S] \n " , NULL
} },
692 { SMBmove
, "SMBmove" , 0 ,
693 { "TreeID2=[d] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
694 "MoveCount=[d] \n " , "|ErrStr=[S] \n " , NULL
} },
696 { SMBopenX
, "SMBopenX" , FLG_CHAIN
,
697 { "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 " ,
699 "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 " ,
702 { SMBreadX
, "SMBreadX" , FLG_CHAIN
,
703 { "Com2=[w] \n Off2=[d] \n Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n CountLeft=[d] \n " ,
705 "Com2=[w] \n Off2=[d] \n Remaining=[d] \n Res=[W] \n DataSize=[d] \n DataOff=[d] \n Res=([w,w,w,w]) \n " ,
708 { SMBwriteX
, "SMBwriteX" , FLG_CHAIN
,
709 { "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 " ,
711 "Com2=[w] \n Off2=[d] \n Count=[d] \n Remaining=[d] \n Res=[W] \n " ,
714 { SMBffirst
, "SMBffirst" , 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 { SMBfunique
, "SMBfunique" , 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 { SMBfclose
, "SMBfclose" , 0 ,
729 { "Count=[d] \n Attrib=[A] \n " ,
730 "Path=[Z] \n BlkType=[B] \n BlkLen=[d] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n " ,
732 "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 " ,
735 { SMBfindnclose
, "SMBfindnclose" , 0 ,
736 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
738 { SMBfindclose
, "SMBfindclose" , 0 ,
739 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
741 { SMBsends
, "SMBsends" , 0 ,
742 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
} },
744 { SMBsendstrt
, "SMBsendstrt" , 0 ,
745 { NULL
, "Source=[Z] \n Dest=[Z] \n " , "GroupID=[d] \n " , NULL
, NULL
} },
747 { SMBsendend
, "SMBsendend" , 0 ,
748 { "GroupID=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
750 { SMBsendtxt
, "SMBsendtxt" , 0 ,
751 { "GroupID=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
753 { SMBsendb
, "SMBsendb" , 0 ,
754 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
} },
756 { SMBfwdname
, "SMBfwdname" , 0 , DEFDESCRIPT
},
757 { SMBcancelf
, "SMBcancelf" , 0 , DEFDESCRIPT
},
758 { SMBgetmac
, "SMBgetmac" , 0 , DEFDESCRIPT
},
760 { SMBnegprot
, "SMBnegprot" , 0 ,
761 { NULL
, NULL
, NULL
, NULL
, print_negprot
} },
763 { SMBsesssetupX
, "SMBsesssetupX" , FLG_CHAIN
,
764 { NULL
, NULL
, NULL
, NULL
, print_sesssetup
} },
766 { SMBtconX
, "SMBtconX" , FLG_CHAIN
,
767 { "Com2=[w] \n Off2=[d] \n Flags=[w] \n PassLen=[d] \n Passwd&Path&Device= \n " ,
768 NULL
, "Com2=[w] \n Off2=[d] \n " , "ServiceType=[R] \n " , NULL
} },
770 { SMBlockingX
, "SMBlockingX" , FLG_CHAIN
,
771 { NULL
, NULL
, NULL
, NULL
, print_lockingandx
} },
773 { SMBtrans2
, "SMBtrans2" , 0 , { NULL
, NULL
, NULL
, NULL
, print_trans2
} },
775 { SMBtranss2
, "SMBtranss2" , 0 , DEFDESCRIPT
},
776 { SMBctemp
, "SMBctemp" , 0 , DEFDESCRIPT
},
777 { SMBreadBs
, "SMBreadBs" , 0 , DEFDESCRIPT
},
778 { SMBtrans
, "SMBtrans" , 0 , { NULL
, NULL
, NULL
, NULL
, print_trans
} },
780 { SMBnttrans
, "SMBnttrans" , 0 , DEFDESCRIPT
},
781 { SMBnttranss
, "SMBnttranss" , 0 , DEFDESCRIPT
},
783 { SMBntcreateX
, "SMBntcreateX" , FLG_CHAIN
,
784 { "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 " ,
786 "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 " ,
789 { SMBntcancel
, "SMBntcancel" , 0 , DEFDESCRIPT
},
791 { - 1 , NULL
, 0 , DEFDESCRIPT
}
796 * print a SMB message
799 print_smb ( netdissect_options
* ndo
,
800 const u_char
* buf
, const u_char
* maxbuf
)
806 const u_char
* words
, * maxwords
, * data
;
807 const struct smbfns
* fn
;
808 const char * fmt_smbheader
=
809 "[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 " ;
813 request
= ( buf
[ 9 ] & 0x80 ) ? 0 : 1 ;
818 fn
= smbfind ( command
, smb_fns
);
820 if ( ndo
-> ndo_vflag
> 1 )
821 ND_PRINT (( ndo
, " \n " ));
823 ND_PRINT (( ndo
, "SMB PACKET: %s (%s) \n " , fn
-> name
, request
? "REQUEST" : "REPLY" ));
825 if ( ndo
-> ndo_vflag
< 2 )
828 ND_TCHECK_16BITS (& buf
[ 10 ]);
829 flags2
= EXTRACT_LE_16BITS (& buf
[ 10 ]);
830 unicodestr
= flags2
& 0x8000 ;
831 nterrcodes
= flags2
& 0x4000 ;
833 /* print out the header */
834 smb_fdata ( ndo
, buf
, fmt_smbheader
, buf
+ 33 , unicodestr
);
837 nterror
= EXTRACT_LE_32BITS (& buf
[ 5 ]);
839 ND_PRINT (( ndo
, "NTError = %s \n " , nt_errstr ( nterror
)));
842 ND_PRINT (( ndo
, "SMBError = %s \n " , smb_errstr ( buf
[ 5 ], EXTRACT_LE_16BITS (& buf
[ 7 ]))));
853 words
= buf
+ smboffset
;
856 data
= words
+ 1 + wct
* 2 ;
857 maxwords
= min ( data
, maxbuf
);
860 f1
= fn
-> descript
. req_f1
;
861 f2
= fn
-> descript
. req_f2
;
863 f1
= fn
-> descript
. rep_f1
;
864 f2
= fn
-> descript
. rep_f2
;
868 (* fn
-> descript
. fn
)( ndo
, words
, data
, buf
, maxbuf
);
872 smb_fdata ( ndo
, words
+ 1 , f1
, words
+ 1 + wct
* 2 , unicodestr
);
877 for ( i
= 0 ; & words
[ 1 + 2 * i
] < maxwords
; i
++) {
878 ND_TCHECK2 ( words
[ 1 + 2 * i
], 2 );
879 v
= EXTRACT_LE_16BITS ( words
+ 1 + 2 * i
);
880 ND_PRINT (( ndo
, "smb_vwv[%d]=%d (0x%X) \n " , i
, v
, v
));
885 ND_TCHECK2 (* data
, 2 );
886 bcc
= EXTRACT_LE_16BITS ( data
);
887 ND_PRINT (( ndo
, "smb_bcc=%u \n " , bcc
));
890 smb_fdata ( ndo
, data
+ 2 , f2
, data
+ 2 + bcc
, unicodestr
);
893 ND_PRINT (( ndo
, "smb_buf[]= \n " ));
894 smb_print_data ( ndo
, data
+ 2 , min ( bcc
, PTR_DIFF ( maxbuf
, data
+ 2 )));
899 if (( fn
-> flags
& FLG_CHAIN
) == 0 )
907 ND_TCHECK2 ( words
[ 3 ], 2 );
908 newsmboffset
= EXTRACT_LE_16BITS ( words
+ 3 );
910 fn
= smbfind ( command
, smb_fns
);
912 ND_PRINT (( ndo
, " \n SMB PACKET: %s (%s) (CHAINED) \n " ,
913 fn
-> name
, request
? "REQUEST" : "REPLY" ));
914 if ( newsmboffset
<= smboffset
) {
915 ND_PRINT (( ndo
, "Bad andX offset: %u <= %u \n " , newsmboffset
, smboffset
));
918 smboffset
= newsmboffset
;
921 ND_PRINT (( ndo
, " \n " ));
924 ND_PRINT (( ndo
, "%s" , tstr
));
929 * print a NBT packet received across tcp on port 139
932 nbt_tcp_print ( netdissect_options
* ndo
,
933 const u_char
* data
, int length
)
938 const u_char
* maxbuf
;
942 if ( ndo
-> ndo_snapend
< data
)
944 caplen
= ndo
-> ndo_snapend
- data
;
947 maxbuf
= data
+ caplen
;
948 ND_TCHECK_8BITS ( data
);
950 ND_TCHECK_16BITS ( data
+ 2 );
951 nbt_len
= EXTRACT_16BITS ( data
+ 2 );
957 if ( ndo
-> ndo_vflag
< 2 ) {
958 ND_PRINT (( ndo
, " NBT Session Packet: " ));
961 ND_PRINT (( ndo
, "Session Message" ));
965 ND_PRINT (( ndo
, "Session Request" ));
969 ND_PRINT (( ndo
, "Session Granted" ));
984 ND_PRINT (( ndo
, "Session Reject, " ));
987 ND_PRINT (( ndo
, "Not listening on called name" ));
990 ND_PRINT (( ndo
, "Not listening for calling name" ));
993 ND_PRINT (( ndo
, "Called name not present" ));
996 ND_PRINT (( ndo
, "Called name present, but insufficient resources" ));
999 ND_PRINT (( ndo
, "Unspecified error 0x%X" , ecode
));
1006 ND_PRINT (( ndo
, "Session Keepalive" ));
1010 data
= smb_fdata ( ndo
, data
, "Unknown packet type [rB]" , maxbuf
, 0 );
1014 ND_PRINT (( ndo
, " \n >>> NBT Session Packet \n " ));
1017 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Message \n Flags=[B] \n Length=[rd] \n " ,
1021 if ( nbt_len
>= 4 && caplen
>= 4 && memcmp ( data
, " \377 SMB" , 4 ) == 0 ) {
1022 if (( int ) nbt_len
> caplen
) {
1023 if (( int ) nbt_len
> length
)
1024 ND_PRINT (( ndo
, "WARNING: Packet is continued in later TCP segments \n " ));
1026 ND_PRINT (( ndo
, "WARNING: Short packet. Try increasing the snap length by %d \n " ,
1029 print_smb ( ndo
, data
, maxbuf
> data
+ nbt_len
? data
+ nbt_len
: maxbuf
);
1031 ND_PRINT (( ndo
, "Session packet:(raw data or continuation?) \n " ));
1035 data
= smb_fdata ( ndo
, data
,
1036 "[P1]NBT Session Request \n Flags=[B] \n Length=[rd] \n Destination=[n1] \n Source=[n1] \n " ,
1041 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Granted \n Flags=[B] \n Length=[rd] \n " , maxbuf
, 0 );
1046 const u_char
* origdata
;
1050 data
= smb_fdata ( ndo
, data
, "[P1]NBT SessionReject \n Flags=[B] \n Length=[rd] \n Reason=[B] \n " ,
1054 if ( nbt_len
>= 1 && caplen
>= 1 ) {
1055 ecode
= origdata
[ 4 ];
1058 ND_PRINT (( ndo
, "Not listening on called name \n " ));
1061 ND_PRINT (( ndo
, "Not listening for calling name \n " ));
1064 ND_PRINT (( ndo
, "Called name not present \n " ));
1067 ND_PRINT (( ndo
, "Called name present, but insufficient resources \n " ));
1070 ND_PRINT (( ndo
, "Unspecified error 0x%X \n " , ecode
));
1078 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Keepalive \n Flags=[B] \n Length=[rd] \n " , maxbuf
, 0 );
1082 data
= smb_fdata ( ndo
, data
, "NBT - Unknown packet type \n Type=[B] \n " , maxbuf
, 0 );
1085 ND_PRINT (( ndo
, " \n " ));
1089 ND_PRINT (( ndo
, "%s" , tstr
));
1092 static const struct tok opcode_str
[] = {
1094 { 5 , "REGISTRATION" },
1097 { 8 , "REFRESH(8)" },
1099 { 15 , "MULTIHOMED REGISTRATION" },
1104 * print a NBT packet received across udp on port 137
1107 nbt_udp137_print ( netdissect_options
* ndo
,
1108 const u_char
* data
, int length
)
1110 const u_char
* maxbuf
= data
+ length
;
1111 int name_trn_id
, response
, opcode
, nm_flags
, rcode
;
1112 int qdcount
, ancount
, nscount
, arcount
;
1116 ND_TCHECK2 ( data
[ 10 ], 2 );
1117 name_trn_id
= EXTRACT_16BITS ( data
);
1118 response
= ( data
[ 2 ] >> 7 );
1119 opcode
= ( data
[ 2 ] >> 3 ) & 0xF ;
1120 nm_flags
= (( data
[ 2 ] & 0x7 ) << 4 ) + ( data
[ 3 ] >> 4 );
1121 rcode
= data
[ 3 ] & 0xF ;
1122 qdcount
= EXTRACT_16BITS ( data
+ 4 );
1123 ancount
= EXTRACT_16BITS ( data
+ 6 );
1124 nscount
= EXTRACT_16BITS ( data
+ 8 );
1125 arcount
= EXTRACT_16BITS ( data
+ 10 );
1131 if ( ndo
-> ndo_vflag
> 1 )
1132 ND_PRINT (( ndo
, " \n >>> " ));
1134 ND_PRINT (( ndo
, "NBT UDP PACKET(137): %s" , tok2str ( opcode_str
, "OPUNKNOWN" , opcode
)));
1136 ND_PRINT (( ndo
, "; %s" , rcode
? "NEGATIVE" : "POSITIVE" ));
1138 ND_PRINT (( ndo
, "; %s; %s" , response
? "RESPONSE" : "REQUEST" ,
1139 ( nm_flags
& 1 ) ? "BROADCAST" : "UNICAST" ));
1141 if ( ndo
-> ndo_vflag
< 2 )
1144 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 " ,
1145 name_trn_id
, opcode
, nm_flags
, rcode
, qdcount
, ancount
, nscount
,
1150 total
= ancount
+ nscount
+ arcount
;
1152 if ( qdcount
> 100 || total
> 100 ) {
1153 ND_PRINT (( ndo
, "Corrupt packet?? \n " ));
1158 ND_PRINT (( ndo
, "QuestionRecords: \n " ));
1159 for ( i
= 0 ; i
< qdcount
; i
++) {
1160 p
= smb_fdata ( ndo
, p
,
1161 "|Name=[n1] \n QuestionType=[rw] \n QuestionClass=[rw] \n #" ,
1169 ND_PRINT (( ndo
, " \n ResourceRecords: \n " ));
1170 for ( i
= 0 ; i
< total
; i
++) {
1174 p
= smb_fdata ( ndo
, p
, "Name=[n1] \n #" , maxbuf
, 0 );
1177 ND_TCHECK_16BITS ( p
);
1178 restype
= EXTRACT_16BITS ( p
);
1179 p
= smb_fdata ( ndo
, p
, "ResType=[rw] \n ResClass=[rw] \n TTL=[rD] \n " , p
+ 8 , 0 );
1182 ND_TCHECK_16BITS ( p
);
1183 rdlen
= EXTRACT_16BITS ( p
);
1184 ND_PRINT (( ndo
, "ResourceLength=%d \n ResourceData= \n " , rdlen
));
1187 p
= smb_fdata ( ndo
, p
, "AddrType=[rw] \n Address=[b.b.b.b] \n " , p
+ rdlen
, 0 );
1191 if ( restype
== 0x21 ) {
1196 p
= smb_fdata ( ndo
, p
, "NumNames=[B] \n " , p
+ 1 , 0 );
1199 while ( numnames
--) {
1200 p
= smb_fdata ( ndo
, p
, "Name=[n2] \t #" , maxbuf
, 0 );
1205 ND_PRINT (( ndo
, "<GROUP> " ));
1206 switch ( p
[ 0 ] & 0x60 ) {
1207 case 0x00 : ND_PRINT (( ndo
, "B " )); break ;
1208 case 0x20 : ND_PRINT (( ndo
, "P " )); break ;
1209 case 0x40 : ND_PRINT (( ndo
, "M " )); break ;
1210 case 0x60 : ND_PRINT (( ndo
, "_ " )); break ;
1213 ND_PRINT (( ndo
, "<DEREGISTERING> " ));
1215 ND_PRINT (( ndo
, "<CONFLICT> " ));
1217 ND_PRINT (( ndo
, "<ACTIVE> " ));
1219 ND_PRINT (( ndo
, "<PERMANENT> " ));
1220 ND_PRINT (( ndo
, " \n " ));
1224 smb_print_data ( ndo
, p
, min ( rdlen
, length
- ( p
- data
)));
1232 smb_fdata ( ndo
, p
, "AdditionalData: \n " , maxbuf
, 0 );
1235 ND_PRINT (( ndo
, " \n " ));
1238 ND_PRINT (( ndo
, "%s" , tstr
));
1242 * Print an SMB-over-TCP packet received across tcp on port 445
1245 smb_tcp_print ( netdissect_options
* ndo
,
1246 const u_char
* data
, int length
)
1250 const u_char
* maxbuf
;
1254 if ( ndo
-> ndo_snapend
< data
)
1256 caplen
= ndo
-> ndo_snapend
- data
;
1259 maxbuf
= data
+ caplen
;
1260 smb_len
= EXTRACT_24BITS ( data
+ 1 );
1267 if ( smb_len
>= 4 && caplen
>= 4 && memcmp ( data
, " \377 SMB" , 4 ) == 0 ) {
1268 if (( int ) smb_len
> caplen
) {
1269 if (( int ) smb_len
> length
)
1270 ND_PRINT (( ndo
, " WARNING: Packet is continued in later TCP segments \n " ));
1272 ND_PRINT (( ndo
, " WARNING: Short packet. Try increasing the snap length by %d \n " ,
1275 ND_PRINT (( ndo
, " " ));
1276 print_smb ( ndo
, data
, maxbuf
> data
+ smb_len
? data
+ smb_len
: maxbuf
);
1278 ND_PRINT (( ndo
, " SMB-over-TCP packet:(raw data or continuation?) \n " ));
1281 ND_PRINT (( ndo
, "%s" , tstr
));
1285 * print a NBT packet received across udp on port 138
1288 nbt_udp138_print ( netdissect_options
* ndo
,
1289 const u_char
* data
, int length
)
1291 const u_char
* maxbuf
= data
+ length
;
1293 if ( maxbuf
> ndo
-> ndo_snapend
)
1294 maxbuf
= ndo
-> ndo_snapend
;
1299 if ( ndo
-> ndo_vflag
< 2 ) {
1300 ND_PRINT (( ndo
, "NBT UDP PACKET(138)" ));
1304 data
= smb_fdata ( ndo
, data
,
1305 " \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 #" ,
1309 /* If there isn't enough data for "\377SMB", don't check for it. */
1310 if (& data
[ 3 ] >= maxbuf
)
1313 if ( memcmp ( data
, " \377 SMB" , 4 ) == 0 )
1314 print_smb ( ndo
, data
, maxbuf
);
1317 ND_PRINT (( ndo
, " \n " ));
1322 print netbeui frames
1324 static struct nbf_strings
{
1326 const char * nonverbose
;
1327 const char * verbose
;
1328 } nbf_strings
[ 0x20 ] = {
1329 { "Add Group Name Query" , ", [P23]Name to add=[n2]#" ,
1330 "[P5]ResponseCorrelator=[w] \n [P16]Name to add=[n2] \n " },
1331 { "Add Name Query" , ", [P23]Name to add=[n2]#" ,
1332 "[P5]ResponseCorrelator=[w] \n [P16]Name to add=[n2] \n " },
1333 { "Name In Conflict" , NULL
, NULL
},
1334 { "Status Query" , NULL
, NULL
},
1335 { NULL
, NULL
, NULL
}, /* not used */
1336 { NULL
, NULL
, NULL
}, /* not used */
1337 { NULL
, NULL
, NULL
}, /* not used */
1338 { "Terminate Trace" , NULL
, NULL
},
1340 "[P7]Destination=[n2] \n Source=[n2] \n " },
1341 { "Broadcast Datagram" , NULL
,
1342 "[P7]Destination=[n2] \n Source=[n2] \n " },
1343 { "Name Query" , ", [P7]Name=[n2]#" ,
1344 "[P1]SessionNumber=[B] \n NameType=[B][P2] \n ResponseCorrelator=[w] \n Name=[n2] \n Name of sender=[n2] \n " },
1345 { NULL
, NULL
, NULL
}, /* not used */
1346 { NULL
, NULL
, NULL
}, /* not used */
1347 { "Add Name Response" , ", [P1]GroupName=[w] [P4]Destination=[n2] Source=[n2]#" ,
1348 "AddNameInProcess=[B] \n GroupName=[w] \n TransmitCorrelator=[w][P2] \n Destination=[n2] \n Source=[n2] \n " },
1349 { "Name Recognized" , NULL
,
1350 "[P1]Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n Destination=[n2] \n Source=[n2] \n " },
1351 { "Status Response" , NULL
, NULL
},
1352 { NULL
, NULL
, NULL
}, /* not used */
1353 { NULL
, NULL
, NULL
}, /* not used */
1354 { NULL
, NULL
, NULL
}, /* not used */
1355 { "Terminate Trace" , NULL
, NULL
},
1357 "[P3]TransmitCorrelator=[w][P2] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1358 { "Data First/Middle" , NULL
,
1359 "Flags=[{RECEIVE_CONTINUE|NO_ACK||PIGGYBACK_ACK_INCLUDED|}] \n ResyncIndicator=[w][P2] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1360 { "Data Only/Last" , NULL
,
1361 "Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}] \n ResyncIndicator=[w][P2] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1362 { "Session Confirm" , NULL
,
1363 "Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1364 { "Session End" , NULL
,
1365 "[P1]Data2=[w][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1366 { "Session Initialize" , NULL
,
1367 "Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1368 { "No Receive" , NULL
,
1369 "Flags=[{|SEND_NO_ACK}] \n DataBytesAccepted=[b][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1370 { "Receive Outstanding" , NULL
,
1371 "[P1]DataBytesAccepted=[b][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1372 { "Receive Continue" , NULL
,
1373 "[P2]TransmitCorrelator=[w] \n [P2]RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1374 { NULL
, NULL
, NULL
}, /* not used */
1375 { NULL
, NULL
, NULL
}, /* not used */
1376 { "Session Alive" , NULL
, NULL
}
1380 netbeui_print ( netdissect_options
* ndo
,
1381 u_short control
, const u_char
* data
, int length
)
1383 const u_char
* maxbuf
= data
+ length
;
1386 const u_char
* data2
;
1387 int is_truncated
= 0 ;
1389 if ( maxbuf
> ndo
-> ndo_snapend
)
1390 maxbuf
= ndo
-> ndo_snapend
;
1392 len
= EXTRACT_LE_16BITS ( data
);
1395 if ( data2
>= maxbuf
) {
1402 if ( ndo
-> ndo_vflag
< 2 ) {
1403 ND_PRINT (( ndo
, "NBF Packet: " ));
1404 data
= smb_fdata ( ndo
, data
, "[P5]#" , maxbuf
, 0 );
1406 ND_PRINT (( ndo
, " \n >>> NBF Packet \n Type=0x%X " , control
));
1407 data
= smb_fdata ( ndo
, data
, "Length=[d] Signature=[w] Command=[B] \n #" , maxbuf
, 0 );
1412 if ( command
> 0x1f || nbf_strings
[ command
]. name
== NULL
) {
1413 if ( ndo
-> ndo_vflag
< 2 )
1414 data
= smb_fdata ( ndo
, data
, "Unknown NBF Command#" , data2
, 0 );
1416 data
= smb_fdata ( ndo
, data
, "Unknown NBF Command \n " , data2
, 0 );
1418 if ( ndo
-> ndo_vflag
< 2 ) {
1419 ND_PRINT (( ndo
, "%s" , nbf_strings
[ command
]. name
));
1420 if ( nbf_strings
[ command
]. nonverbose
!= NULL
)
1421 data
= smb_fdata ( ndo
, data
, nbf_strings
[ command
]. nonverbose
, data2
, 0 );
1423 ND_PRINT (( ndo
, "%s: \n " , nbf_strings
[ command
]. name
));
1424 if ( nbf_strings
[ command
]. verbose
!= NULL
)
1425 data
= smb_fdata ( ndo
, data
, nbf_strings
[ command
]. verbose
, data2
, 0 );
1427 ND_PRINT (( ndo
, " \n " ));
1431 if ( ndo
-> ndo_vflag
< 2 )
1438 /* data2 was past the end of the buffer */
1442 /* If this isn't a command that would contain an SMB message, quit. */
1443 if ( command
!= 0x08 && command
!= 0x09 && command
!= 0x15 &&
1447 /* If there isn't enough data for "\377SMB", don't look for it. */
1448 if (& data2
[ 3 ] >= maxbuf
)
1451 if ( memcmp ( data2
, " \377 SMB" , 4 ) == 0 )
1452 print_smb ( ndo
, data2
, maxbuf
);
1455 for ( i
= 0 ; i
< 128 ; i
++) {
1456 if (& data2
[ i
+ 3 ] >= maxbuf
)
1458 if ( memcmp (& data2
[ i
], " \377 SMB" , 4 ) == 0 ) {
1459 ND_PRINT (( ndo
, "found SMB packet at %d \n " , i
));
1460 print_smb ( ndo
, & data2
[ i
], maxbuf
);
1467 ND_PRINT (( ndo
, " \n " ));
1470 ND_PRINT (( ndo
, "%s" , tstr
));
1475 * print IPX-Netbios frames
1478 ipx_netbios_print ( netdissect_options
* ndo
,
1479 const u_char
* data
, u_int length
)
1482 * this is a hack till I work out how to parse the rest of the
1483 * NetBIOS-over-IPX stuff
1486 const u_char
* maxbuf
;
1488 maxbuf
= data
+ length
;
1489 /* Don't go past the end of the captured data in the packet. */
1490 if ( maxbuf
> ndo
-> ndo_snapend
)
1491 maxbuf
= ndo
-> ndo_snapend
;
1493 for ( i
= 0 ; i
< 128 ; i
++) {
1494 if (& data
[ i
+ 4 ] > maxbuf
)
1496 if ( memcmp (& data
[ i
], " \377 SMB" , 4 ) == 0 ) {
1497 smb_fdata ( ndo
, data
, " \n >>> IPX transport " , & data
[ i
], 0 );
1498 print_smb ( ndo
, & data
[ i
], maxbuf
);
1499 ND_PRINT (( ndo
, " \n " ));
1504 smb_fdata ( ndo
, data
, " \n >>> Unknown IPX " , maxbuf
, 0 );