Package jcifs.netbios

# Class NbtAddress

java.lang.Object
jcifs.netbios.NbtAddress

public final class NbtAddress extends Object
This class represents a NetBIOS over TCP/IP address. Under normal conditions, users of jCIFS need not be concerned with this class as name resolution and session services are handled internally by the smb package.

Applications can use the methods `getLocalHost`, `getByName`, and `getAllByAddress` to create a new NbtAddress instance. This class is symmetric with `InetAddress`.

About NetBIOS: The NetBIOS name service is a dynamic distributed service that allows hosts to resolve names by broadcasting a query, directing queries to a server such as Samba or WINS. NetBIOS is currently the primary networking layer for providing name service, datagram service, and session service to the Microsoft Windows platform. A NetBIOS name can be 15 characters long and hosts usually registers several names on the network. From a Windows command prompt you can see what names a host registers with the nbtstat command.

>      C:\>nbtstat -a 192.168.1.15

>             NetBIOS Remote Machine Name Table

>         Name               Type         Status
>      ---------------------------------------------
>      JMORRIS2        invalid input: '<'00>  UNIQUE      Registered
>      BILLING-NY      invalid input: '<'00>  GROUP       Registered
>      JMORRIS2        invalid input: '<'03>  UNIQUE      Registered
>      JMORRIS2        invalid input: '<'20>  UNIQUE      Registered
>      BILLING-NY      invalid input: '<'1E>  GROUP       Registered
>      JMORRIS         invalid input: '<'03>  UNIQUE      Registered

>      MAC Address = 00-B0-34-21-FA-3B

The hostname of this machine is `JMORRIS2`. It is a member of the group(a.k.a workgroup and domain) `BILLING-NY`. To obtain an `InetAddress` for a host one might do:

       InetAddress addr = NbtAddress.getByName( "jmorris2" ).getInetAddress();

From a UNIX platform with Samba installed you can perform similar diagnostics using the `nmblookup` utility.

Since:
  jcifs-0.1
Author:
  Michael B. Allen
See Also:
  - `InetAddress`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`B_NODE`
A B node only broadcasts name queries.
`static final int`
`H_NODE`
A Hybrid node tries to resolve a name using the nameserver first.
`static final int`
`M_NODE`
Try Broadcast queries first, then try to resolve the name using the nameserver.
`static final String`
`MASTER_BROWSER_NAME`
This is a special name for querying the master browser that serves the list of hosts found in "Network Neighborhood".
`static final int`
`P_NODE`
A Point-to-Point node, or P node, unicasts queries to a nameserver only.
`static final String`
`SMBSERVER_NAME`
A special generic name specified when connecting to a host for which a name is not known.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`equals(Object obj)`
Determines if this address is equal two another.
`String`
`firstCalledName()`
`byte[]`
`getAddress()`
Returns the raw IP address of this NbtAddress.
`static NbtAddress[]`
`getAllByAddress(String host)`
Retrieve all addresses of a host by it's address.
`static NbtAddress[]`
`getAllByAddress(String host, int type, String scope)`
Retrieve all addresses of a host by it's address.
`static NbtAddress[]`
`getAllByAddress(NbtAddress addr)`
Retrieve all addresses of a host by it's address.
`static NbtAddress[]`
`getAllByName(String host, int type, String scope, InetAddress svr)`
`static NbtAddress`
`getByName(String host)`
Determines the address of a host given it's host name.
`static NbtAddress`
`getByName(String host, int type, String scope)`
Determines the address of a host given it's host name.
`static NbtAddress`
`getByName(String host, int type, String scope, InetAddress svr)`
`String`
`getHostAddress()`
Returns this IP adress as a `String` in the form "%d.%d.%d.%d".
`String`
`getHostName()`
The hostname of this address.
`InetAddress`
`getInetAddress()`
To convert this address to an `InetAddress`.
`static NbtAddress`
`getLocalHost()`
Retrieves the local host address.
`static jcifs.netbios.Name`
`getLocalName()`
`byte[]`
`getMacAddress()`
Retrieves the MAC address of the remote network interface.
`int`
`getNameType()`
Returned the hex code associated with this name(e.g.
`int`
`getNodeType()`
Checks the node type of this address.
`static InetAddress`
`getWINSAddress()`
`int`
`hashCode()`
Returns a hashcode for this IP address.
`boolean`
`isActive()`
Determines if this address is active.
`boolean`
`isBeingDeleted()`
Determines if this address in the process of being deleted.
`boolean`
`isGroupAddress()`
Determines if the address is a group address.
`boolean`
`isInConflict()`
Determines if this address in conflict with another address.
`boolean`
`isPermanent()`
Determines if this address is set to be permanent.
`static boolean`
`isWINS(InetAddress svr)`
`String`
`nextCalledName()`
`String`
`toString()`
Returns the `String` representaion of this address.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### MASTER_BROWSER_NAME

public static final String MASTER_BROWSER_NAME
This is a special name for querying the master browser that serves the list of hosts found in "Network Neighborhood".

See Also:
  - Constant Field Values

### SMBSERVER_NAME

public static final String SMBSERVER_NAME
A special generic name specified when connecting to a host for which a name is not known. Not all servers respond to this name.

See Also:
  - Constant Field Values

### B_NODE

public static final int B_NODE
A B node only broadcasts name queries. This is the default if a nameserver such as WINS or Samba is not specified.

See Also:
  - Constant Field Values

### P_NODE

public static final int P_NODE
A Point-to-Point node, or P node, unicasts queries to a nameserver only. Natrually the `jcifs.netbios.nameserver` property must be set.

See Also:
  - Constant Field Values

### M_NODE

public static final int M_NODE
Try Broadcast queries first, then try to resolve the name using the nameserver.

See Also:
  - Constant Field Values

### H_NODE

public static final int H_NODE
A Hybrid node tries to resolve a name using the nameserver first. If that fails use the broadcast address. This is the default if a nameserver is provided. This is the behavior of Microsoft Windows machines.

See Also:
  - Constant Field Values

## Method Details

### getLocalHost

public static NbtAddress getLocalHost() throws UnknownHostException
Retrieves the local host address.

Throws:
  `UnknownHostException` - This is not likely as the IP returned by `InetAddress` should be available

### getLocalName

public static jcifs.netbios.Name getLocalName()

### getByName

public static NbtAddress getByName(String host) throws UnknownHostException
Determines the address of a host given it's host name. The name can be a NetBIOS name like "freto" or an IP address like "192.168.1.15". It cannot be a DNS name; the analygous `UniAddress` or `InetAddress` `getByName` methods can be used for that.

Parameters:
  `host` - hostname to resolve
Throws:
  `UnknownHostException` - if there is an error resolving the name

### getByName

public static NbtAddress getByName(String host, int type, String scope) throws UnknownHostException
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 in other NetBIOS products and so for completeness it has been implemented. A `scope` of `null` or `""` signifies no scope.

Parameters:
  `host` - the name to resolve
  `type` - the hex code of the name
  `scope` - the scope of the name
Throws:
  `UnknownHostException` - if there is an error resolving the name

### getByName

public static NbtAddress getByName(String host, int type, String scope, InetAddress svr) throws UnknownHostException

Throws:
  `UnknownHostException`

### getAllByName

public static NbtAddress[] getAllByName(String host, int type, String scope, InetAddress svr) throws UnknownHostException

Throws:
  `UnknownHostException`

### getAllByAddress

public static NbtAddress[] getAllByAddress(String host) throws UnknownHostException
Retrieve all addresses of a host by it's address. NetBIOS hosts can have many names for a given IP address. The name and IP address make the NetBIOS address. This provides a way to retrieve the other names for a host with the same IP address.

Parameters:
  `host` - hostname to lookup all addresses for
Throws:
  `UnknownHostException` - if there is an error resolving the name

### getAllByAddress

public static NbtAddress[] getAllByAddress(String host, int type, String scope) throws UnknownHostException
Retrieve all addresses of a host by it's address. NetBIOS hosts can have many names for a given IP address. The name and IP address make the NetBIOS address. This provides a way to retrieve the other names for a host with the same IP address. See `getByName(java.lang.String)` for a description of `type` and `scope`.

Parameters:
  `host` - hostname to lookup all addresses for
  `type` - the hexcode of the name
  `scope` - the scope of the name
Throws:
  `UnknownHostException` - if there is an error resolving the name

### getAllByAddress

public static NbtAddress[] getAllByAddress(NbtAddress addr) throws UnknownHostException
Retrieve all addresses of a host by it's address. NetBIOS hosts can have many names for a given IP address. The name and IP address make the NetBIOS address. This provides a way to retrieve the other names for a host with the same IP address.

Parameters:
  `addr` - the address to query
Throws:
  `UnknownHostException` - if address cannot be resolved

### getWINSAddress

public static InetAddress getWINSAddress()

### isWINS

public static boolean isWINS(InetAddress svr)

### firstCalledName

public String firstCalledName()

### nextCalledName

public String nextCalledName()

### isGroupAddress

public boolean isGroupAddress() throws UnknownHostException
Determines if the address is a group address. This is also known as a workgroup name or group name.

Throws:
  `UnknownHostException` - if the host cannot be resolved to find out.

### getNodeType

public int getNodeType() throws UnknownHostException
Checks the node type of this address.

Returns:
  `B_NODE`, `P_NODE`, `M_NODE`, `H_NODE`
Throws:
  `UnknownHostException` - if the host cannot be resolved to find out.

### isBeingDeleted

public boolean isBeingDeleted() throws UnknownHostException
Determines if this address in the process of being deleted.

Throws:
  `UnknownHostException` - if the host cannot be resolved to find out.

### isInConflict

public boolean isInConflict() throws UnknownHostException
Determines if this address in conflict with another address.

Throws:
  `UnknownHostException` - if the host cannot be resolved to find out.

### isActive

public boolean isActive() throws UnknownHostException
Determines if this address is active.

Throws:
  `UnknownHostException` - if the host cannot be resolved to find out.

### isPermanent

public boolean isPermanent() throws UnknownHostException
Determines if this address is set to be permanent.

Throws:
  `UnknownHostException` - if the host cannot be resolved to find out.

### getMacAddress

public byte[] getMacAddress() throws UnknownHostException
Retrieves the MAC address of the remote network interface. Samba returns all zeros.

Returns:
  the MAC address as an array of six bytes
Throws:
  `UnknownHostException` - if the host cannot be resolved to determine the MAC address.

### getHostName

public String getHostName()
The hostname of this address. If the hostname is null the local machines IP address is returned.

Returns:
  the text representation of the hostname associated with this address

### getAddress

public byte[] getAddress()
Returns the raw IP address of this NbtAddress. The result is in network byte order: the highest order byte of the address is in getAddress()[0].

Returns:
  a four byte array

### getInetAddress

public InetAddress getInetAddress() throws UnknownHostException
To convert this address to an `InetAddress`.

Returns:
  the `InetAddress` representation of this address.
Throws:
  `UnknownHostException`

### getHostAddress

public String getHostAddress()
Returns this IP adress as a `String` in the form "%d.%d.%d.%d".

### getNameType

public int getNameType()
Returned the hex code associated with this name(e.g. 0x20 is for the file service)

### hashCode

public int hashCode()
Returns a hashcode for this IP address. The hashcode comes from the IP address and is not generated from the string representation. So because NetBIOS nodes can have many names, all names associated with an IP will have the same hashcode.

Overrides:
  `hashCode` in class `Object`

### equals

public boolean equals(Object obj)
Determines if this address is equal two another. Only the IP Addresses are compared. Similar to the `hashCode()` method, the comparison is based on the integer IP address and not the string representation.

Overrides:
  `equals` in class `Object`

### toString

public String toString()
Returns the `String` representaion of this address.

Overrides:
  `toString` in class `Object`