Package java.net

Examples of java.net.InetAddress


           
          Enumeration addresses = ni.getInetAddresses();
         
          while( addresses.hasMoreElements()){
           
            InetAddress address = (InetAddress)addresses.nextElement();
           
            if ( address.isLoopbackAddress() || address instanceof Inet6Address ){
             
              continue;
            }
           
            return( address );
View Full Code Here


    if ( Constants.isCVSVersion()){
   
        // allow local addresses for testing
     
      try{
        InetAddress ia = InetAddress.getByName( host );
     
        return( ia.isLoopbackAddress() || ia.isLinkLocalAddress() || ia.isSiteLocalAddress());
       
      }catch( Throwable e ){
      }
    }
   
View Full Code Here

    boolean                  upnp_map,
    NetworkAdminProgressListener      listener )
 
    throws NetworkAdminException
  {
    InetAddress bind_ip = address==null?null:address.getAddress();
   
    NetworkAdminProtocolTester  tester;
   
    if ( type == PT_HTTP ){
     
      tester = new NetworkAdminHTTPTester( core, listener );
     
    }else if ( type == PT_TCP ){
     
      tester = new NetworkAdminTCPTester( core, listener );

    }else{
     
      tester = new NetworkAdminUDPTester( core, listener );
    }
   
    InetAddress  res;
   
    if ( port <= 0 ){
     
      res = tester.testOutbound( bind_ip, 0 );
     
View Full Code Here

  {

    int  pos = bgp_prefix.indexOf('/');
   
    try{
      InetAddress  start = InetAddress.getByName( bgp_prefix.substring(0,pos));
     
      int  cidr_mask = Integer.parseInt( bgp_prefix.substring( pos+1 ));
     
      int  rev_mask = 0;
     
      for (int i=0;i<32-cidr_mask;i++){
       
     
        rev_mask = ( rev_mask << 1 ) | 1;
      }
     
      byte[]  bytes = start.getAddress();
     
      bytes[0] |= (rev_mask>>24)&0xff;
      bytes[1] |= (rev_mask>>16)&0xff;
      bytes[2] |= (rev_mask>>8)&0xff;
      bytes[3] |= (rev_mask)&0xff;
View Full Code Here

        return( true );
      }
     
        // allow local addresses for testing purposes
     
      InetAddress iad = InetAddress.getByName(host);
     
      if (   iad.isLoopbackAddress() ||
          iad.isLinkLocalAddress() ||
          iad.isSiteLocalAddress()){
       
        return( true );
      }
    }catch( Throwable e ){
    }
View Full Code Here

     
      return( false );
    }
   
    try{
      InetAddress  start  = getCIDRStartAddress();
      InetAddress  end    = getCIDREndAddress();
     
      long  l_start = PRHelpers.addressToLong( start );
      long  l_end  = PRHelpers.addressToLong( end );
     
      long  test = PRHelpers.addressToLong( address );
View Full Code Here

    InetSocketAddress  address,
    byte        protocol_version )
 
    throws DHTTransportException
  {   
    InetAddress ia = address.getAddress();
   
    if ( ia == null ){
     
      // Debug.out( "Address '" + address + "' is unresolved" );
     
      throw( new DHTTransportException( "Address '" + address + "' is unresolved" ));
     
    }else{
     
      String  key;
     
      if ( protocol_version >= DHTTransportUDP.PROTOCOL_VERSION_RESTRICT_ID3 ){
       
        byte[] bytes = ia.getAddress();
       
        if ( bytes.length == 4 ){
         
          //final long K0  = Long.MAX_VALUE; 
          //final long K1  = Long.MAX_VALUE; 
         
            // restrictions suggested by UoW researchers as effective at reducing Sybil opportunity but
            // not so restrictive as to impact DHT performance
         
          final long K2  = 2500;
          final long K3  = 50;
          final long K4  = 5;

          long  result = address.getPort() % K4;
         
          result = ((((long)bytes[3] << 8 ) &0x000000ff00L ) | result ) % K3;
          result = ((((long)bytes[2] << 16 )&0x0000ff0000L ) | result ) % K2;
          result = ((((long)bytes[1] << 24 )&0x00ff000000L ) | result ); // % K1;
          result = ((((long)bytes[0] << 32 )&0xff00000000L ) | result ); // % K0;

          key = String.valueOf( result );
                   
        }else{

            // stick with existing approach for IPv6 at the moment
         
          key = ia.getHostAddress() + ":" + ( address.getPort() % 8 );
        }
      }else if ( protocol_version >= DHTTransportUDP.PROTOCOL_VERSION_RESTRICT_ID_PORTS2 ){

          // more draconian limit, analysis shows that of 500,000 node addresses only
          // 0.01% had >= 8 ports active. ( 1% had 2 ports, 0.1% 3)
          // Having > 1 node with the same ID doesn't actually cause too much grief
   
        key = ia.getHostAddress() + ":" + ( address.getPort() % 8 );
       
      }else if ( protocol_version >= DHTTransportUDP.PROTOCOL_VERSION_RESTRICT_ID_PORTS ){

          // limit range to around 2000 (1999 is prime)

        key = ia.getHostAddress() + ":" + ( address.getPort() % 1999 );
       
      }else{
     
        key = ia.getHostAddress() + ":" + address.getPort();
      }
     
      synchronized( node_id_history ){
       
        byte[]  res = node_id_history.get( key );
View Full Code Here

    DataOutputStream  os,
    InetSocketAddress  address )
 
    throws IOException, DHTTransportException
  {
    InetAddress  ia = address.getAddress();
   
    if ( ia == null ){
     
      Debug.out( "Address '" + address + "' is unresolved" );
     
      throw( new DHTTransportException( "Address '" + address + "' is unresolved" ));
    }
   
    serialiseByteArray( os, ia.getAddress(), 16)// 16 (Pv6) + 1 length
   
    os.writeShort( address.getPort())//19
  }
View Full Code Here

 
  protected PeerItem( String _address, int _tcp_port, byte _source, byte _handshake, int _udp_port, byte _crypto_level, int _up_speed  ) {
    byte[] raw;
    try{
      //see if we can resolve the address into a compact raw IPv4/6 byte array (4 or 16 bytes)
      InetAddress ip = InetAddress.getByName( _address );
      raw = ip.getAddress();
    }
    catch( UnknownHostException e ) {
      //not a standard IPv4/6 address, so just use the full string bytes
      raw = _address.getBytes();
    }
View Full Code Here

        getPort() != other.getPort()){
     
      return( false );
    }
   
    InetAddress e1 = getExternalAddress();
    InetAddress e2 = other.getExternalAddress();
   
    if ( e1 == null && e2 == null ){
     
      return( true );
    }
View Full Code Here

TOP

Related Classes of java.net.InetAddress

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.