Esempio n. 1
0
  /** @return whether the IpPort is a valid external address. */
  public static boolean isValidExternalIpPort(IpPort addr) {
    if (addr == null) return false;

    return isValidAddress(addr.getAddress())
        && !isPrivateAddress(addr.getAddress())
        && isValidPort(addr.getPort());
  }
Esempio n. 2
0
 /** Packs a Collection of IpPorts into a byte array. */
 public static byte[] packIpPorts(Collection ipPorts) {
   byte[] data = new byte[ipPorts.size() * 6];
   int offset = 0;
   for (Iterator i = ipPorts.iterator(); i.hasNext(); ) {
     IpPort next = (IpPort) i.next();
     byte[] addr = next.getInetAddress().getAddress();
     int port = next.getPort();
     System.arraycopy(addr, 0, data, offset, 4);
     offset += 4;
     ByteOrder.short2leb((short) port, data, offset);
     offset += 2;
   }
   return data;
 }