Methods Summary |
---|
public boolean | equals(java.lang.Object obj)Compare two addresses for equality. Two UniAddresss are equal
if they are both UniAddress' and refer to the same IP address.
return obj instanceof UniAddress && addr.equals(((UniAddress)obj).addr);
|
public java.lang.String | firstCalledName()Guess first called name to try for session establishment. This
method is used exclusively by the jcifs.smb package.
if( addr instanceof NbtAddress ) {
return ((NbtAddress)addr).firstCalledName();
} else {
calledName = ((InetAddress)addr).getHostName();
if( isDotQuadIP( calledName )) {
calledName = NbtAddress.SMBSERVER_NAME;
} else {
int i = calledName.indexOf( '." );
if( i > 1 && i < 15 ) {
calledName = calledName.substring( 0, i ).toUpperCase();
} else if( calledName.length() > 15 ) {
calledName = NbtAddress.SMBSERVER_NAME;
} else {
calledName = calledName.toUpperCase();
}
}
}
return calledName;
|
public java.lang.Object | getAddress()Return the underlying NbtAddress or InetAddress.
return addr;
|
public static jcifs.UniAddress[] | getAllByName(java.lang.String hostname, boolean possibleNTDomainOrWorkgroup)
Object addr;
int i;
if( hostname == null || hostname.length() == 0 ) {
throw new UnknownHostException();
}
if( isDotQuadIP( hostname )) {
UniAddress[] addrs = new UniAddress[1];
addrs[0] = new UniAddress( NbtAddress.getByName( hostname ));
return addrs;
}
for( i = 0; i < resolveOrder.length; i++ ) {
try {
switch( resolveOrder[i] ) {
case RESOLVER_LMHOSTS:
if(( addr = Lmhosts.getByName( hostname )) == null ) {
continue;
}
break;
case RESOLVER_WINS:
if( hostname == NbtAddress.MASTER_BROWSER_NAME ||
hostname.length() > 15 ) {
// invalid netbios name
continue;
}
if( possibleNTDomainOrWorkgroup ) {
addr = lookupServerOrWorkgroup( hostname, NbtAddress.getWINSAddress() );
} else {
addr = NbtAddress.getByName( hostname, 0x20, null, NbtAddress.getWINSAddress() );
}
break;
case RESOLVER_BCAST:
if( hostname.length() > 15 ) {
// invalid netbios name
continue;
}
if( possibleNTDomainOrWorkgroup ) {
addr = lookupServerOrWorkgroup( hostname, baddr );
} else {
addr = NbtAddress.getByName( hostname, 0x20, null, baddr );
}
break;
case RESOLVER_DNS:
if( isAllDigits( hostname )) {
throw new UnknownHostException( hostname );
}
InetAddress[] iaddrs = InetAddress.getAllByName( hostname );
UniAddress[] addrs = new UniAddress[iaddrs.length];
for (int ii = 0; ii < iaddrs.length; ii++) {
addrs[ii] = new UniAddress(iaddrs[ii]);
}
return addrs; // Success
default:
throw new UnknownHostException( hostname );
}
UniAddress[] addrs = new UniAddress[1];
addrs[0] = new UniAddress( addr );
return addrs; // Success
} catch( IOException ioe ) {
// Failure
}
}
throw new UnknownHostException( hostname );
|
public static jcifs.UniAddress | getByName(java.lang.String hostname)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".
return getByName( hostname, false );
|
public static jcifs.UniAddress | getByName(java.lang.String hostname, boolean possibleNTDomainOrWorkgroup)Lookup hostname and return it's UniAddress. If the
possibleNTDomainOrWorkgroup parameter is true an
addtional name query will be performed to locate a master browser.
UniAddress[] addrs = UniAddress.getAllByName(hostname, possibleNTDomainOrWorkgroup);
return addrs[0];
|
public java.lang.String | getHostAddress()Return the IP address as text such as "192.168.1.15".
if( addr instanceof NbtAddress ) {
return ((NbtAddress)addr).getHostAddress();
}
return ((InetAddress)addr).getHostAddress();
|
public java.lang.String | getHostName()Return the hostname of this address such as "MYCOMPUTER".
if( addr instanceof NbtAddress ) {
return ((NbtAddress)addr).getHostName();
}
return ((InetAddress)addr).getHostName();
|
public int | hashCode()Return the IP address of this address as a 32 bit integer.
return addr.hashCode();
|
static boolean | isAllDigits(java.lang.String hostname)
for (int i = 0; i < hostname.length(); i++) {
if (Character.isDigit( hostname.charAt( i )) == false) {
return false;
}
}
return true;
|
static boolean | isDotQuadIP(java.lang.String hostname)
if( Character.isDigit( hostname.charAt( 0 ))) {
int i, len, dots;
char[] data;
i = dots = 0; /* quick IP address validation */
len = hostname.length();
data = hostname.toCharArray();
while( i < len && Character.isDigit( data[i++] )) {
if( i == len && dots == 3 ) {
// probably an IP address
return true;
}
if( i < len && data[i] == '." ) {
dots++;
i++;
}
}
}
return false;
|
static jcifs.netbios.NbtAddress | lookupServerOrWorkgroup(java.lang.String name, java.net.InetAddress svr)
Sem sem = new Sem( 2 );
int type = NbtAddress.isWINS( svr ) ? 0x1b : 0x1d;
QueryThread q1x = new QueryThread( sem, name, type, null, svr );
QueryThread q20 = new QueryThread( sem, name, 0x20, null, svr );
q1x.setDaemon( true );
q20.setDaemon( true );
try {
synchronized( sem ) {
q1x.start();
q20.start();
while( sem.count > 0 && q1x.ans == null && q20.ans == null ) {
sem.wait();
}
}
} catch( InterruptedException ie ) {
throw new UnknownHostException( name );
}
if( q1x.ans != null ) {
return q1x.ans;
} else if( q20.ans != null ) {
return q20.ans;
} else {
throw q1x.uhe;
}
|
public java.lang.String | nextCalledName()Guess next called name to try for session establishment. This
method is used exclusively by the jcifs.smb package.
if( addr instanceof NbtAddress ) {
return ((NbtAddress)addr).nextCalledName();
} else if( calledName != NbtAddress.SMBSERVER_NAME ) {
calledName = NbtAddress.SMBSERVER_NAME;
return calledName;
}
return null;
|
public java.lang.String | toString()Return the a text representation of this address such as
MYCOMPUTER/192.168.1.15.
return addr.toString();
|