#ifndef _NETSMB_SMB_H_
#define _NETSMB_SMB_H_
#define SMB_TCP_PORT 139
enum smb_dialects {
SMB_DIALECT_NONE,
SMB_DIALECT_CORE,
SMB_DIALECT_COREPLUS,
SMB_DIALECT_LANMAN1_0,
SMB_DIALECT_LANMAN2_0,
SMB_DIALECT_LANMAN2_1,
SMB_DIALECT_NTLM0_12
};
#define SMB_DT_DATA 1
#define SMB_DT_DIALECT 2
#define SMB_DT_PATHNAME 3
#define SMB_DT_ASCII 4
#define SMB_DT_VARIABLE 5
#define SMB_SIGNATURE "\xFFSMB"
#define SMB_SIGLEN 4
#define SMB_HDRMID(p) (le16toh(*(u_short*)((u_char*)(p) + 30)))
#define SMB_HDRLEN 32
#define SMB_FLAGS_CASELESS 0x08
#define SMB_FLAGS_SERVER_RESP 0x80
#define SMB_FLAGS2_KNOWS_LONG_NAMES 0x0001
#define SMB_FLAGS2_KNOWS_EAS 0x0002
#define SMB_FLAGS2_SECURITY_SIGNATURE 0x0004
#define SMB_FLAGS2_IS_LONG_NAME 0x0040
#define SMB_FLAGS2_EXT_SEC 0x0800
#define SMB_FLAGS2_DFS 0x1000
#define SMB_FLAGS2_PAGING_IO 0x2000
#define SMB_FLAGS2_ERR_STATUS 0x4000
#define SMB_FLAGS2_UNICODE 0x8000
#define SMB_UID_UNKNOWN 0xffff
#define SMB_TID_UNKNOWN 0xffff
#define SMB_SM_USER 0x01
#define SMB_SM_ENCRYPT 0x02
#define SMB_SM_SIGS 0x04
#define SMB_SM_SIGS_REQUIRE 0x08
#define SMB_CAP_RAW_MODE 0x0001
#define SMB_CAP_MPX_MODE 0x0002
#define SMB_CAP_UNICODE 0x0004
#define SMB_CAP_LARGE_FILES 0x0008
#define SMB_CAP_NT_SMBS 0x0010
#define SMB_CAP_RPC_REMOTE_APIS 0x0020
#define SMB_CAP_STATUS32 0x0040
#define SMB_CAP_LEVEL_II_OPLOCKS 0x0080
#define SMB_CAP_LOCK_AND_READ 0x0100
#define SMB_CAP_NT_FIND 0x0200
#define SMB_CAP_DFS 0x1000
#define SMB_CAP_INFOLEVEL_PASSTHRU 0x2000
#define SMB_CAP_LARGE_READX 0x4000
#define SMB_CAP_LARGE_WRITEX 0x8000
#define SMB_CAP_UNIX 0x00800000
#define SMB_CAP_BULK_TRANSFER 0x20000000
#define SMB_CAP_COMPRESSED_DATA 0x40000000
#define SMB_CAP_EXT_SECURITY 0x80000000
#define SMB_FA_RDONLY 0x01
#define SMB_FA_HIDDEN 0x02
#define SMB_FA_SYSTEM 0x04
#define SMB_FA_VOLUME 0x08
#define SMB_FA_DIR 0x10
#define SMB_FA_ARCHIVE 0x20
#define SMB_EFA_RDONLY 0x0001
#define SMB_EFA_HIDDEN 0x0002
#define SMB_EFA_SYSTEM 0x0004
#define SMB_EFA_DIRECTORY 0x0010
#define SMB_EFA_ARCHIVE 0x0020
#define SMB_EFA_NORMAL 0x0080
#define SMB_EFA_TEMPORARY 0x0100
#define SMB_EFA_COMPRESSED 0x0800
#define SMB_EFA_POSIX_SEMANTICS 0x01000000
#define SMB_EFA_BACKUP_SEMANTICS 0x02000000
#define SMB_EFA_DELETE_ON_CLOSE 0x04000000
#define SMB_EFA_SEQUENTIAL_SCAN 0x08000000
#define SMB_EFA_RANDOM_ACCESS 0x10000000
#define SMB_EFA_NO_BUFFERING 0x20000000
#define SMB_EFA_WRITE_THROUGH 0x80000000
#define SMB_AM_OPENREAD 0x0000
#define SMB_AM_OPENWRITE 0x0001
#define SMB_AM_OPENRW 0x0002
#define SMB_AM_OPENEXEC 0x0003
#define SMB_SM_COMPAT 0x0000
#define SMB_SM_EXCLUSIVE 0x0010
#define SMB_SM_DENYWRITE 0x0020
#define SMB_SM_DENYREADEXEC 0x0030
#define SMB_SM_DENYNONE 0x0040
#define SMB_COM_CREATE_DIRECTORY 0x00
#define SMB_COM_DELETE_DIRECTORY 0x01
#define SMB_COM_OPEN 0x02
#define SMB_COM_CREATE 0x03
#define SMB_COM_CLOSE 0x04
#define SMB_COM_FLUSH 0x05
#define SMB_COM_DELETE 0x06
#define SMB_COM_RENAME 0x07
#define SMB_COM_QUERY_INFORMATION 0x08
#define SMB_COM_SET_INFORMATION 0x09
#define SMB_COM_READ 0x0A
#define SMB_COM_WRITE 0x0B
#define SMB_COM_LOCK_BYTE_RANGE 0x0C
#define SMB_COM_UNLOCK_BYTE_RANGE 0x0D
#define SMB_COM_CREATE_TEMPORARY 0x0E
#define SMB_COM_CREATE_NEW 0x0F
#define SMB_COM_CHECK_DIRECTORY 0x10
#define SMB_COM_PROCESS_EXIT 0x11
#define SMB_COM_SEEK 0x12
#define SMB_COM_LOCK_AND_READ 0x13
#define SMB_COM_WRITE_AND_UNLOCK 0x14
#define SMB_COM_READ_RAW 0x1A
#define SMB_COM_READ_MPX 0x1B
#define SMB_COM_READ_MPX_SECONDARY 0x1C
#define SMB_COM_WRITE_RAW 0x1D
#define SMB_COM_WRITE_MPX 0x1E
#define SMB_COM_WRITE_COMPLETE 0x20
#define SMB_COM_SET_INFORMATION2 0x22
#define SMB_COM_QUERY_INFORMATION2 0x23
#define SMB_COM_LOCKING_ANDX 0x24
#define SMB_COM_TRANSACTION 0x25
#define SMB_COM_TRANSACTION_SECONDARY 0x26
#define SMB_COM_IOCTL 0x27
#define SMB_COM_IOCTL_SECONDARY 0x28
#define SMB_COM_COPY 0x29
#define SMB_COM_MOVE 0x2A
#define SMB_COM_ECHO 0x2B
#define SMB_COM_WRITE_AND_CLOSE 0x2C
#define SMB_COM_OPEN_ANDX 0x2D
#define SMB_COM_READ_ANDX 0x2E
#define SMB_COM_WRITE_ANDX 0x2F
#define SMB_COM_CLOSE_AND_TREE_DISC 0x31
#define SMB_COM_TRANSACTION2 0x32
#define SMB_COM_TRANSACTION2_SECONDARY 0x33
#define SMB_COM_FIND_CLOSE2 0x34
#define SMB_COM_FIND_NOTIFY_CLOSE 0x35
#define SMB_COM_TREE_CONNECT 0x70
#define SMB_COM_TREE_DISCONNECT 0x71
#define SMB_COM_NEGOTIATE 0x72
#define SMB_COM_SESSION_SETUP_ANDX 0x73
#define SMB_COM_LOGOFF_ANDX 0x74
#define SMB_COM_TREE_CONNECT_ANDX 0x75
#define SMB_COM_QUERY_INFORMATION_DISK 0x80
#define SMB_COM_SEARCH 0x81
#define SMB_COM_FIND 0x82
#define SMB_COM_FIND_UNIQUE 0x83
#define SMB_COM_NT_TRANSACT 0xA0
#define SMB_COM_NT_TRANSACT_SECONDARY 0xA1
#define SMB_COM_NT_CREATE_ANDX 0xA2
#define SMB_COM_NT_CANCEL 0xA4
#define SMB_COM_OPEN_PRINT_FILE 0xC0
#define SMB_COM_WRITE_PRINT_FILE 0xC1
#define SMB_COM_CLOSE_PRINT_FILE 0xC2
#define SMB_COM_GET_PRINT_QUEUE 0xC3
#define SMB_COM_READ_BULK 0xD8
#define SMB_COM_WRITE_BULK 0xD9
#define SMB_COM_WRITE_BULK_DATA 0xDA
#define SMB_TRANS2_OPEN2 0x00
#define SMB_TRANS2_FIND_FIRST2 0x01
#define SMB_TRANS2_FIND_NEXT2 0x02
#define SMB_TRANS2_QUERY_FS_INFORMATION 0x03
#define SMB_TRANS2_QUERY_PATH_INFORMATION 0x05
#define SMB_TRANS2_SET_PATH_INFORMATION 0x06
#define SMB_TRANS2_QUERY_FILE_INFORMATION 0x07
#define SMB_TRANS2_SET_FILE_INFORMATION 0x08
#define SMB_TRANS2_FSCTL 0x09
#define SMB_TRANS2_IOCTL2 0x0A
#define SMB_TRANS2_FIND_NOTIFY_FIRST 0x0B
#define SMB_TRANS2_FIND_NOTIFY_NEXT 0x0C
#define SMB_TRANS2_CREATE_DIRECTORY 0x0D
#define SMB_TRANS2_SESSION_SETUP 0x0E
#define SMB_TRANS2_GET_DFS_REFERRAL 0x10
#define SMB_TRANS2_REPORT_DFS_INCONSISTENCY 0x11
#define SMB_INFO_ALLOCATION 1
#define SMB_INFO_VOLUME 2
#define SMB_QUERY_FS_VOLUME_INFO 0x102
#define SMB_QUERY_FS_SIZE_INFO 0x103
#define SMB_QUERY_FS_DEVICE_INFO 0x104
#define SMB_QUERY_FS_ATTRIBUTE_INFO 0x105
#define SMB_QUERY_FILE_STANDARD 1
#define SMB_QUERY_FILE_EA_SIZE 2
#define SMB_QUERY_FILE_EAS_FROM_LIST 3
#define SMB_QUERY_FILE_ALL_EAS 4
#define SMB_QUERY_FILE_IS_NAME_VALID 6
#define SMB_QUERY_FILE_BASIC_INFO 0x101
#define SMB_QUERY_FILE_STANDARD_INFO 0x102
#define SMB_QUERY_FILE_EA_INFO 0x103
#define SMB_QUERY_FILE_NAME_INFO 0x104
#define SMB_QUERY_FILE_ALL_INFO 0x107
#define SMB_QUERY_FILE_ALT_NAME_INFO 0x108
#define SMB_QUERY_FILE_STREAM_INFO 0x109
#define SMB_QUERY_FILE_COMPRESSION_INFO 0x10b
#define SMB_QUERY_FILE_UNIX_BASIC 0x200
#define SMB_QUERY_FILE_UNIX_LINK 0x201
#define SMB_QUERY_FILE_MAC_DT_GET_APPL 0x306
#define SMB_QUERY_FILE_MAC_DT_GET_ICON 0x307
#define SMB_QUERY_FILE_MAC_DT_GET_ICON_INFO 0x308
#define SMB_INFO_STANDARD 1
#define SMB_INFO_QUERY_EA_SIZE 2
#define SMB_INFO_QUERY_EAS_FROM_LIST 3
#define SMB_FIND_FILE_DIRECTORY_INFO 0x101
#define SMB_FIND_FULL_DIRECTORY_INFO 0x102
#define SMB_FIND_FILE_NAMES_INFO 0x103
#define SMB_FIND_BOTH_DIRECTORY_INFO 0x104
#define SMB_SET_FILE_BASIC_INFO 0x101
#define SMB_SET_FILE_END_OF_FILE_INFO 0x104
#define SMB_LOCKING_ANDX_SHARED_LOCK 0x01
#define SMB_LOCKING_ANDX_OPLOCK_RELEASE 0x02
#define SMB_LOCKING_ANDX_CHANGE_LOCKTYPE 0x04
#define SMB_LOCKING_ANDX_CANCEL_LOCK 0x08
#define SMB_LOCKING_ANDX_LARGE_FILES 0x10
#define SMB_MAXSRVNAMELEN 15
#define SMB_MAXUSERNAMELEN 128
#define SMB_MAXPASSWORDLEN 128
#define SMB_MAXSHARENAMELEN 128
#define SMB_MAXPKTLEN 0x1FFFF
#define SMB_MAXCHALLENGELEN 8
#define SMB_MAXFNAMELEN 255
#define SMB_MAXRCN 3
#define SMBSUCCESS 0x00
#define ERRDOS 0x01
#define ERRSRV 0x02
#define ERRHRD 0x03
#define ERRCMD 0xFF
#define ERRbadfunc 1
#define ERRbadfile 2
#define ERRbadpath 3
#define ERRnofids 4
#define ERRnoaccess 5
#define ERRbadfid 6
#define ERRbadmcb 7
#define ERRnomem 8
#define ERRbadmem 9
#define ERRbadenv 10
#define ERRbadformat 11
#define ERRbadaccess 12
#define ERRbaddata 13
#define ERRbaddrive 15
#define ERRremcd 16
#define ERRdiffdevice 17
#define ERRnofiles 18
#define ERRbadshare 32
#define ERRlock 33
#define ERRunsup 50
#define ERRnoipc 66
#define ERRnosuchshare 67
#define ERRfilexists 80
#define ERRquota 112
#define ERRcannotopen 110
#define ERRinvalidname 123
#define ERRunknownlevel 124
#define ERRnotlocked 158
#define ERRrename 183
#define ERRbadpipe 230
#define ERRpipebusy 231
#define ERRpipeclosing 232
#define ERRnotconnected 233
#define ERRmoredata 234
#define ERRbaddirectory 267
#define ERReasunsupported 282
#define ERRunknownipc 2142
#define ERRbuftoosmall 2123
#define ERRnosuchprintjob 2151
#define ERRerror 1
#define ERRbadpw 2
#define ERRbadtype 3
#define ERRaccess 4
#define ERRinvnid 5
#define ERRinvnetname 6
#define ERRinvdevice 7
#define ERRqfull 49
#define ERRqtoobig 50
#define ERRinvpfid 52
#define ERRsmbcmd 64
#define ERRsrverror 65
#define ERRfilespecs 67
#define ERRbadpermits 69
#define ERRsetattrmode 71
#define ERRpaused 81
#define ERRmsgoff 82
#define ERRnoroom 83
#define ERRrmuns 87
#define ERRtimeout 88
#define ERRnoresource 89
#define ERRtoomanyuids 90
#define ERRbaduid 91
#define ERRusempx 250
#define ERRusestd 251
#define ERRcontmpx 252
#define ERRbadPassword 254
#define ERRaccountExpired 2239
#define ERRbadClient 2240
#define ERRbadLogonTime 2241
#define ERRpasswordExpired 2242
#define ERRnosupport 65535
#define ERRnowrite 19
#define ERRbadunit 20
#define ERRnotready 21
#define ERRbadcmd 22
#define ERRdata 23
#define ERRbadreq 24
#define ERRseek 25
#define ERRbadmedia 26
#define ERRbadsector 27
#define ERRnopaper 28
#define ERRwrite 29
#define ERRread 30
#define ERRgeneral 31
#define ERRbadshare 32
#define ERRlock 33
#define ERRwrongdisk 34
#define ERRFCBunavail 35
#define ERRsharebufexc 36
#define ERRdiskfull 39
#define SMB_ERROR_ACCESS_DENIED 5
#define SMB_ERROR_NETWORK_ACCESS_DENIED 65
#define SMB_ERROR_MORE_DATA 234
typedef u_int16_t smbfh;
#endif