public final class NetBIOSSession extends NetworkSession
Holds the details of a TCP/IP NetBIOS session connection to a remote NetBIOS service.
The session is usually used to send higher level requests such as SMB/CIFS requests to a file server service.
Contains a number of static methods for performing name lookups of remote servers/services.
Modifier and Type | Field and Description |
---|---|
static int |
DNSOnly |
static char |
JVMIdChar |
static int |
MaxCallerNameTemplateLength |
static char |
SessionIdChar |
static String |
ValidTemplateChars |
static int |
WINSAndDNS |
static int |
WINSOnly |
Constructor and Description |
---|
NetBIOSSession()
NetBIOS session class constructor.
|
NetBIOSSession(int tmo)
NetBIOS session class constructor
|
NetBIOSSession(int tmo,
int port,
int namePort)
NetBIOS session class constructor
|
Modifier and Type | Method and Description |
---|---|
void |
Close()
Close the NetBIOS session.
|
static NetBIOSName |
ConvertAddressToName(String addr,
char nbTyp,
boolean isGroup)
Convert a TCP/IP address to a NetBIOS or host name
|
static NetBIOSName |
ConvertAddressToName(String addr,
char nbTyp,
boolean isGroup,
NetBIOSSession sess)
Convert a TCP/IP address to a NetBIOS or host name
|
static String |
ConvertName(String hostName)
Convert a host name string into RFC NetBIOS format.
|
static String |
ConvertName(String hostName,
char nameType)
Convert a host name string into RFC NetBIOS format.
|
static String |
DecodeName(byte[] buf,
int off)
Convert an encoded NetBIOS name to a normal name string
|
static String |
DecodeName(String encnam)
Convert an encoded NetBIOS name to a normal name string
|
static int |
EncodeName(String hostName,
char nameType,
byte[] buf,
int off)
Convert a host name string into RFC NetBIOS format.
|
protected void |
finalize()
Finalize the NetBIOS session object
|
static NetBIOSName |
FindName(NetBIOSName nbName,
int tmo)
Find a NetBIOS name on the network
|
static NetBIOSName |
FindName(NetBIOSName nbName,
int tmo,
int lookupTypes,
NetBIOSSession sess)
Find a NetBIOS name on the network
|
static NetBIOSName |
FindName(NetBIOSName nbName,
int tmo,
NetBIOSSession sess)
Find a NetBIOS name on the network
|
static NetBIOSName |
FindName(String nbName,
char nbType,
int tmo)
Find a NetBIOS name on the network
|
static NetBIOSName |
FindName(String nbName,
char nbType,
int tmo,
NetBIOSSession sess)
Find a NetBIOS name on the network
|
static StringList |
FindNameList(String nbName,
char nbType,
int tmo)
Build a list of nodes that own the specified NetBIOS name.
|
static StringList |
FindNameList(String nbName,
char nbType,
int tmo,
NetBIOSSession sess)
Build a list of nodes that own the specified NetBIOS name.
|
static NetBIOSNameList |
FindNamesForAddress(String ipAddr)
Get the NetBIOS name list for the specified IP address
|
static NetBIOSNameList |
FindNamesForAddress(String ipAddr,
NetBIOSSession sess)
Get the NetBIOS name list for the specified IP address
|
static String |
GenerateSubnetMask(String addr)
Determine the subnet mask from the local hosts TCP/IP address
|
static int |
getDefaultLookupTimeout()
Get the WINS/NetBIOS name lookup timeout, in milliseconds.
|
static int |
getDefaultLookupType()
Return the name lookup type that is used when setting up new sessions, valid values
are DNSOnly, WINSOnly, WINSAndDNS.
|
static String |
getDefaultSubnetMask()
Return the subnet mask string
|
static boolean |
getDefaultWildcardFileServerName()
Return the default setting for the use wildcard file server name setting
|
static InetAddress |
getDefaultWINSServer()
Return the WINS server address
|
static int |
getJVMIndex()
Return the JVM unique id, used when generating caller names
|
char |
getLocalNameType()
Return the local NetBIOS name type.
|
int |
getLookupTimeout()
Return the name lookup timeout, in milliseconds
|
int |
getLookupType()
Return the name lookup type(s) to use
|
int |
getNamePort()
Return the name port
|
char |
getRemoteNameType()
Return the remote NetBIOS name type.
|
int |
getSessionPort()
Get the NetBIOS session port to connect to
|
String |
getSubnetMask()
Return the subnet mask
|
InetAddress |
getWINSServer()
Return the WINS server address
|
boolean |
hasData()
Check if there is data available on this network session
|
static boolean |
hasDefaultWINSServer()
Determine if the WINS server address is configured
|
boolean |
hasWINSServer()
Check if WINS server is configured
|
boolean |
isConnected()
Determine if the session is connected to a remote host
|
static boolean |
isDebug()
Determine if SMB session debugging is enabled
|
static String |
NetBIOSName(String hostName)
Convert the TCP/IP host name to a NetBIOS name string.
|
void |
Open(String remHost,
String locName,
String remAddr)
Connect to a remote host.
|
int |
Receive(byte[] buf)
Receive a data packet from the remote host.
|
boolean |
Send(byte[] data,
int siz)
Send a data packet to the remote host.
|
static void |
setCallerNameTemplate(String template)
Set the caller session name template string that is appended to the local host name to create a unique caller
name.
|
static void |
setDebug(boolean dbg)
Enable/disable NetBIOS session debugging
|
static void |
setDefaultLookupTimeout(int tmo)
Set the WINS/NetBIOS name lookup timeout value, in milliseconds.
|
static void |
setDefaultLookupType(int typ)
Set the name lookup type(s) to be used when opening new sessions, valid values
are DNSOnly, WINSOnly, WINSAndDNS.
|
static void |
setDefaultSubnetMask(String subnet)
Set the subnet mask string
|
static void |
setDefaultWildcardFileServerName(boolean useWildcard)
Set the default use wildcard file server name flag.
|
static void |
setDefaultWINSServer(InetAddress addr)
Set the WINS server address
|
static void |
setJVMIndex(int jvmIdx)
Set the JVM index, used to generate unique caller names when multiple JVMs are run on the same host.
|
void |
setLocalNameType(char nameType)
Set the local NetBIOS name type for this session.
|
void |
setLookupTimeout(int tmo)
Override the name lookup timeout, in milliseconds
|
void |
setLookupType(int lookupTyp)
Override the name lookup type(s) to use
|
void |
setRemoteNameType(char nameType)
Set the remote NetBIOS name type.
|
void |
setSessionPort(int port)
Override the NetBIOS session port to connect to
|
void |
setSubnetMask(String mask)
Override the default subnet mask
|
void |
setTimeout(int tmo)
Set the socket timeout
|
void |
setWildcardFileServerName(boolean useWildcard)
Set the use wildcard file server name flag.
|
void |
setWINSServer(InetAddress addr)
Override the default WINS server address
|
boolean |
useWildcardFileServerName()
Return the use wildcard file server name flag status.
|
getDefaultTimeout, getProtocolName, getTimeout, setDefaultTimeout
public static final int DNSOnly
public static final int WINSOnly
public static final int WINSAndDNS
public static final int MaxCallerNameTemplateLength
public static final char SessionIdChar
public static final char JVMIdChar
public static final String ValidTemplateChars
public NetBIOSSession()
public NetBIOSSession(int tmo)
tmo
- Send/receive timeout value in millisecondspublic NetBIOSSession(int tmo, int port, int namePort)
tmo
- Send/receive timeout value in millisecondsport
- Remote port to connect tonamePort
- Name lookup port to usepublic final int getSessionPort()
public final int getNamePort()
public final int getLookupType()
public final int getLookupTimeout()
public final boolean hasWINSServer()
public final InetAddress getWINSServer()
public final String getSubnetMask()
public final boolean isConnected()
isConnected
in class NetworkSession
public final boolean hasData() throws IOException
hasData
in class NetworkSession
IOException
public static String ConvertName(String hostName)
hostName
- Host name to be converted.public static String ConvertName(String hostName, char nameType)
hostName
- Host name to be converted.nameType
- NetBIOS name type, added as the 16th byte of the name
before conversion.public static String DecodeName(byte[] buf, int off)
buf
- Buffer that contains the NetBIOS encoded nameoff
- Offset that the name starts within the bufferpublic static String DecodeName(String encnam)
encnam
- RFC NetBIOS encoded namepublic static int EncodeName(String hostName, char nameType, byte[] buf, int off)
hostName
- Host name to be converted.nameType
- NetBIOS name type, added as the 16th byte of the name
before conversion.buf
- Buffer to write the encoded name into.off
- Offset within the buffer to start writing.public static NetBIOSName FindName(String nbName, char nbType, int tmo, NetBIOSSession sess) throws IOException
nbName
- NetBIOS name to search for, not yet RFC encodednbType
- Name type, appended as the 16th byte of the nametmo
- Timeout value for receiving incoming datagramssess
- NetBIOS session to use to override various settingsIOException
- If an I/O error occurspublic static NetBIOSName FindName(String nbName, char nbType, int tmo) throws IOException
nbName
- NetBIOS name to search for, not yet RFC encodednbType
- Name type, appended as the 16th byte of the nametmo
- Timeout value for receiving incoming datagramsIOException
- If an I/O error occurspublic static NetBIOSName FindName(NetBIOSName nbName, int tmo) throws IOException
nbName
- NetBIOS name to search fortmo
- Timeout value for receiving incoming datagramsIOException
- If an I/O error occurspublic static NetBIOSName FindName(NetBIOSName nbName, int tmo, NetBIOSSession sess) throws IOException
nbName
- NetBIOS name to search fortmo
- Timeout value for receiving incoming datagramssess
- NetBIOS session to use to override various settingsIOException
- If an I/O error occurspublic static NetBIOSName FindName(NetBIOSName nbName, int tmo, int lookupTypes, NetBIOSSession sess) throws IOException
nbName
- NetBIOS name to search fortmo
- Timeout value for receiving incoming datagramslookupTypes
- Types of name lookup to use (DNS and/or NetBIOS)sess
- NetBIOS session to use to override various settingsIOException
- If an I/O error occurspublic static StringList FindNameList(String nbName, char nbType, int tmo) throws IOException
nbName
- NetBIOS name to search for, not yet RFC encodednbType
- Name type, appended as the 16th byte of the nametmo
- Timeout value for receiving incoming datagramsIOException
- If an I/O error occurspublic static StringList FindNameList(String nbName, char nbType, int tmo, NetBIOSSession sess) throws IOException
nbName
- NetBIOS name to search for, not yet RFC encodednbType
- Name type, appended as the 16th byte of the nametmo
- Timeout value for receiving incoming datagramssess
- NetBIOS session to use to override various settingsIOException
- If an I/O error occurspublic static NetBIOSNameList FindNamesForAddress(String ipAddr) throws UnknownHostException, SocketException
ipAddr
- StringUnknownHostException
SocketException
public static NetBIOSNameList FindNamesForAddress(String ipAddr, NetBIOSSession sess) throws UnknownHostException, SocketException
ipAddr
- Stringsess
- NetBIOSSessionUnknownHostException
SocketException
public static final NetBIOSName ConvertAddressToName(String addr, char nbTyp, boolean isGroup) throws UnknownHostException, SocketException, IOException
addr
- StringnbTyp
- charisGroup
- booleanUnknownHostException
- If the name cannot be converted using a DNS lookupSocketException
- If there is an error searching for the NetBIOS nameIOException
- If a name conversion failspublic static final NetBIOSName ConvertAddressToName(String addr, char nbTyp, boolean isGroup, NetBIOSSession sess) throws UnknownHostException, SocketException, IOException
addr
- StringnbTyp
- charisGroup
- booleansess
- NetBIOS session to use to override various settingsUnknownHostException
- If the name cannot be converted using a DNS lookupSocketException
- If there is an error searching for the NetBIOS nameIOException
- If a name conversion failspublic static String GenerateSubnetMask(String addr) throws UnknownHostException
addr
- TCP/IP address to set the subnet mask for, in 'nnn.nnn.nnn.nnn'
format.UnknownHostException
public static int getDefaultLookupTimeout()
public static int getDefaultLookupType()
public static String getDefaultSubnetMask()
public static final boolean hasDefaultWINSServer()
public static final InetAddress getDefaultWINSServer()
public static boolean isDebug()
public static final int getJVMIndex()
public static String NetBIOSName(String hostName)
hostName
- java.lang.Stringpublic final void setSessionPort(int port)
port
- intpublic final void setLookupType(int lookupTyp)
lookupTyp
- intpublic final void setLookupTimeout(int tmo)
tmo
- intpublic final void setWINSServer(InetAddress addr)
addr
- InetAddresspublic final void setSubnetMask(String mask)
mask
- Stringpublic static void setDebug(boolean dbg)
dbg
- true to enable debugging, else falsepublic static void setDefaultLookupTimeout(int tmo)
tmo
- intpublic static void setDefaultLookupType(int typ)
typ
- intpublic static void setDefaultSubnetMask(String subnet)
subnet
- Subnet mask string, in 'nnn.nnn.nnn.nnn' formatpublic static final void setDefaultWINSServer(InetAddress addr)
addr
- InetAddresspublic void Open(String remHost, String locName, String remAddr) throws IOException, UnknownHostException
Open
in class NetworkSession
remHost
- Remote host node name/NetBIOS name.locName
- Local name/NetBIOS name.remAddr
- Optional remote address, if null then lookup will be done to convert name to addressIOException
- I/O error occurred.UnknownHostException
- Remote host is unknown.public char getLocalNameType()
public char getRemoteNameType()
public void Close() throws IOException
Close
in class NetworkSession
IOException
- If an I/O error occurspublic int Receive(byte[] buf) throws IOException
Receive
in class NetworkSession
buf
- Byte buffer to receive the data into.IOException
- I/O error occurred.public boolean Send(byte[] data, int siz) throws IOException
Send
in class NetworkSession
data
- Byte array containing the data to be sent.siz
- Length of the data to send.IOException
- I/O error occurred.public void setTimeout(int tmo)
setTimeout
in class NetworkSession
tmo
- intpublic void setLocalNameType(char nameType)
nameType
- intpublic void setRemoteNameType(char nameType)
nameType
- charpublic static final void setCallerNameTemplate(String template) throws NameTemplateException
template
- StringNameTemplateException
public static final void setJVMIndex(int jvmIdx)
jvmIdx
- intpublic final boolean useWildcardFileServerName()
public final void setWildcardFileServerName(boolean useWildcard)
useWildcard
- booleanpublic static final boolean getDefaultWildcardFileServerName()
public static final void setDefaultWildcardFileServerName(boolean useWildcard)
useWildcard
- booleanCopyright © 2005–2018 Alfresco Software. All rights reserved.