home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 June
/
Chip_2001-06_cd1.bin
/
zkuste
/
vbasic
/
Data
/
Zdroj
/
netbios.bas
< prev
next >
Wrap
BASIC Source File
|
1999-06-29
|
19KB
|
445 lines
Attribute VB_Name = "vbNetBios"
Option Explicit
' This section contains the definitions
' for portable NetBIOS 3.0 support.
Public Const NCBNAMSZ = 16 ' absolute length of a net name
Public Const MAX_LANA = 254 ' lana's in range 0 to MAX_LANA
' NCB Command Codes (NetBios 3.0)
Public Const NCBCALL = &H10 ' Call
Public Const NCBLISTEN = &H11 ' Listen
Public Const NCBHANGUP = &H12 ' HangUp
Public Const NCBSEND = &H14 ' Send
Public Const NCBRECV = &H15 ' Receive
Public Const NCBRECVANY = &H16 ' Receive Any
Public Const NCBCHAINSEND = &H17 ' Chain Send
Public Const NCBDGSEND = &H20 ' Send Datagram
Public Const NCBDGRECV = &H21 ' Receive Datagram
Public Const NCBDGSENDBC = &H22 ' Send Broadcast Datagram
Public Const NCBDGRECVBC = &H23 ' Receive Broadcase Datagram
Public Const NCBADDNAME = &H30 ' Add Name
Public Const NCBDELNAME = &H31 ' Delete Name
Public Const NCBRESET = &H32 ' Reset
Public Const NCBASTAT = &H33 ' Adapter Status
Public Const NCBSSTAT = &H34 ' Session Status
Public Const NCBCANCEL = &H35 ' Cancel
Public Const NCBADDGRNAME = &H36 ' Add Group Name
Public Const NCBENUM = &H37 ' Enumerate Lana Numbers
Public Const NCBUNLINK = &H70 ' Unlink
Public Const NCBSENDNA = &H71 ' Send No Ack
Public Const NCBCHAINSENDNA = &H72 ' Chain Send No Ack
Public Const NCBLANSTALERT = &H73 ' LAN Status Alert
Public Const NCBACTION = &H77 ' Action
Public Const NCBFINDNAME = &H78 ' Find Name
Public Const NCBTRACE = &H79 ' Trace
Public Const ASYNCH = &H80 ' High bit set = Asynchronous
' NCB Return Codes
Public Const NRC_GOODRET = &H0 ' Good return (also returned when
' ASYNCH request accepted)
Public Const NRC_BUFLEN = &H1 ' Illegal Buffer Length
Public Const NRC_ILLCMD = &H3 ' Illegal Command
Public Const NRC_CMDTMO = &H5 ' Command Timed Out
Public Const NRC_INCOMP = &H6 ' Message Incomplete, Issue Another
' Command
Public Const NRC_BADDR = &H7 ' Illegal Buffer Address
Public Const NRC_SNUMOUT = &H8 ' Session Number is Out Of Range
Public Const NRC_NORES = &H9 ' No Resource Available
Public Const NRC_SCLOSED = &HA ' Session Closed
Public Const NRC_CMDCAN = &HB ' Command Cancelled
Public Const NRC_DUPNAME = &HD ' Duplicate Name
Public Const NRC_NAMTFUL = &HE ' Name Table Full
Public Const NRC_ACTSES = &HF ' No Deletions, Name has Active
' Sessions
Public Const NRC_LOCTFUL = &H11 ' Local Session Table Full
Public Const NRC_REMTFUL = &H12 ' Remote Session Table Full
Public Const NRC_ILLNN = &H13 ' Illegal Name Number
Public Const NRC_NOCALL = &H14 ' No Call Name
Public Const NRC_NOWILD = &H15 ' Cannot Put in NCB_NAME
Public Const NRC_INUSE = &H16 ' Name in Use on Remote Adapter
Public Const NRC_NAMERR = &H17 ' Name Deleted
Public Const NRC_SABORT = &H18 ' Session Ended Abnormally
Public Const NRC_NAMCONF = &H19 ' Name Conflict Detected
Public Const NRC_IFBUSY = &H21 ' Interface Busy, IRET before
' Retrying
Public Const NRC_TOOMANY = &H22 ' Too Many Commands outstanding,
' Retry later
Public Const NRC_BRIDGE = &H23 ' ncb_lana_num field invalid
Public Const NRC_CANOCCR = &H24 ' Command Completed While Cancel
' Occurring
Public Const NRC_CANCEL = &H26 ' Command Not Valid to Cancel
Public Const NRC_DUPENV = &H30 ' Name Defined By Another Local
' Process
Public Const NRC_ENVNOTDEF = &H34 ' Envirnment Undefined. RESET
' Required
Public Const NRC_OSRESNOTAV = &H35 ' Required OS Resources Exhausted
Public Const NRC_MAXAPPS = &H36 ' Max Number of Applications
' Exceeded
Public Const NRC_NOSAPS = &H37 ' No Saps Available for NetBIOS
Public Const NRC_NORESOURCES = &H38 ' Requested Resources are Not
' Available
Public Const NRC_INVADDRESS = &H39 ' Invalid NCB Address, or
' Length > Segment
Public Const NRC_INVDDID = &H3B ' Invalid NCB DDID
Public Const NRC_LOCKFAIL = &H3C ' Lock of User Area Failed
Public Const NRC_OPENERR = &H3F ' NetBIOS Not Loaded
Public Const NRC_SYSTEM = &H40 ' System Error
Public Const NRC_PENDING = &HFF ' Asynchronous Command is Not Yet
' Fulfilled
' State Values
Public Const LISTEN_OUTSTANDING = &H1
Public Const CALL_PENDING = &H2
Public Const SESSION_ESTABLISHED = &H3
Public Const HANGUP_PENDING = &H4
Public Const HANGUP_COMPLETE = &H5
Public Const SESSION_ABORTED = &H6
' NCB User Defined Types (structures)
Type SESSION_HEADER
sess_name As Byte
num_sess As Byte
rcv_dg_outstanding As Byte
rcv_any_outstanding As Byte
End Type
' The structure returned to the NCB Command NCBSTAT is SESSION_HEADER
' followed by an array of SESSION_BUFFER structures. If the NCB_NAME
' starts with an asterisk, then an array of these structures is returned
' containing the status for all names.
Public SESSION_HEADER As SESSION_HEADER
Public PSESSION_HEADER As SESSION_HEADER
Type SESSION_BUFFER
lsn As Byte
state As Byte
local_name As String * NCBNAMSZ
remote_name As String * NCBNAMSZ
rcvs_outstanding As Byte
sends_outstanding As Byte
End Type
' Structure returned to the NCB command NCBFINDNAME is
' FIND_NAME_HEADER, followed by an array of FIND_NAME_BUFFER
' structures.
Public SESSION_BUFFER As SESSION_BUFFER
Public PSESSION_BUFFER As SESSION_BUFFER
Type FIND_NAME_HEADER
node_count As Long
reserved As Byte
unique_group As Byte
End Type
Public FIND_NAME_HEADER As FIND_NAME_HEADER
Public PFIND_NAME_HEADER As FIND_NAME_HEADER
Type FIND_NAME_BUFFER
length As Byte
access_control As Byte
frame_control As Byte
destination_addr(0 To 5) As Byte
source_addr(0 To 5) As Byte
routing_info(0 To 17) As Byte
End Type
Public FIND_NAME_BUFFER As FIND_NAME_BUFFER
Public PFIND_NAME_BUFFER As FIND_NAME_BUFFER
Type ACTION_HEADER
transport_id As Long ' ULONG
action_code As Integer ' USHORT
reserved As Integer ' USHORT
End Type
' Structures provided with NCBACTION. The purpose of NCBACTION is
' to provide transport specific extensions to NetBIOS.
Public ACTION_HEADER As ACTION_HEADER
Public PACTION_HEADER As ACTION_HEADER
' Values for trasport_id in Type ACTION_HEADER
Public Const ALL_TRANSPORTS = "M\0\0\0"
Public Const MS_NBF = "MNBF"
Type NCB
ncb_command As Byte ' 1-byte UCHAR
ncb_retcode As Byte ' 1-byte UCHAR
ncb_lsn As Byte ' 1-byte UCHAR
ncb_num As Byte ' 1-byte UCHAR
ncb_buffer As Long ' 4-bytes PUCHAR
ncb_length As Integer ' 2-bytes WORD
ncb_callname As String * NCBNAMSZ ' 16-bytes
ncb_name As String * NCBNAMSZ ' 16-bytes
ncb_rto As Byte ' 1-byte
ncb_sto As Byte ' 1-byte
ncb_post As Long ' 4-bytes
ncb_lana_num As Byte ' 1-byte
ncb_cmd_cplt As Byte ' 1-byte
ncb_reserve(0 To 9) As Byte ' 10-bytes Reserved for BIOS, must be 0
ncb_event As Long ' 4-bytes
End Type ' 64-bytes
Public NCB As NCB
Public PNCB As NCB
Type ADAPTER_STATUS
adapter_address(0 To 5) As Byte ' 6-bytes UCHAR Array
rev_major As Byte ' 1
reserved0 As Byte ' 1
adapter_type As Byte ' 1
rev_minor As Byte ' 1
duration As Integer ' 2
frmr_recv As Integer ' 2
frmr_xmit As Integer ' 2
iframe_recv_err As Integer ' 2
xmit_aborts As Integer ' 2
xmit_success As Long ' 4
recv_success As Long ' 4
iframe_xmit_err As Integer ' 2
recv_buff_unavail As Integer ' 2
t1_timeouts As Integer ' 2
ti_timeouts As Integer ' 2
Reserved1 As Long ' 4
free_ncbs As Integer ' 2
max_cfg_ncbs As Integer ' 2
max_ncbs As Integer ' 2
xmit_buf_unavail As Integer ' 2
max_dgram_size As Integer ' 2
pending_sess As Integer ' 2
max_cfg_sess As Integer ' 2
max_sess As Integer ' 2
max_sess_pkt_size As Integer ' 2
name_count As Integer ' 2
End Type ' 60-bytes total
' Structure returned to the NCB command NCBASTAT is ADAPTER_STATUS,
' followed by an array of NAME_BUFFER structures.
Public ADAPTER_STATUS As ADAPTER_STATUS
Public PADAPTER_STATUS As ADAPTER_STATUS
Type NAME_BUFFER ' NCBNAMSZ = 16
name_(0 To (NCBNAMSZ - 1)) As Byte ' 16-bytes
name_num As Byte ' 1-byte
name_flags As Byte ' 1-byte
End Type ' 18-bytes total
' Values for name_flags bits
Public Const NAME_FLAGS_MASK = &H87
Public Const GROUP_NAME = &H80
Public Const UNIQUE_NAME = &H0
Public Const REGISTERING = &H0
Public Const DEREGISTERED = &H4
Public Const DUPLICATE = &H5
Public Const DUPLICATE_DEREG = &H7
Public NAME_BUFFER As NAME_BUFFER
Public PNAME_BUFFER As NAME_BUFFER
Type LANA_ENUM
length As Byte ' 1-byte (Number of valid entries in lana[]
lana(0 To (MAX_LANA - 1)) As Byte ' 256-bytes
End Type ' 257-bytes total
' Command NCBENUM returns:
' On a system containing lana's 0,2 and 3, a structure with
' length=3, lan[0] = 0, lana[1] = 1 and lana[2] = 3 will be
' returned.
Public LANA_ENUM As LANA_ENUM
Public PLANA_ENUM As LANA_ENUM
Type NET_STATUS
ADAPTER_STATUS As ADAPTER_STATUS ' 60-bytes for ADAPTER_STATUS
NAME_BUFFER(0 To (NCBNAMSZ + 1)) As NAME_BUFFER ' 18-bytes for NAME_BUFFER UDT
End Type ' 78-bytes total
Public NET_STATUS As NET_STATUS
Declare Function NetBios Lib "NetAPI32.dll" Alias "Netbios" (ByRef PNCB As NCB) As Long
' The following lines of code were modified by Jim Huff on May 18, 1998 to include
' the location of the VarPtr function call for those who are using vb5.0
' The following VarPtr function call is for vb5.
' Declare Function VarPtr Lib "MSVBVM50.DLL" (pVoid As Any) As Long
' The following VarPtr function call is for vb4.
Declare Function VarPtr Lib "VB40032.dll" (pVoid As Any) As Long
Function vbGetMacAddress(Adapter As Integer, HostName As String) As String
If Adapter >= MAX_LANA Then
MsgBox "ERROR: Illegal lana has been designated. Must be less than 254.", vbOKOnly, "vbNetBIOS.BAS Demo"
vbGetMacAddress = ""
Exit Function
End If
' This function returns the MAC Address to the calling procedure when provided with
' the LanaEnum (Adapter) number.
Dim lResult As Long
Dim MACAddr As String
Dim HexStringValue As String
Dim i As Integer
MACAddr = ""
NCB.ncb_command = NCBENUM ' Enumerate lana numbers
NCB.ncb_buffer = VarPtr(LANA_ENUM)
NCB.ncb_length = LenB(LANA_ENUM)
lResult = NetBios(NCB)
DisplayError lResult
Debug.Print "Enumerate lana Numbers Result: " & lResult
NCB.ncb_command = NCBRESET ' Reset
NCB.ncb_lana_num = LANA_ENUM.lana(Adapter)
lResult = NetBios(NCB)
DisplayError lResult
NCB.ncb_command = NCBASTAT ' Adapter Status
NCB.ncb_lana_num = LANA_ENUM.lana(Adapter)
' Use the following lines to identify a remote host
NCB.ncb_callname = UCase(HostName) + Space(16 - Len(HostName))
NCB.ncb_buffer = VarPtr(NET_STATUS)
NCB.ncb_length = LenB(NET_STATUS)
lResult = NetBios(NCB)
DisplayError lResult
Debug.Print "Adapter Status Result: " & lResult
For i = 0 To 5
HexStringValue = Hex(NET_STATUS.ADAPTER_STATUS.adapter_address(i))
If NET_STATUS.ADAPTER_STATUS.adapter_address(i) < 16 Then HexStringValue = "0" & HexStringValue
MACAddr = MACAddr + HexStringValue
If i <> 5 Then MACAddr = MACAddr + "-"
Next i
vbGetMacAddress = MACAddr
End Function
Sub DisplayError(ResultCode As Long)
Dim DispMsg As String
Select Case ResultCode
Case NRC_GOODRET ' Good return (also returned when
Exit Sub ' ASYNCH request accepted)
Case NRC_BUFLEN ' Illegal Buffer Length
DispMsg = "Illegal Buffer Length"
Case NRC_ILLCMD ' Illegal Command
DispMsg = "Illegal Command"
Case NRC_CMDTMO ' Command Timed Out
DispMsg = "Command Timed Out"
Case NRC_INCOMP ' Message Incomplete, Issue Another
' Command
DispMsg = "Message Incomplete. Issue Another Command"
Case NRC_BADDR ' Illegal Buffer Address
DispMsg = "Illegal Buffer Address"
Case NRC_SNUMOUT ' Session Number is Out Of Range
DispMsg = "Session Number is Out of Range"
Case NRC_NORES ' No Resource Available
DispMsg = "No Resources Available"
Case NRC_SCLOSED ' Session Closed
DispMsg = "Session Closed"
Case NRC_CMDCAN ' Command Cancelled
DispMsg = "Command Cancelled"
Case NRC_DUPNAME ' Duplicate Name
DispMsg = "Duplicate Name"
Case NRC_NAMTFUL ' Name Table Full
DispMsg = "Name Table Full"
Case NRC_ACTSES ' No Deletions, Name has Active
' Sessions
DispMsg = "No Deletions. Name has Active Sessions"
Case NRC_LOCTFUL ' Local Session Table Full
DispMsg = "Local Session Table Full"
Case NRC_REMTFUL ' Remote Session Table Full
DispMsg = "Remote Session Table Full"
Case NRC_ILLNN ' Illegal Name Number
DispMsg = "Illegal Name Number"
Case NRC_NOCALL ' No Call Name
DispMsg = "No Call Name"
Case NRC_NOWILD ' Cannot Put in NCB_NAME
DispMsg = "Cannot Put in NCB_NAME"
Case NRC_INUSE ' Name in Use on Remote Adapter
DispMsg = "Name in Use on Remote Computer"
Case NRC_NAMERR ' Name Deleted
DispMsg = "Name Deleted"
Case NRC_SABORT ' Session Ended Abnormally
DispMsg = "Session Ended Abnormally"
Case NRC_NAMCONF ' Name Conflict Detected
DispMsg = "Name Conflict Detected"
Case NRC_IFBUSY ' Interface Busy, IRET before
' Retrying
DispMsg = "Interface Busy. IRET Before Retrying"
Case NRC_TOOMANY ' Too Many Commands outstanding,
' Retry later
DispMsg = "Too Many Commands Outstanding. Retry Later"
Case NRC_BRIDGE ' ncb_lana_num field invalid
DispMsg = "ncb_lana_num Field Invalid"
Case NRC_CANOCCR ' Command Completed While Cancel
' Occurring
DispMsg = "Command Completed While Cancel Occurring"
Case NRC_CANCEL ' Command Not Valid to Cancel
DispMsg = "Command Not Valid to Cancel"
Case NRC_DUPENV ' Name Defined By Another Local
' Process
DispMsg = "Name Defined By Another Process"
Case NRC_ENVNOTDEF ' Environment Undefined. RESET
' Required
DispMsg = "Environment Undefined. RESET Required"
Case NRC_OSRESNOTAV ' Required OS Resources Exhausted
DispMsg = "Required OS Resources Exhausted"
Case NRC_MAXAPPS ' Max Number of Applications
' Exceeded
DispMsg = "Max Number Of Applications Exceeded"
Case NRC_NOSAPS ' No Saps Available for NetBIOS
DispMsg = "No saps Available for NetBIOS"
Case NRC_NORESOURCES ' Requested Resources are Not
' Available
DispMsg = "Requested Resources are Not Available"
Case NRC_INVADDRESS ' Invalid NCB Address, or
' Length > Segment
DispMsg = "Invalid NCB Address, or Length > Segment"
Case NRC_INVDDID ' Invalid NCB DDID
DispMsg = "Invalid NCB DDID"
Case NRC_LOCKFAIL ' Lock of User Area Failed
DispMsg = "Lock of User Area Failed"
Case NRC_OPENERR ' NetBIOS Not Loaded
DispMsg = "NetBIOS Not Loaded"
Case NRC_SYSTEM ' System Error
DispMsg = "System Error"
Case NRC_PENDING ' Asynchronous Command is Not Yet
' Completed
DispMsg = "Asynchronous Command Is Not Yet Completed"
End Select
MsgBox "ERROR: " + CStr(ResultCode) + Chr$(13) + Chr$(10) + DispMsg, vbOKOnly, "vbNetBIOS.BAS Demo"
End Sub