Methods Summary |
---|
static void | cacheAddress(Name hostName, jcifs.netbios.NbtAddress addr)
InetAddress localInetAddress;
String localHostname;
Name localName;
/* Create an address to represent failed lookups and cache forever.
*/
ADDRESS_CACHE.put( UNKNOWN_NAME, new CacheEntry( UNKNOWN_NAME, UNKNOWN_ADDRESS, FOREVER ));
/* Determine the InetAddress of the local interface
* if one was not specified.
*/
localInetAddress = CLIENT.laddr;
if( localInetAddress == null ) {
try {
localInetAddress = InetAddress.getLocalHost();
} catch( UnknownHostException uhe ) {
/* Java cannot determine the localhost. This is basically a config
* issue on the host. There's not much we can do about it. Just
* to suppress NPEs that would result we can create a possibly bogus
* address. Pretty sure the below cannot actually thrown a UHE tho.
*/
try {
localInetAddress = InetAddress.getByName("127.0.0.1");
} catch( UnknownHostException ignored ) {
}
}
}
/* If a local hostname was not provided a name like
* JCIFS34_172_A6 will be dynamically generated for the
* client. This is primarily (exclusively?) used as a
* CallingName during session establishment.
*/
localHostname = Config.getProperty( "jcifs.netbios.hostname", null );
if( localHostname == null || localHostname.length() == 0 ) {
byte[] addr = localInetAddress.getAddress();
localHostname = "JCIFS" +
( addr[2] & 0xFF ) + "_" +
( addr[3] & 0xFF ) + "_" +
Hexdump.toHexString( (int)( Math.random() * (double)0xFF ), 2 );
}
/* Create an NbtAddress for the local interface with
* the name deduced above possibly with scope applied and
* cache it forever.
*/
localName = new Name( localHostname, 0x00,
Config.getProperty( "jcifs.netbios.scope", null ));
localhost = new NbtAddress( localName,
localInetAddress.hashCode(),
false,
B_NODE,
false, false, true, false,
UNKNOWN_MAC_ADDRESS );
cacheAddress( localName, localhost, FOREVER );
if( CACHE_POLICY == 0 ) {
return;
}
long expiration = -1;
if( CACHE_POLICY != FOREVER ) {
expiration = System.currentTimeMillis() + CACHE_POLICY * 1000;
}
cacheAddress( hostName, addr, expiration );
|
static void | cacheAddress(Name hostName, jcifs.netbios.NbtAddress addr, long expiration)
if( CACHE_POLICY == 0 ) {
return;
}
synchronized( ADDRESS_CACHE ) {
CacheEntry entry = (CacheEntry)ADDRESS_CACHE.get( hostName );
if( entry == null ) {
entry = new CacheEntry( hostName, addr, expiration );
ADDRESS_CACHE.put( hostName, entry );
} else {
entry.address = addr;
entry.expiration = expiration;
}
}
|
static void | cacheAddressArray(jcifs.netbios.NbtAddress[] addrs)
if( CACHE_POLICY == 0 ) {
return;
}
long expiration = -1;
if( CACHE_POLICY != FOREVER ) {
expiration = System.currentTimeMillis() + CACHE_POLICY * 1000;
}
synchronized( ADDRESS_CACHE ) {
for( int i = 0; i < addrs.length; i++ ) {
CacheEntry entry = (CacheEntry)ADDRESS_CACHE.get( addrs[i].hostName );
if( entry == null ) {
entry = new CacheEntry( addrs[i].hostName, addrs[i], expiration );
ADDRESS_CACHE.put( addrs[i].hostName, entry );
} else {
entry.address = addrs[i];
entry.expiration = expiration;
}
}
}
|
void | checkData()
if( hostName == UNKNOWN_NAME ) {
getAllByAddress( this );
}
|
private static java.lang.Object | checkLookupTable(Name name)
Object obj;
synchronized( LOOKUP_TABLE ) {
if( LOOKUP_TABLE.containsKey( name ) == false ) {
LOOKUP_TABLE.put( name, name );
return null;
}
while( LOOKUP_TABLE.containsKey( name )) {
try {
LOOKUP_TABLE.wait();
} catch( InterruptedException e ) {
}
}
}
obj = getCachedAddress( name );
if( obj == null ) {
synchronized( LOOKUP_TABLE ) {
LOOKUP_TABLE.put( name, name );
}
}
return obj;
|
void | checkNodeStatusData()
if( isDataFromNodeStatus == false ) {
getAllByAddress( this );
}
|
static jcifs.netbios.NbtAddress | doNameQuery(Name name, java.net.InetAddress svr)
NbtAddress addr;
if( name.hexCode == 0x1d && svr == null ) {
svr = CLIENT.baddr; // bit of a hack but saves a lookup
}
name.srcHashCode = svr != null ? svr.hashCode() : 0;
addr = getCachedAddress( name );
if( addr == null ) {
/* This is almost exactly like InetAddress.java. See the
* comments there for a description of how the LOOKUP_TABLE prevents
* redundant queries from going out on the wire.
*/
if(( addr = (NbtAddress)checkLookupTable( name )) == null ) {
try {
addr = CLIENT.getByName( name, svr );
} catch( UnknownHostException uhe ) {
addr = UNKNOWN_ADDRESS;
} finally {
cacheAddress( name, addr );
updateLookupTable( name );
}
}
}
if( addr == UNKNOWN_ADDRESS ) {
throw new UnknownHostException( name.toString() );
}
return addr;
|
public boolean | equals(java.lang.Object obj)Determines if this address is equal two another. Only the IP Addresses
are compared. Similar to the {@link #hashCode} method, the comparison
is based on the integer IP address and not the string representation.
return ( obj != null ) && ( obj instanceof NbtAddress ) &&
( ((NbtAddress)obj).address == address );
|
public java.lang.String | firstCalledName()
calledName = hostName.name;
if( Character.isDigit( calledName.charAt( 0 ))) {
int i, len, dots;
char[] data;
i = dots = 0; /* quick IP address validation */
len = calledName.length();
data = calledName.toCharArray();
while( i < len && Character.isDigit( data[i++] )) {
if( i == len && dots == 3 ) {
// probably an IP address
calledName = SMBSERVER_NAME;
break;
}
if( i < len && data[i] == '." ) {
dots++;
i++;
}
}
} else {
switch (hostName.hexCode) {
case 0x1B:
case 0x1C:
case 0x1D:
calledName = SMBSERVER_NAME;
}
}
return calledName;
|
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].
byte[] addr = new byte[4];
addr[0] = (byte)(( address >>> 24 ) & 0xFF );
addr[1] = (byte)(( address >>> 16 ) & 0xFF );
addr[2] = (byte)(( address >>> 8 ) & 0xFF );
addr[3] = (byte)( address & 0xFF );
return addr;
|
public static jcifs.netbios.NbtAddress[] | getAllByAddress(java.lang.String host)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.
return getAllByAddress( getByName( host, 0x00, null ));
|
public static jcifs.netbios.NbtAddress[] | getAllByAddress(java.lang.String host, int type, java.lang.String scope)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 {@link #getByName}
for a description of type
and scope .
return getAllByAddress( getByName( host, type, scope ));
|
public static jcifs.netbios.NbtAddress[] | getAllByAddress(jcifs.netbios.NbtAddress addr)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.
try {
NbtAddress[] addrs = CLIENT.getNodeStatus( addr );
cacheAddressArray( addrs );
return addrs;
} catch( UnknownHostException uhe ) {
throw new UnknownHostException( "no name with type 0x" +
Hexdump.toHexString( addr.hostName.hexCode, 2 ) +
((( addr.hostName.scope == null ) ||
( addr.hostName.scope.length() == 0 )) ?
" with no scope" : " with scope " + addr.hostName.scope ) +
" for host " + addr.getHostAddress() );
}
|
public static jcifs.netbios.NbtAddress[] | getAllByName(java.lang.String host, int type, java.lang.String scope, java.net.InetAddress svr)
return CLIENT.getAllByName( new Name( host, type, scope ), svr );
|
public static jcifs.netbios.NbtAddress | getByName(java.lang.String host)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 {@link jcifs.UniAddress} or {@link java.net.InetAddress}
getByName methods can be used for that.
return getByName( host, 0x00, null );
|
public static jcifs.netbios.NbtAddress | getByName(java.lang.String host, int type, java.lang.String scope)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.
return getByName( host, type, scope, null );
|
public static jcifs.netbios.NbtAddress | getByName(java.lang.String host, int type, java.lang.String scope, java.net.InetAddress svr)
if( host == null || host.length() == 0 ) {
return getLocalHost();
}
if( !Character.isDigit( host.charAt(0) )) {
return (NbtAddress)doNameQuery( new Name( host, type, scope ), svr );
} else {
int IP = 0x00;
int hitDots = 0;
char[] data = host.toCharArray();
for( int i = 0; i < data.length; i++ ) {
char c = data[i];
if( c < 48 || c > 57 ) {
return (NbtAddress)doNameQuery( new Name( host, type, scope ), svr );
}
int b = 0x00;
while( c != '." ) {
if( c < 48 || c > 57 ) {
return (NbtAddress)doNameQuery( new Name( host, type, scope ), svr );
}
b = b * 10 + c - '0";
if( ++i >= data.length )
break;
c = data[i];
}
if( b > 0xFF ) {
return (NbtAddress)doNameQuery( new Name( host, type, scope ), svr );
}
IP = ( IP << 8 ) + b;
hitDots++;
}
if( hitDots != 4 || host.endsWith( "." )) {
return (NbtAddress)doNameQuery( new Name( host, type, scope ), svr );
}
return new NbtAddress( UNKNOWN_NAME, IP, false, B_NODE );
}
|
static jcifs.netbios.NbtAddress | getCachedAddress(Name hostName)
if( CACHE_POLICY == 0 ) {
return null;
}
synchronized( ADDRESS_CACHE ) {
CacheEntry entry = (CacheEntry)ADDRESS_CACHE.get( hostName );
if( entry != null && entry.expiration < System.currentTimeMillis() &&
entry.expiration >= 0 ) {
entry = null;
}
return entry != null ? entry.address : null;
}
|
public java.lang.String | getHostAddress()Returns this IP adress as a {@link java.lang.String} in the form "%d.%d.%d.%d".
return (( address >>> 24 ) & 0xFF ) + "." +
(( address >>> 16 ) & 0xFF ) + "." +
(( address >>> 8 ) & 0xFF ) + "." +
(( address >>> 0 ) & 0xFF );
|
public java.lang.String | getHostName()The hostname of this address. If the hostname is null the local machines
IP address is returned.
/* 2010 - We no longer try a Node Status to get the
* hostname because apparently some servers do not respond
* anymore. I think everyone post Windows 98 will accept
* an IP address as the tconHostName which is the principal
* use of this method.
*/
if (hostName == UNKNOWN_NAME) {
return getHostAddress();
}
return hostName.name;
|
public java.net.InetAddress | getInetAddress()To convert this address to an InetAddress .
return InetAddress.getByName( getHostAddress() );
|
public static jcifs.netbios.NbtAddress | getLocalHost()Retrieves the local host address.
return localhost;
|
public static Name | getLocalName()
return localhost.hostName;
|
public byte[] | getMacAddress()Retrieves the MAC address of the remote network interface. Samba returns all zeros.
checkNodeStatusData();
return macAddress;
|
public int | getNameType()Returned the hex code associated with this name(e.g. 0x20 is for the file service)
return hostName.hexCode;
|
public int | getNodeType()Checks the node type of this address.
checkData();
return nodeType;
|
public static java.net.InetAddress | getWINSAddress()
return NBNS.length == 0 ? null : NBNS[nbnsIndex];
|
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.
return address;
|
public boolean | isActive()Determines if this address is active.
checkNodeStatusData();
return isActive;
|
public boolean | isBeingDeleted()Determines if this address in the process of being deleted.
checkNodeStatusData();
return isBeingDeleted;
|
public boolean | isGroupAddress()Determines if the address is a group address. This is also
known as a workgroup name or group name.
checkData();
return groupName;
|
public boolean | isInConflict()Determines if this address in conflict with another address.
checkNodeStatusData();
return isInConflict;
|
public boolean | isPermanent()Determines if this address is set to be permanent.
checkNodeStatusData();
return isPermanent;
|
public static boolean | isWINS(java.net.InetAddress svr)
for( int i = 0; svr != null && i < NBNS.length; i++ ) {
if( svr.hashCode() == NBNS[i].hashCode() ) {
return true;
}
}
return false;
|
public java.lang.String | nextCalledName()
if( calledName == hostName.name ) {
calledName = SMBSERVER_NAME;
} else if( calledName == SMBSERVER_NAME ) {
NbtAddress[] addrs;
try {
addrs = CLIENT.getNodeStatus( this );
if( hostName.hexCode == 0x1D ) {
for( int i = 0; i < addrs.length; i++ ) {
if( addrs[i].hostName.hexCode == 0x20 ) {
return addrs[i].hostName.name;
}
}
return null;
} else if( isDataFromNodeStatus ) {
/* 'this' has been updated and should now
* have a real NetBIOS name
*/
calledName = null;
return hostName.name;
}
} catch( UnknownHostException uhe ) {
calledName = null;
}
} else {
calledName = null;
}
return calledName;
|
static java.net.InetAddress | switchWINS()
nbnsIndex = (nbnsIndex + 1) < NBNS.length ? nbnsIndex + 1 : 0;
return NBNS.length == 0 ? null : NBNS[nbnsIndex];
|
public java.lang.String | toString()Returns the {@link java.lang.String} representaion of this address.
return hostName.toString() + "/" + getHostAddress();
|
private static void | updateLookupTable(Name name)
synchronized( LOOKUP_TABLE ) {
LOOKUP_TABLE.remove( name );
LOOKUP_TABLE.notifyAll();
}
|