1 /******************************************************************************
2 *
3 * Copyright (C) 2008, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * Author: Alexey Krivonogov ( gentee )
11 *
12 ******************************************************************************/
13
14 define
15 {
16 NCBNAMSZ = 16 // absolute length of a net name
17 MAX_LANA = 254 // lana's in range 0 to MAX_LANA inclusive
18
19 NCBRESET = 0x32 // NCB RESET
20 NCBASTAT = 0x33 // NCB ADAPTER STATUS
21 NCBENUM = 0x37 // NCB ENUMERATE LANA NUMBERS
22 }
23
24 type NCB {
25 ubyte ncb_command // command code
26 ubyte ncb_retcode // return code
27 ubyte ncb_lsn // local session number
28 ubyte ncb_num // number of our network name
29 uint ncb_buffer // address of message buffer
30 ushort ncb_length // size of message buffer
31 reserved ncb_callname[ $NCBNAMSZ] // blank-padded name of remote
32 reserved ncb_name[ $NCBNAMSZ] // our blank-padded netname
33 ubyte ncb_rto // rcv timeout/retry count
34 ubyte ncb_sto // send timeout/sys timeout
35 uint ncb_post // POST routine address
36 ubyte ncb_lana_num // lana (adapter) number
37 ubyte ncb_cmd_cplt // 0xff => commmand pending
38 reserved ncb_reserve[10] // reserved, used by BIOS
39 uint ncb_event // HANDLE to Win32 event which will be set to the
40 // signalled state when an ASYNCH command completes
41 }
42
43 type ADAPTER_STATUS {
44 reserved adapter_address[6]
45 ubyte rev_major
46 ubyte reserved0
47 ubyte adapter_type
48 ubyte rev_minor
49 ushort duration
50 ushort frmr_recv
51 ushort frmr_xmit
52
53 ushort iframe_recv_err
54
55 ushort xmit_aborts
56 uint xmit_success
57 uint recv_success
58
59 ushort iframe_xmit_err
60
61 ushort recv_buff_unavail
62 ushort t1_timeouts
63 ushort ti_timeouts
64 uint reserved1
65 ushort free_ncbs
66 ushort max_cfg_ncbs
67 ushort max_ncbs
68 ushort xmit_buf_unavail
69 ushort max_dgram_size
70 ushort pending_sess
71 ushort max_cfg_sess
72 ushort max_sess
73 ushort max_sess_pkt_size
74 ushort name_count
75 }
76
77 type NAME_BUFFER {
78 reserved name[ $NCBNAMSZ ]
79 ubyte name_num
80 ubyte name_flags
81 }
82
83 type LANA_ENUM {
84 ubyte length // Number of valid entries in lana[]
85 reserved lana[ $MAX_LANA+1 ]
86 }
87
88 type adapter
89 {
90 ADAPTER_STATUS adapt
91 reserved NameBuff[ 540 ] // 30 * NAME_BUFFER
92 }
93
94 import "netapi32.dll"
95 {
96 ubyte Netbios( NCB )
97 }
98
99 func uint nb_getmac( arr mac )
100 {
101 uint ret ok
102 NCB ncb
103 adapter ad
104 LANA_ENUM lenum
105
106 mac.clear()
107 ncb.ncb_command = $NCBENUM
108 ncb.ncb_buffer = &lenum
109 ncb.ncb_length = sizeof( LANA_ENUM )
110 if ok = Netbios( ncb ) : return 0
111 mzero( &ncb, sizeof( NCB ))
112
113 ncb.ncb_command = $NCBRESET
114 ncb.ncb_lana_num = lenum.lana[0]
115 if ok = Netbios( ncb ) : return 0
116 mzero( &ncb, sizeof( NCB ))
117 ncb.ncb_command = $NCBASTAT
118 ncb.ncb_lana_num = lenum.lana[0]
119 mcopy( &ncb.ncb_callname, "* ".ptr(), 16 )
120 ncb.ncb_buffer = &ad
121 ncb.ncb_length = sizeof( adapter )
122 if !Netbios( ncb )
123 {
124 mac.expand( 6 )
125 fornum ok = 0, 6
126 {
127 mac[ ok ] = ad.adapt.adapter_address[ ok ]
128 }
129 }
130 return 1
131 }