1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/*
WinPopup Protocol plugin for Miranda IM.
Copyright (C) 2004-2011 Nikolay Raspopov
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
const DWORD SMB_MAGIC = 0x424d53ff; // 0xff 'S' 'M' 'B'
const WORD SM_MAGIC = 0x4d53; // 'S' 'M'
// NetBIOS datagrams:
// (obsolete)
const UCHAR SM_CHANGESTATUS = 0x01;
// Status request: 'S' 'M' 0x02
const UCHAR SM_GETSTATUS = 0x02;
// Status answer: 'S' 'M' 0x03 status(i32)
const UCHAR SM_SENDSTATUS = 0x03;
// Away message request: 'S' 'M' 0x04
const UCHAR SM_GETAWAYMESSAGE = 0x04;
// Away message answer: 'S' 'M' 0x05 0x00(i32) message(ASCII)
const UCHAR SM_SENDAWAYMESSAGE = 0x05;
// Avatar request: 'S' 'M' 0x06
const UCHAR SM_GETAVATAR = 0x06;
// Avatar answer: 'S' 'M' 0x07 avatar
const UCHAR SM_SENDAVATAR = 0x07;
const LPCTSTR MNS_STATUS = _T("MNS_STATUS");
#define MAX_AVATAR_SIZE 65000 // Ìàêñèìàëüíûé ðàçìåð ôàéëà àâàòàðà (áàéò)
#pragma pack (push, 1)
typedef struct _FIND_NAME_BLOCK
{
FIND_NAME_HEADER fnb_header;
FIND_NAME_BUFFER fnb_Names [256];
} FIND_NAME_BLOCK, *PFIND_NAME_BLOCK;
typedef struct _ADAPTER_STATUS_BLOCK
{
ADAPTER_STATUS asb_header;
NAME_BUFFER asb_Names [NCBNAMSZ];
} ADAPTER_STATUS_BLOCK, *PADAPTER_STATUS_BLOCK;
#pragma pack (pop)
class netbios
{
public:
netbios();
~netbios();
bool Create (BOOL registration);
void AskForDestroy(); // Äëÿ óñêîðåíèÿ
void Destroy ();
operator bool() const;
bool SendNetBIOSMessage (HANDLE hContact, LPCTSTR msg /* ANSI */, DWORD& err);
ip FindNameIP (LPCTSTR szName /* ANSI */, UCHAR type = 3);
void GetRegisteredNames (netbios_name_list& names);
bool GetNames (netbios_name_list& names, LPCTSTR name /* ANSI */, bool bGroup);
// Ïîëó÷åíèå èìåíè èç ñïèñêà ïî óêàçàííîìó èìåíè
netbios_name* GetName (const netbios_name& nname);
// Ïîèñê íîìåðà àäàïòåðà ÷åðåç êîòîðûé ìîæíî äîñòó÷àòüñÿ äî óêàçàííîãî èìåíè
bool FindNameLana (const netbios_name& nname, UCHAR& lana);
bool GetMAC (UCHAR lana, CString& mac);
UCHAR FindName (const netbios_name& nname, UCHAR lana, FIND_NAME_BLOCK& fn);
UCHAR GetAdapterStatus (const netbios_name& nname, UCHAR lana, ADAPTER_STATUS_BLOCK& astat);
UCHAR EnumLanas (LANA_ENUM& le);
UCHAR ResetLana (UCHAR lana);
UCHAR Hangup (UCHAR lana, UCHAR lsn);
UCHAR Send (UCHAR lana, UCHAR lsn, unsigned char* data, WORD length);
UCHAR Recv (UCHAR lana, UCHAR lsn, unsigned char* data, WORD& length);
UCHAR Stat (const netbios_name& nname, SESSION_INFO_BLOCK* psibSession);
UCHAR Listen (const netbios_name& nname, UCHAR& lsn);
UCHAR AddName (netbios_name& nname);
UCHAR DeleteName (const netbios_name& nname);
UCHAR SendDatagram (const netbios_name& nname_from, const netbios_name& nname_to, unsigned char* data, WORD length);
UCHAR RecvDatagram (netbios_name& nname_from, const netbios_name& nname_to, unsigned char* data, WORD& length);
UCHAR Call (UCHAR lana, const netbios_name& nname_from, const netbios_name& nname_to, UCHAR& lsn);
unsigned char* SetSMBHeaderCommand (unsigned char* szHeader, BYTE iCommandCode, size_t iBufferLen);
// Çàïðîñ ýâåé-ñîîáùåíèÿ
bool AskAway(const netbios_name& nname_to);
// Îòïðàâêà ýâåé-ñîîáùåíèÿ
bool SendAway(netbios_name& nname_from, const netbios_name& nname_to);
// Çàïðîñ ñòàòóñà
bool AskStatus(const netbios_name& nname_to);
// Îòïðàâêà ñòàòóñà
bool SendStatus(netbios_name& nname_from, const netbios_name& nname_to);
// Îòïðàâêà ñòàòóñà íà âñåõ àäàïòåðàõ (îò COMPUTER<03> U íà MNS_STATUS<ab> G)
bool BroadcastStatus();
// Çàïðîñ àâàòàðà
bool AskAvatar(const netbios_name& nname_to);
// Îòïðàâêà àâàòàðà
bool SendAvatar(netbios_name& nname_from, const netbios_name& nname_to);
protected:
bool m_initialized; // Ôëàã èíèöèàëèçàöèè ïîäñèñòåìû NetBIOS
netbios_name_array m_names; // Âñå ðåãèñòðèðóåìûå NetBIOS-èìåíà äëÿ ñëóøàòåëÿ
LANA_ENUM m_le; // Ñïèñîê àäàïòåðîâ
CComAutoCriticalSection m_csData; // Çàùèòà äàííûõ
CComAutoCriticalSection m_csNetBIOS; // Ñèíõðîíèçàöèÿ NetBIOS
bool Register (); // Ðåãèñòðàöèÿ âñåõ NetBIOS-èìåí
void Deregister (); // Äåðåãèñòðàöèÿ âñåõ NetBIOS-èìåí
};
extern netbios pluginNetBIOS; // Ïðèåì/îòïðàâêà ñîîáùåíèé ÷åðåç NetBIOS
LPCSTR GetNetbiosCommand(UCHAR command);
LPCSTR GetNetbiosError(UCHAR err);
UCHAR NetbiosEx(NCB* pNCB);
|