Exemplo n.º 1
0
  protected InetSocketAddress readAddress() throws IOException {
    // Address
    int addressType = input.read();
    InetAddress address;
    switch (addressType) {
      case 1: // IPv4
        byte[] ip4 = new byte[4];
        readFully(ip4);
        address = Inet4Address.getByAddress(ip4);
        break;

      case 3: // Domain name
        int size = input.read();
        byte[] domain = new byte[size];
        readFully(domain);
        address = InetAddress.getByName(new String(domain, "US-ASCII"));
        break;

      case 4: // IPv6
        byte[] ip6 = new byte[16];
        readFully(ip6);
        address = Inet6Address.getByAddress(ip6);
        break;

      default:
        throw new SOCKS5Exception(
            "Unexpected address type in SOCKS server response: " + addressType);
    }

    // Port
    int port = (input.read() << 8) | input.read();

    return new InetSocketAddress(address, port);
  }
Exemplo n.º 2
0
 /**
  * Compares this object against the specified object. The result is {@code true} if and only if
  * the argument is not {@code null} and it represents the same interface address as this object.
  *
  * <p>Two instances of {@code InterfaceAddress} represent the same address if the InetAddress, the
  * prefix length and the broadcast are the same for both.
  *
  * @param obj the object to compare against.
  * @return {@code true} if the objects are the same; {@code false} otherwise.
  * @see j86.java.net.InterfaceAddress#hashCode()
  */
 public boolean equals(Object obj) {
   if (!(obj instanceof InterfaceAddress)) {
     return false;
   }
   InterfaceAddress cmp = (InterfaceAddress) obj;
   if (!(address == null ? cmp.address == null : address.equals(cmp.address))) return false;
   if (!(broadcast == null ? cmp.broadcast == null : broadcast.equals(cmp.broadcast)))
     return false;
   if (maskLength != cmp.maskLength) return false;
   return true;
 }
Exemplo n.º 3
0
 /**
  * Returns a hashcode for this Interface address.
  *
  * @return a hash code value for this Interface address.
  */
 public int hashCode() {
   return address.hashCode() + ((broadcast != null) ? broadcast.hashCode() : 0) + maskLength;
 }