jwanb30.pas 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. {******************************************************************************}
  2. { }
  3. { Portable Netbios 3.0 API interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: Nb30.h, released June 2000. The original Pascal }
  9. { code is: JwaN30.pas, released December 2000. The initial developer of the }
  10. { Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
  11. { }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  13. { Marcel van Brakel. All Rights Reserved. }
  14. { }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  16. { }
  17. { You may retrieve the latest version of this file at the Project JEDI }
  18. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  19. { }
  20. { The contents of this file are used with permission, subject to the Mozilla }
  21. { Public License Version 1.1 (the "License"); you may not use this file except }
  22. { in compliance with the License. You may obtain a copy of the License at }
  23. { http://www.mozilla.org/MPL/MPL-1.1.html }
  24. { }
  25. { Software distributed under the License is distributed on an "AS IS" basis, }
  26. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  27. { the specific language governing rights and limitations under the License. }
  28. { }
  29. { Alternatively, the contents of this file may be used under the terms of the }
  30. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  31. { provisions of the LGPL License are applicable instead of those above. }
  32. { If you wish to allow use of your version of this file only under the terms }
  33. { of the LGPL License and not to allow others to use your version of this file }
  34. { under the MPL, indicate your decision by deleting the provisions above and }
  35. { replace them with the notice and other provisions required by the LGPL }
  36. { License. If you do not delete the provisions above, a recipient may use }
  37. { your version of this file under either the MPL or the LGPL License. }
  38. { }
  39. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  40. { }
  41. {******************************************************************************}
  42. unit JwaNb30;
  43. {$WEAKPACKAGEUNIT}
  44. {$HPPEMIT ''}
  45. {$HPPEMIT '#include "Nb30.h"'}
  46. {$HPPEMIT ''}
  47. {$I jediapilib.inc}
  48. interface
  49. uses
  50. JwaWinType;
  51. (****************************************************************
  52. * *
  53. * Data structure templates *
  54. * *
  55. ****************************************************************)
  56. const
  57. NCBNAMSZ = 16; // absolute length of a net name
  58. {$EXTERNALSYM NCBNAMSZ}
  59. MAX_LANA = 254; // lana's in range 0 to MAX_LANA inclusive
  60. {$EXTERNALSYM MAX_LANA}
  61. //
  62. // Network Control Block
  63. //
  64. type
  65. PNCB = ^NCB;
  66. TNcbPost = procedure(P: PNCB); stdcall;
  67. _NCB = record
  68. ncb_command: UCHAR; // command code
  69. ncb_retcode: UCHAR; // return code
  70. ncb_lsn: UCHAR; // local session number
  71. ncb_num: UCHAR; // number of our network name
  72. ncb_buffer: PChar; // address of message buffer
  73. ncb_length: Word; // size of message buffer
  74. ncb_callname: array [0..NCBNAMSZ - 1] of Char; // blank-padded name of remote
  75. ncb_name: array [0..NCBNAMSZ - 1] of Char; // our blank-padded netname
  76. ncb_rto: UCHAR; // rcv timeout/retry count
  77. ncb_sto: UCHAR; // send timeout/sys timeout
  78. ncb_post: TNcbPost; // POST routine address
  79. ncb_lana_num: UCHAR; // lana (adapter) number
  80. ncb_cmd_cplt: UCHAR; // 0xff => commmand pending
  81. {$IFDEF _WIN64}
  82. ncb_reserve: array [0..17] of Char; // reserved, used by BIOS
  83. {$ELSE}
  84. ncb_reserve: array [0..9] of Char; // reserved, used by BIOS
  85. {$ENDIF _WIN64}
  86. ncb_event: HANDLE; // HANDLE to Win32 event which
  87. // will be set to the signalled
  88. // state when an ASYNCH command
  89. // completes
  90. end;
  91. {$EXTERNALSYM _NCB}
  92. NCB = _NCB;
  93. {$EXTERNALSYM NCB}
  94. TNcb = NCB;
  95. //
  96. // Structure returned to the NCB command NCBASTAT is ADAPTER_STATUS followed
  97. // by an array of NAME_BUFFER structures.
  98. //
  99. _ADAPTER_STATUS = record
  100. adapter_address: array [0..5] of UCHAR;
  101. rev_major: UCHAR;
  102. reserved0: UCHAR;
  103. adapter_type: UCHAR;
  104. rev_minor: UCHAR;
  105. duration: WORD;
  106. frmr_recv: WORD;
  107. frmr_xmit: WORD;
  108. iframe_recv_err: WORD;
  109. xmit_aborts: WORD;
  110. xmit_success: DWORD;
  111. recv_success: DWORD;
  112. iframe_xmit_err: WORD;
  113. recv_buff_unavail: WORD;
  114. t1_timeouts: WORD;
  115. ti_timeouts: WORD;
  116. reserved1: DWORD;
  117. free_ncbs: WORD;
  118. max_cfg_ncbs: WORD;
  119. max_ncbs: WORD;
  120. xmit_buf_unavail: WORD;
  121. max_dgram_size: WORD;
  122. pending_sess: WORD;
  123. max_cfg_sess: WORD;
  124. max_sess: WORD;
  125. max_sess_pkt_size: WORD;
  126. name_count: WORD;
  127. end;
  128. {$EXTERNALSYM _ADAPTER_STATUS}
  129. ADAPTER_STATUS = _ADAPTER_STATUS;
  130. {$EXTERNALSYM ADAPTER_STATUS}
  131. PADAPTER_STATUS = ^ADAPTER_STATUS;
  132. {$EXTERNALSYM PADAPTER_STATUS}
  133. TAdapterStatus = ADAPTER_STATUS;
  134. PAdapterStatus = PADAPTER_STATUS;
  135. _NAME_BUFFER = record
  136. name: array [0..NCBNAMSZ - 1] of Char;
  137. name_num: UCHAR;
  138. name_flags: UCHAR;
  139. end;
  140. {$EXTERNALSYM _NAME_BUFFER}
  141. NAME_BUFFER = _NAME_BUFFER;
  142. {$EXTERNALSYM NAME_BUFFER}
  143. PNAME_BUFFER = ^NAME_BUFFER;
  144. {$EXTERNALSYM PNAME_BUFFER}
  145. TNameBuffer = NAME_BUFFER;
  146. PNameBuffer = PNAME_BUFFER;
  147. // values for name_flags bits.
  148. const
  149. NAME_FLAGS_MASK = $87;
  150. {$EXTERNALSYM NAME_FLAGS_MASK}
  151. GROUP_NAME = $80;
  152. {$EXTERNALSYM GROUP_NAME}
  153. UNIQUE_NAME = $00;
  154. {$EXTERNALSYM UNIQUE_NAME}
  155. REGISTERING = $00;
  156. {$EXTERNALSYM REGISTERING}
  157. REGISTERED = $04;
  158. {$EXTERNALSYM REGISTERED}
  159. DEREGISTERED = $05;
  160. {$EXTERNALSYM DEREGISTERED}
  161. DUPLICATE = $06;
  162. {$EXTERNALSYM DUPLICATE}
  163. DUPLICATE_DEREG = $07;
  164. {$EXTERNALSYM DUPLICATE_DEREG}
  165. //
  166. // Structure returned to the NCB command NCBSSTAT is SESSION_HEADER followed
  167. // by an array of SESSION_BUFFER structures. If the NCB_NAME starts with an
  168. // asterisk then an array of these structures is returned containing the
  169. // status for all names.
  170. //
  171. type
  172. _SESSION_HEADER = record
  173. sess_name: UCHAR;
  174. num_sess: UCHAR;
  175. rcv_dg_outstanding: UCHAR;
  176. rcv_any_outstanding: UCHAR;
  177. end;
  178. {$EXTERNALSYM _SESSION_HEADER}
  179. SESSION_HEADER = _SESSION_HEADER;
  180. {$EXTERNALSYM SESSION_HEADER}
  181. PSESSION_HEADER = ^SESSION_HEADER;
  182. {$EXTERNALSYM PSESSION_HEADER}
  183. TSessionHeader = SESSION_HEADER;
  184. PSessionHeader = PSESSION_HEADER;
  185. _SESSION_BUFFER = record
  186. lsn: UCHAR;
  187. state: UCHAR;
  188. local_name: array [0..NCBNAMSZ - 1] of UCHAR;
  189. remote_name: array [0..NCBNAMSZ - 1] of UCHAR;
  190. rcvs_outstanding: UCHAR;
  191. sends_outstanding: UCHAR;
  192. end;
  193. {$EXTERNALSYM _SESSION_BUFFER}
  194. SESSION_BUFFER = _SESSION_BUFFER;
  195. {$EXTERNALSYM SESSION_BUFFER}
  196. PSESSION_BUFFER = ^SESSION_BUFFER;
  197. {$EXTERNALSYM PSESSION_BUFFER}
  198. TSessionBuffer = SESSION_BUFFER;
  199. PSessionBuffer = PSESSION_BUFFER;
  200. // Values for state
  201. const
  202. LISTEN_OUTSTANDING = $01;
  203. {$EXTERNALSYM LISTEN_OUTSTANDING}
  204. CALL_PENDING = $02;
  205. {$EXTERNALSYM CALL_PENDING}
  206. SESSION_ESTABLISHED = $03;
  207. {$EXTERNALSYM SESSION_ESTABLISHED}
  208. HANGUP_PENDING = $04;
  209. {$EXTERNALSYM HANGUP_PENDING}
  210. HANGUP_COMPLETE = $05;
  211. {$EXTERNALSYM HANGUP_COMPLETE}
  212. SESSION_ABORTED = $06;
  213. {$EXTERNALSYM SESSION_ABORTED}
  214. //
  215. // Structure returned to the NCB command NCBENUM.
  216. //
  217. // On a system containing lana's 0, 2 and 3, a structure with
  218. // length =3, lana[0]=0, lana[1]=2 and lana[2]=3 will be returned.
  219. //
  220. type
  221. _LANA_ENUM = record
  222. length: UCHAR; // Number of valid entries in lana[]
  223. lana: array [0..MAX_LANA] of UCHAR;
  224. end;
  225. {$EXTERNALSYM _LANA_ENUM}
  226. LANA_ENUM = _LANA_ENUM;
  227. {$EXTERNALSYM LANA_ENUM}
  228. PLANA_ENUM = ^LANA_ENUM;
  229. {$EXTERNALSYM PLANA_ENUM}
  230. TLanaEnum = LANA_ENUM;
  231. PLanaEnum = PLANA_ENUM;
  232. //
  233. // Structure returned to the NCB command NCBFINDNAME is FIND_NAME_HEADER followed
  234. // by an array of FIND_NAME_BUFFER structures.
  235. //
  236. type
  237. _FIND_NAME_HEADER = record
  238. node_count: WORD;
  239. reserved: UCHAR;
  240. unique_group: UCHAR;
  241. end;
  242. {$EXTERNALSYM _FIND_NAME_HEADER}
  243. FIND_NAME_HEADER = _FIND_NAME_HEADER;
  244. {$EXTERNALSYM FIND_NAME_HEADER}
  245. PFIND_NAME_HEADER = ^FIND_NAME_HEADER;
  246. {$EXTERNALSYM PFIND_NAME_HEADER}
  247. TFindNameHeader = FIND_NAME_HEADER;
  248. PFindNameHeader = PFIND_NAME_HEADER;
  249. _FIND_NAME_BUFFER = record
  250. length: UCHAR;
  251. access_control: UCHAR;
  252. frame_control: UCHAR;
  253. destination_addr: array [0..5] of UCHAR;
  254. source_addr: array [0..5] of UCHAR;
  255. routing_info: array [0..17] of UCHAR;
  256. end;
  257. {$EXTERNALSYM _FIND_NAME_BUFFER}
  258. FIND_NAME_BUFFER = _FIND_NAME_BUFFER;
  259. {$EXTERNALSYM FIND_NAME_BUFFER}
  260. PFIND_NAME_BUFFER = ^FIND_NAME_BUFFER;
  261. {$EXTERNALSYM PFIND_NAME_BUFFER}
  262. TFindNameBuffer = FIND_NAME_BUFFER;
  263. PFindNameBuffer = PFIND_NAME_BUFFER;
  264. //
  265. // Structure provided with NCBACTION. The purpose of NCBACTION is to provide
  266. // transport specific extensions to netbios.
  267. //
  268. _ACTION_HEADER = record
  269. transport_id: ULONG;
  270. action_code: USHORT;
  271. reserved: USHORT;
  272. end;
  273. {$EXTERNALSYM _ACTION_HEADER}
  274. ACTION_HEADER = _ACTION_HEADER;
  275. {$EXTERNALSYM ACTION_HEADER}
  276. PACTION_HEADER = ^ACTION_HEADER;
  277. {$EXTERNALSYM PACTION_HEADER}
  278. TActionHeader = ACTION_HEADER;
  279. PActionHeader = PACTION_HEADER;
  280. // Values for transport_id
  281. const
  282. ALL_TRANSPORTS = 'M'#0#0#0;
  283. {$EXTERNALSYM ALL_TRANSPORTS}
  284. MS_NBF = 'MNBF';
  285. {$EXTERNALSYM MS_NBF}
  286. (****************************************************************
  287. * *
  288. * Special values and constants *
  289. * *
  290. ****************************************************************)
  291. //
  292. // NCB Command codes
  293. //
  294. const
  295. NCBCALL = $10; // NCB CALL
  296. {$EXTERNALSYM NCBCALL}
  297. NCBLISTEN = $11; // NCB LISTEN
  298. {$EXTERNALSYM NCBLISTEN}
  299. NCBHANGUP = $12; // NCB HANG UP
  300. {$EXTERNALSYM NCBHANGUP}
  301. NCBSEND = $14; // NCB SEND
  302. {$EXTERNALSYM NCBSEND}
  303. NCBRECV = $15; // NCB RECEIVE
  304. {$EXTERNALSYM NCBRECV}
  305. NCBRECVANY = $16; // NCB RECEIVE ANY
  306. {$EXTERNALSYM NCBRECVANY}
  307. NCBCHAINSEND = $17; // NCB CHAIN SEND
  308. {$EXTERNALSYM NCBCHAINSEND}
  309. NCBDGSEND = $20; // NCB SEND DATAGRAM
  310. {$EXTERNALSYM NCBDGSEND}
  311. NCBDGRECV = $21; // NCB RECEIVE DATAGRAM
  312. {$EXTERNALSYM NCBDGRECV}
  313. NCBDGSENDBC = $22; // NCB SEND BROADCAST DATAGRAM
  314. {$EXTERNALSYM NCBDGSENDBC}
  315. NCBDGRECVBC = $23; // NCB RECEIVE BROADCAST DATAGRAM
  316. {$EXTERNALSYM NCBDGRECVBC}
  317. NCBADDNAME = $30; // NCB ADD NAME
  318. {$EXTERNALSYM NCBADDNAME}
  319. NCBDELNAME = $31; // NCB DELETE NAME
  320. {$EXTERNALSYM NCBDELNAME}
  321. NCBRESET = $32; // NCB RESET
  322. {$EXTERNALSYM NCBRESET}
  323. NCBASTAT = $33; // NCB ADAPTER STATUS
  324. {$EXTERNALSYM NCBASTAT}
  325. NCBSSTAT = $34; // NCB SESSION STATUS
  326. {$EXTERNALSYM NCBSSTAT}
  327. NCBCANCEL = $35; // NCB CANCEL
  328. {$EXTERNALSYM NCBCANCEL}
  329. NCBADDGRNAME = $36; // NCB ADD GROUP NAME
  330. {$EXTERNALSYM NCBADDGRNAME}
  331. NCBENUM = $37; // NCB ENUMERATE LANA NUMBERS
  332. {$EXTERNALSYM NCBENUM}
  333. NCBUNLINK = $70; // NCB UNLINK
  334. {$EXTERNALSYM NCBUNLINK}
  335. NCBSENDNA = $71; // NCB SEND NO ACK
  336. {$EXTERNALSYM NCBSENDNA}
  337. NCBCHAINSENDNA = $72; // NCB CHAIN SEND NO ACK
  338. {$EXTERNALSYM NCBCHAINSENDNA}
  339. NCBLANSTALERT = $73; // NCB LAN STATUS ALERT
  340. {$EXTERNALSYM NCBLANSTALERT}
  341. NCBACTION = $77; // NCB ACTION
  342. {$EXTERNALSYM NCBACTION}
  343. NCBFINDNAME = $78; // NCB FIND NAME
  344. {$EXTERNALSYM NCBFINDNAME}
  345. NCBTRACE = $79; // NCB TRACE
  346. {$EXTERNALSYM NCBTRACE}
  347. ASYNCH = $80; // high bit set == asynchronous
  348. {$EXTERNALSYM ASYNCH}
  349. //
  350. // NCB Return codes
  351. //
  352. NRC_GOODRET = $00; // good return also returned when ASYNCH request accepted
  353. {$EXTERNALSYM NRC_GOODRET}
  354. NRC_BUFLEN = $01; // illegal buffer length
  355. {$EXTERNALSYM NRC_BUFLEN}
  356. NRC_ILLCMD = $03; // illegal command
  357. {$EXTERNALSYM NRC_ILLCMD}
  358. NRC_CMDTMO = $05; // command timed out
  359. {$EXTERNALSYM NRC_CMDTMO}
  360. NRC_INCOMP = $06; // message incomplete, issue another command
  361. {$EXTERNALSYM NRC_INCOMP}
  362. NRC_BADDR = $07; // illegal buffer address
  363. {$EXTERNALSYM NRC_BADDR}
  364. NRC_SNUMOUT = $08; // session number out of range
  365. {$EXTERNALSYM NRC_SNUMOUT}
  366. NRC_NORES = $09; // no resource available
  367. {$EXTERNALSYM NRC_NORES}
  368. NRC_SCLOSED = $0a; // session closed
  369. {$EXTERNALSYM NRC_SCLOSED}
  370. NRC_CMDCAN = $0b; // command cancelled
  371. {$EXTERNALSYM NRC_CMDCAN}
  372. NRC_DUPNAME = $0d; // duplicate name
  373. {$EXTERNALSYM NRC_DUPNAME}
  374. NRC_NAMTFUL = $0e; // name table full
  375. {$EXTERNALSYM NRC_NAMTFUL}
  376. NRC_ACTSES = $0f; // no deletions, name has active sessions
  377. {$EXTERNALSYM NRC_ACTSES}
  378. NRC_LOCTFUL = $11; // local session table full
  379. {$EXTERNALSYM NRC_LOCTFUL}
  380. NRC_REMTFUL = $12; // remote session table full
  381. {$EXTERNALSYM NRC_REMTFUL}
  382. NRC_ILLNN = $13; // illegal name number
  383. {$EXTERNALSYM NRC_ILLNN}
  384. NRC_NOCALL = $14; // no callname
  385. {$EXTERNALSYM NRC_NOCALL}
  386. NRC_NOWILD = $15; // cannot put * in NCB_NAME
  387. {$EXTERNALSYM NRC_NOWILD}
  388. NRC_INUSE = $16; // name in use on remote adapter
  389. {$EXTERNALSYM NRC_INUSE}
  390. NRC_NAMERR = $17; // name deleted
  391. {$EXTERNALSYM NRC_NAMERR}
  392. NRC_SABORT = $18; // session ended abnormally
  393. {$EXTERNALSYM NRC_SABORT}
  394. NRC_NAMCONF = $19; // name conflict detected
  395. {$EXTERNALSYM NRC_NAMCONF}
  396. NRC_IFBUSY = $21; // interface busy, IRET before retrying
  397. {$EXTERNALSYM NRC_IFBUSY}
  398. NRC_TOOMANY = $22; // too many commands outstanding, retry later
  399. {$EXTERNALSYM NRC_TOOMANY}
  400. NRC_BRIDGE = $23; // ncb_lana_num field invalid
  401. {$EXTERNALSYM NRC_BRIDGE}
  402. NRC_CANOCCR = $24; // command completed while cancel occurring
  403. {$EXTERNALSYM NRC_CANOCCR}
  404. NRC_CANCEL = $26; // command not valid to cancel
  405. {$EXTERNALSYM NRC_CANCEL}
  406. NRC_DUPENV = $30; // name defined by anther local process
  407. {$EXTERNALSYM NRC_DUPENV}
  408. NRC_ENVNOTDEF = $34; // environment undefined. RESET required
  409. {$EXTERNALSYM NRC_ENVNOTDEF}
  410. NRC_OSRESNOTAV = $35; // required OS resources exhausted
  411. {$EXTERNALSYM NRC_OSRESNOTAV}
  412. NRC_MAXAPPS = $36; // max number of applications exceeded
  413. {$EXTERNALSYM NRC_MAXAPPS}
  414. NRC_NOSAPS = $37; // no saps available for netbios
  415. {$EXTERNALSYM NRC_NOSAPS}
  416. NRC_NORESOURCES = $38; // requested resources are not available
  417. {$EXTERNALSYM NRC_NORESOURCES}
  418. NRC_INVADDRESS = $39; // invalid ncb address or length > segment
  419. {$EXTERNALSYM NRC_INVADDRESS}
  420. NRC_INVDDID = $3B; // invalid NCB DDID
  421. {$EXTERNALSYM NRC_INVDDID}
  422. NRC_LOCKFAIL = $3C; // lock of user area failed
  423. {$EXTERNALSYM NRC_LOCKFAIL}
  424. NRC_OPENERR = $3f; // NETBIOS not loaded
  425. {$EXTERNALSYM NRC_OPENERR}
  426. NRC_SYSTEM = $40; // system error
  427. {$EXTERNALSYM NRC_SYSTEM}
  428. NRC_PENDING = $ff; // asynchronous command is not yet finished
  429. {$EXTERNALSYM NRC_PENDING}
  430. (****************************************************************
  431. * *
  432. * main user entry point for NetBIOS 3.0 *
  433. * *
  434. * Usage: result = Netbios( pncb ); *
  435. ****************************************************************)
  436. function Netbios(pncb: PNCB): UCHAR; stdcall;
  437. {$EXTERNALSYM Netbios}
  438. (****************************************************************
  439. * *
  440. * Prefix for callback routines *
  441. * *
  442. * Usage in a declaration: NCB_POST MyPostRoutine( PNCB pncb ); *
  443. ****************************************************************)
  444. // #define NCB_POST void CALLBACK
  445. implementation
  446. {$IFDEF DYNAMIC_LINK}
  447. var
  448. _Netbios: Pointer;
  449. function Netbios;
  450. begin
  451. GetProcedureAddress(_Netbios, 'netapi32.dll', 'Netbios');
  452. asm
  453. MOV ESP, EBP
  454. POP EBP
  455. JMP [_Netbios]
  456. end;
  457. end;
  458. {$ELSE}
  459. function Netbios; external 'netapi32.dll' name 'Netbios';
  460. {$ENDIF DYNAMIC_LINK}
  461. end.