jcifs.netbios
Class NbtNameServiceClient

java.lang.Object
  |
  +--jcifs.netbios.NbtNameServiceClient

public class NbtNameServiceClient
extends Object

Applications should use the NbtAddress class for interacting with the netbios. This class is for lower-level control over the name service and would only be usefull for netbios centric tools.

This class provides the name service functionality for the netbios networking protocol. The netbios name service is a dynamic distributed service that allows hosts to resolve names by broadcasting a query, directing querys to a server such as Samba or WINS. A netbios name consists of two parts, a 15 character string and a 1 byte type. A netbios node usually registers several names on the network. You can see what names a Windows machine registers with the nbtstat command.

 C:\>nbtstat -a 192.168.1.15
 
        NetBIOS Remote Machine Name Table
 
    Name               Type         Status
 ---------------------------------------------
 ANGUS          <00>  UNIQUE      Registered
 RSCH-NY        <00>  GROUP       Registered
 ANGUS          <03>  UNIQUE      Registered
 ANGUS          <20>  UNIQUE      Registered
 RSCH-NY        <1E>  GROUP       Registered
 MIALLEN        <03>  UNIQUE      Registered
 
 MAC Address = 00-A0-34-21-FA-3B
 

The hostname of this machine is ANGUS. It is a member of the group(or workgroup) RSCH-NY. The hexadecimal values are the names types. The types correspond to the services that the host provides. Usually the <00> type is the only of interest as it is registered by all hosts. Here is a list of what services correspond to what hex codes.

Since:
jcifs-0.1
Author:
Michael B. Allen

Constructor Summary
NbtNameServiceClient()
          Instantiate a new client.
NbtNameServiceClient(int port)
          Instantiate a new client.
NbtNameServiceClient(int port, InetAddress laddr)
          Instantiate a new client.
 
Method Summary
 NbtAddress[] getAllByName(String name)
          Resloves the addresses of all hosts given a name(presumably a workgroup name).
 NbtAddress[] getAllByName(String name, int type, String scope, boolean recurDesired)
          Resloves the addresses of all hosts given a hostname(presumably a workgroup name).
 NbtAddress getByName(String name)
          Determines the address of a host given it's host name.
 NbtAddress getByName(String name, int type, String scope, boolean recurDesired)
          Determines the address of a host given it's host name.
 NbtAddress getLocalHostName()
          Retrieve the local host name.
 NbtAddress[] getNodeStatus(NbtAddress addr)
          Do a node status on an address.
 void setLocalHostName(String name, String scope)
          Set the local host name that the client uses when connecting to other hosts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NbtNameServiceClient

public NbtNameServiceClient()
                     throws SocketException
Instantiate a new client. The name service client will not bind the port until a request is issued. The underlying socket will timeout and close after 30 seconds of incativity.
Throws:
SocketException - if the MultiDatagramSocket cannot be started

NbtNameServiceClient

public NbtNameServiceClient(int port)
                     throws SocketException
Instantiate a new client. The name service client will not bind the port until a request is issued. The underlying socket will timeout and close after 30 seconds of incativity.
Parameters:
port - the port the client should bind to.
Throws:
SocketException - if the MultiDatagramSocket cannot be started

NbtNameServiceClient

public NbtNameServiceClient(int port,
                            InetAddress laddr)
                     throws SocketException
Instantiate a new client. The name service client will not bind the port until a request is issued. The underlying socket will timeout and close after 30 seconds of incativity.
Parameters:
port - the port the client should run on
laddr - the address of the interface the client should bind
Throws:
SocketException - if the MultiDatagramSocket cannot be started
Method Detail

setLocalHostName

public void setLocalHostName(String name,
                             String scope)
Set the local host name that the client uses when connecting to other hosts. The scope is likely not used and can therefore be and empty string or null. If the name parameter is empty or null a name will try resolve the name of the machine using standard netbios queries. If that fails the first label of the DNS name is use. If that fails the name JCIFS_XXX is used where XXX is a random number.
Parameters:
name - the name this client should masquarade as
scope - the scope of the client's name. This is generally not used but if it is, it must be set

getLocalHostName

public NbtAddress getLocalHostName()
Retrieve the local host name.
See Also:
setLocalHostName(String name, String scope)

getByName

public NbtAddress getByName(String name)
                     throws UnknownNbtHostException
Determines the address of a host given it's host name. The name can be a machine name like "jcifs.samba.org" or an IP address like "192.168.1.15".
Parameters:
name - hostname to resolve
Throws:
UnknownNbtHostException - if there is an error resolving the name

getByName

public NbtAddress getByName(String name,
                            int type,
                            String scope,
                            boolean recurDesired)
                     throws UnknownNbtHostException
Determines the address of a host given it's host name. Netbios names also have a type. Types(aka Hex Codes) are used to distiquish the various services on a host. Here is a fairly complete list of netbios hex codes. Scope is not used but is still functional on Windows machines and so for completeness it has been implemented. A scope of null or "" signifies no scope.
Parameters:
name - the name to resolve
type - the hex code of the name
scope - the scope of the name
is - recursion desired
Throws:
UnknownNbtHostException - if there is an error resolving the name

getAllByName

public NbtAddress[] getAllByName(String name)
                          throws UnknownNbtHostException
Resloves the addresses of all hosts given a name(presumably a workgroup name).
Parameters:
name - groupname to lookup
Throws:
UnknownNbtHostException - if there is an error resolving the name

getAllByName

public NbtAddress[] getAllByName(String name,
                                 int type,
                                 String scope,
                                 boolean recurDesired)
                          throws UnknownNbtHostException
Resloves the addresses of all hosts given a hostname(presumably a workgroup name). See getByName(java.lang.String) for a description of type and scope.
Parameters:
name - group name to lookup
type - the hexcode of the name
is - recursion desired
Throws:
UnknownNbtHostException - if there is an error resolving the name

getNodeStatus

public NbtAddress[] getNodeStatus(NbtAddress addr)
                           throws UnknownNbtHostException
Do a node status on an address.
Parameters:
addr - the address to do a node status on
Throws:
UnknownNbtHostException - if the address does not respond
See Also:
NbtAddress.getAllByAddress( NbtAddress addr )