Java Code Examples for java.net.InetAddress#hashCode()

The following examples show how to use java.net.InetAddress#hashCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NbtAddress.java    From jcifs with GNU Lesser General Public License v2.1 5 votes vote down vote up
static NbtAddress doNameQuery( Name name, InetAddress svr )
                                                throws UnknownHostException {
    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;
}
 
Example 2
Source File: NbtAddress.java    From jcifs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean isWINS( InetAddress svr ) {
    for( int i = 0; svr != null && i < NBNS.length; i++ ) {
        if( svr.hashCode() == NBNS[i].hashCode() ) {
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: NameServiceClientImpl.java    From jcifs with GNU Lesser General Public License v2.1 5 votes vote down vote up
NbtAddress doNameQuery ( Name name, InetAddress svr ) throws UnknownHostException {
    NbtAddress addr;

    if ( name.hexCode == 0x1d && svr == null ) {
        svr = this.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 = getByName(name, svr);
            }
            catch ( UnknownHostException uhe ) {
                addr = this.unknownAddress;
            }
            finally {
                cacheAddress(name, addr);
                updateLookupTable(name);
            }
        }
    }
    if ( addr == this.unknownAddress ) {
        throw new UnknownHostException(name.toString());
    }
    return addr;
}
 
Example 4
Source File: NameServiceClientImpl.java    From jcifs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 
 * @param svr
 * @return whether the given address is a WINS server
 */
protected boolean isWINS ( InetAddress svr ) {
    for ( int i = 0; svr != null && i < this.transportContext.getConfig().getWinsServers().length; i++ ) {
        if ( svr.hashCode() == this.transportContext.getConfig().getWinsServers()[ i ].hashCode() ) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: Host.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public int hashCode() {
    if (Host.UNKNOWN_HOST == this) return super.hashCode();
    InetAddress address = getInetAddress();
    if (this == LOCALHOST) return address.hashCode();
    if (address.isLoopbackAddress()) return LOCALHOST.hashCode();
    else return address.hashCode();
}
 
Example 6
Source File: NameServiceClientImpl.java    From jcifs-ng with GNU Lesser General Public License v2.1 5 votes vote down vote up
NbtAddress doNameQuery ( Name name, InetAddress svr ) throws UnknownHostException {
    NbtAddress addr;

    if ( name.hexCode == 0x1d && svr == null ) {
        svr = this.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 = getByName(name, svr);
            }
            catch ( UnknownHostException uhe ) {
                addr = this.unknownAddress;
            }
            finally {
                cacheAddress(name, addr);
                updateLookupTable(name);
            }
        }
    }
    if ( addr == this.unknownAddress ) {
        throw new UnknownHostException(name.toString());
    }
    return addr;
}
 
Example 7
Source File: NameServiceClientImpl.java    From jcifs-ng with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 
 * @param svr
 * @return whether the given address is a WINS server
 */
protected boolean isWINS ( InetAddress svr ) {
    for ( int i = 0; svr != null && i < this.transportContext.getConfig().getWinsServers().length; i++ ) {
        if ( svr.hashCode() == this.transportContext.getConfig().getWinsServers()[ i ].hashCode() ) {
            return true;
        }
    }
    return false;
}
 
Example 8
Source File: Instance.java    From hola with MIT License 5 votes vote down vote up
@Override
public int hashCode() {
    int result = 17;
    result = 31 * result + getName().hashCode();
    result = 31 * result + getPort();
    for (InetAddress address : getAddresses()) {
        result = 31 * result + address.hashCode();
    }
    for (Map.Entry<String, String> entry : attributes.entrySet()) {
        result = 31 * result + entry.hashCode();
    }
    return result;
}
 
Example 9
Source File: NameServiceClientImpl.java    From jcifs with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * 
 */
private void initCache ( CIFSContext tc ) {
    this.unknownName = new Name(tc.getConfig(), "0.0.0.0", 0x00, null);
    this.unknownAddress = new NbtAddress(this.unknownName, 0, false, NbtAddress.B_NODE);
    this.addressCache.put(this.unknownName, new CacheEntry(this.unknownName, this.unknownAddress, SmbConstants.FOREVER));

    /*
     * Determine the InetAddress of the local interface
     * if one was not specified.
     */
    InetAddress localInetAddress = tc.getConfig().getNetbiosLocalAddress();
    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 ) {
                throw new RuntimeCIFSException(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.
     */
    String localHostname = tc.getConfig().getNetbiosHostname();
    if ( localHostname == null || localHostname.length() == 0 ) {
        byte[] addr = localInetAddress.getAddress();
        localHostname = "JCIFS" + ( addr[ 2 ] & 0xFF ) + "_" + ( addr[ 3 ] & 0xFF ) + "_"
                + Hexdump.toHexString((int) ( Math.random() * 0xFF ), 2);
    }

    /*
     * Create an NbtAddress for the local interface with
     * the name deduced above possibly with scope applied and
     * cache it forever.
     */
    Name localName = new Name(tc.getConfig(), localHostname, 0x00, tc.getConfig().getNetbiosScope());
    this.localhostAddress = new NbtAddress(
        localName,
        localInetAddress.hashCode(),
        false,
        NbtAddress.B_NODE,
        false,
        false,
        true,
        false,
        UNKNOWN_MAC_ADDRESS);
    cacheAddress(localName, this.localhostAddress, SmbConstants.FOREVER);
}
 
Example 10
Source File: NameServiceClientImpl.java    From jcifs-ng with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * 
 */
private void initCache ( CIFSContext tc ) {
    this.unknownName = new Name(tc.getConfig(), "0.0.0.0", 0x00, null);
    this.unknownAddress = new NbtAddress(this.unknownName, 0, false, NbtAddress.B_NODE);
    this.addressCache.put(this.unknownName, new CacheEntry(this.unknownName, this.unknownAddress, SmbConstants.FOREVER));

    /*
     * Determine the InetAddress of the local interface
     * if one was not specified.
     */
    InetAddress localInetAddress = tc.getConfig().getNetbiosLocalAddress();
    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 ) {
                throw new RuntimeCIFSException(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.
     */
    String localHostname = tc.getConfig().getNetbiosHostname();
    if ( localHostname == null || localHostname.length() == 0 ) {
        byte[] addr = localInetAddress.getAddress();
        localHostname = "JCIFS" + ( addr[ 2 ] & 0xFF ) + "_" + ( addr[ 3 ] & 0xFF ) + "_"
                + Hexdump.toHexString((int) ( Math.random() * 0xFF ), 2);
    }

    /*
     * Create an NbtAddress for the local interface with
     * the name deduced above possibly with scope applied and
     * cache it forever.
     */
    Name localName = new Name(tc.getConfig(), localHostname, 0x00, tc.getConfig().getNetbiosScope());
    this.localhostAddress = new NbtAddress(
        localName,
        localInetAddress.hashCode(),
        false,
        NbtAddress.B_NODE,
        false,
        false,
        true,
        false,
        UNKNOWN_MAC_ADDRESS);
    cacheAddress(localName, this.localhostAddress, SmbConstants.FOREVER);
}