示例#1
0
    private void doConnect(InetSocketAddress addr) throws IOException {
      dest = new Socket();
      try {
        dest.connect(addr, 10000);
      } catch (SocketTimeoutException ex) {
        sendError(HOST_UNREACHABLE);
        return;
      } catch (ConnectException cex) {
        sendError(CONN_REFUSED);
        return;
      }
      // Success
      InetAddress iadd = addr.getAddress();
      if (iadd instanceof Inet4Address) {
        out.write(PROTO_VERS);
        out.write(REQUEST_OK);
        out.write(0);
        out.write(IPV4);
        out.write(iadd.getAddress());
      } else if (iadd instanceof Inet6Address) {
        out.write(PROTO_VERS);
        out.write(REQUEST_OK);
        out.write(0);
        out.write(IPV6);
        out.write(iadd.getAddress());
      } else {
        sendError(GENERAL_FAILURE);
        return;
      }
      out.write((addr.getPort() >> 8) & 0xff);
      out.write((addr.getPort() >> 0) & 0xff);
      out.flush();

      InputStream in2 = dest.getInputStream();
      OutputStream out2 = dest.getOutputStream();

      Tunnel tunnel = new Tunnel(in2, out);
      tunnel.start();

      int b = 0;
      do {
        // Note that the socket might be closed from another thread (the tunnel)
        try {
          b = in.read();
          if (b == -1) {
            in.close();
            out2.close();
            return;
          }
          out2.write(b);
        } catch (IOException ioe) {
        }
      } while (!client.isClosed());
    }
示例#2
0
 /** List file names */
 public Enumeration nlst(String s) throws IOException {
   InetAddress inetAddress = InetAddress.getLocalHost();
   byte ab[] = inetAddress.getAddress();
   serverSocket_ = new ServerSocket(0, 1);
   StringBuffer sb = new StringBuffer(32);
   sb.append("PORT ");
   for (int i = 0; i < ab.length; i++) {
     sb.append(String.valueOf(ab[i] & 255));
     sb.append(",");
   }
   sb.append(String.valueOf(serverSocket_.getLocalPort() >>> 8 & 255));
   sb.append(",");
   sb.append(String.valueOf(serverSocket_.getLocalPort() & 255));
   if (issueCommand(sb.toString()) != FTP_SUCCESS) {
     serverSocket_.close();
     throw new IOException(getResponseString());
   } else if (issueCommand("NLST " + ((s == null) ? "" : s)) != FTP_SUCCESS) {
     serverSocket_.close();
     throw new IOException(getResponseString());
   }
   dataSocket_ = serverSocket_.accept();
   serverSocket_.close();
   serverSocket_ = null;
   Vector v = readServerResponse_(dataSocket_.getInputStream());
   dataSocket_.close();
   dataSocket_ = null;
   return (v == null) ? null : v.elements();
 }
示例#3
0
 public byte[] getRAddr() {
   try {
     InetAddress addr = InetAddress.getByName(host);
     return addr.getAddress();
   } catch (UnknownHostException e) {
     System.err.println("NCCPConnection::getRAddr Don't know about host: ");
     return null;
   }
 }
示例#4
0
文件: dns.java 项目: lemmy/dnsjava
 public static String inaddrString(InetAddress addr) {
   byte[] address = addr.getAddress();
   StringBuffer sb = new StringBuffer();
   for (int i = 3; i >= 0; i--) {
     sb.append(address[i] & 0xFF);
     sb.append(".");
   }
   sb.append(".IN-ADDR.ARPA.");
   return sb.toString();
 }
示例#5
0
 /** Converts rdata to a String */
 public String rrToString() {
   InetAddress addr;
   try {
     addr = InetAddress.getByAddress(null, address);
   } catch (UnknownHostException e) {
     return null;
   }
   if (addr.getAddress().length == 4) {
     // Deal with Java's broken handling of mapped IPv4 addresses.
     StringBuffer sb = new StringBuffer("0:0:0:0:0:ffff:");
     int high = ((address[12] & 0xFF) << 8) + (address[13] & 0xFF);
     int low = ((address[14] & 0xFF) << 8) + (address[15] & 0xFF);
     sb.append(Integer.toHexString(high));
     sb.append(':');
     sb.append(Integer.toHexString(low));
     return sb.toString();
   }
   return addr.getHostAddress();
 }
示例#6
0
 void rdataFromString(Tokenizer st, Name origin) throws IOException {
   InetAddress address = st.getAddress(Address.IPv4);
   addr = fromArray(address.getAddress());
 }
示例#7
0
 /**
  * Creates an A Record from the given data
  *
  * @param address The address that the name refers to
  */
 public ARecord(Name name, int dclass, long ttl, InetAddress address) {
   super(name, Type.A, dclass, ttl);
   if (Address.familyOf(address) != Address.IPv4)
     throw new IllegalArgumentException("invalid IPv4 address");
   addr = fromArray(address.getAddress());
 }
 /** InetAddress: size = 4 */
 public static void InetAddressToArray(InetAddress inet, byte[] b, int offset) {
   System.arraycopy(inet.getAddress(), 0, b, offset, 4);
 }
示例#9
0
 /**
  * Creates an AAAA Record from the given data
  *
  * @param address The address suffix
  */
 public AAAARecord(Name name, int dclass, long ttl, InetAddress address) {
   super(name, Type.AAAA, dclass, ttl);
   if (Address.familyOf(address) != Address.IPv6)
     throw new IllegalArgumentException("invalid IPv6 address");
   this.address = address.getAddress();
 }
  /** {@inheritDoc} */
  @Override
  public void writeExternal(ObjectOutput out) throws IOException {
    super.writeExternal(out);

    U.writeByteArray(out, addr.getAddress());
  }
示例#11
0
 void rrToWire(DNSOutput out, Compression c, boolean canonical) {
   out.writeByteArray(address.getAddress());
 }