Refine search
private InetSocketAddress createInetSocketAddress(InetSocketAddress resolved, String host) { byte[] addr = NetUtil.createByteArrayFromIpAddressString(resolved.getAddress().getHostAddress()); try { return new InetSocketAddress(InetAddress.getByAddress(host, addr), resolved.getPort()); } catch (UnknownHostException e) { throw new RuntimeException(e); } }
private InetSocketAddress createInetSocketAddress(InetSocketAddress resolved, String host) { byte[] addr = NetUtil.createByteArrayFromIpAddressString(resolved.getAddress().getHostAddress()); try { return new InetSocketAddress(InetAddress.getByAddress(host, addr), resolved.getPort()); } catch (UnknownHostException e) { throw new RuntimeException(e); } }
private static InetSocketAddress getMulticastControlAddress(final InetSocketAddress endpointAddress) throws UnknownHostException { final byte[] addressAsBytes = endpointAddress.getAddress().getAddress(); validateDataAddress(addressAsBytes); addressAsBytes[addressAsBytes.length - 1]++; return new InetSocketAddress(getByAddress(addressAsBytes), endpointAddress.getPort()); }
/** * Adds the hostname string to the specified {@link InetSocketAddress} so that * Jetty's {@code ServletRequest.getLocalName()} implementation returns the configured hostname. */ private static InetSocketAddress addHostname(InetSocketAddress address, @Nullable String hostname) { try { return new InetSocketAddress(InetAddress.getByAddress( hostname, address.getAddress().getAddress()), address.getPort()); } catch (UnknownHostException e) { throw new Error(e); // Should never happen } }
public static InetSocketAddress computeRemoteAddr(InetSocketAddress remoteAddr, InetSocketAddress osRemoteAddr) { if (osRemoteAddr != null) { if (PlatformDependent.javaVersion() >= 7) { try { // Only try to construct a new InetSocketAddress if we using java >= 7 as getHostString() does not // exists in earlier releases and so the retrieval of the hostname could block the EventLoop if a // reverse lookup would be needed. return new InetSocketAddress(InetAddress.getByAddress(remoteAddr.getHostString(), osRemoteAddr.getAddress().getAddress()), osRemoteAddr.getPort()); } catch (UnknownHostException ignore) { // Should never happen but fallback to osRemoteAddr anyway. } } return osRemoteAddr; } return remoteAddr; } }
private static InetSocketAddress toRemoteAddress(PoolKey key) throws UnknownHostException { final InetAddress inetAddr = InetAddress.getByAddress( key.host, NetUtil.createByteArrayFromIpAddressString(key.ipAddr)); return new InetSocketAddress(inetAddr, key.port); }
public static MessageId decodeMessageId(final String msgId) throws UnknownHostException { SocketAddress address; long offset; byte[] ip = UtilAll.string2bytes(msgId.substring(0, 8)); byte[] port = UtilAll.string2bytes(msgId.substring(8, 16)); ByteBuffer bb = ByteBuffer.wrap(port); int portInt = bb.getInt(0); address = new InetSocketAddress(InetAddress.getByAddress(ip), portInt); // offset byte[] data = UtilAll.string2bytes(msgId.substring(16, 32)); bb = ByteBuffer.wrap(data); offset = bb.getLong(0); return new MessageId(address, offset); }
public static boolean connect(SocketChannel ch, SocketAddress dest) throws IOException { if(dest instanceof InetSocketAddress) { InetAddress addr=((InetSocketAddress)dest).getAddress(); if(addr instanceof Inet6Address) { Inet6Address tmp=(Inet6Address)addr; if(tmp.getScopeId() != 0) { dest=new InetSocketAddress(InetAddress.getByAddress(tmp.getAddress()),((InetSocketAddress)dest).getPort()); } } } return ch.connect(dest); }
public static InetSocketAddress computeRemoteAddr(InetSocketAddress remoteAddr, InetSocketAddress osRemoteAddr) { if (osRemoteAddr != null) { if (PlatformDependent.javaVersion() >= 7) { try { // Only try to construct a new InetSocketAddress if we using java >= 7 as getHostString() does not // exists in earlier releases and so the retrieval of the hostname could block the EventLoop if a // reverse lookup would be needed. return new InetSocketAddress(InetAddress.getByAddress(remoteAddr.getHostString(), osRemoteAddr.getAddress().getAddress()), osRemoteAddr.getPort()); } catch (UnknownHostException ignore) { // Should never happen but fallback to osRemoteAddr anyway. } } return osRemoteAddr; } return remoteAddr; } }
public InetSocketAddress toInetSocketAddress() { try { return new InetSocketAddress(InetAddress.getByAddress(sin_addr()), sin_port()); } catch (UnknownHostException e) { e.printStackTrace(); } return null; } }
/** * Utility method. If the dest address is IPv6, convert scoped link-local addrs into unscoped ones * @param sock * @param dest * @param sock_conn_timeout * @throws IOException */ public static void connect(Socket sock,SocketAddress dest,int sock_conn_timeout) throws IOException { if(dest instanceof InetSocketAddress) { InetAddress addr=((InetSocketAddress)dest).getAddress(); if(addr instanceof Inet6Address) { Inet6Address tmp=(Inet6Address)addr; if(tmp.getScopeId() != 0) { dest=new InetSocketAddress(InetAddress.getByAddress(tmp.getAddress()),((InetSocketAddress)dest).getPort()); } } } sock.connect(dest, sock_conn_timeout); }
@Override public AddressableNode read(DataInput input) throws IOException { Address jgroupsAddress = AddressSerializer.INSTANCE.read(input); String name = input.readUTF(); byte[] address = new byte[IndexSerializer.UNSIGNED_BYTE.readInt(input)]; input.readFully(address); int port = IndexSerializer.UNSIGNED_SHORT.readInt(input); return new AddressableNode(jgroupsAddress, name, new InetSocketAddress(InetAddress.getByAddress(address), port)); }
byte[] ipv4 = new byte[4]; System.arraycopy(addr, offset, ipv4, 0, 4); address = InetAddress.getByAddress(ipv4); break; throw new Error(); return new InetSocketAddress(address, port); } catch (UnknownHostException e) { throw new Error("Should never happen", e);
private Collection<InetSocketAddress> getServerAddresses(byte size) { ArrayList<InetSocketAddress> list = new ArrayList<InetSocketAddress>( size); while (size > 0) { try { list.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, size}), 1234 + size)); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } --size; } return list; }
/** * Build a peer list as a list of {@link Peer}s from the * announce response's binary compact peer list. * * @param data The bytes representing the compact peer list from the * announce response. * @return A {@link List} of {@link Peer}s representing the * peers' addresses. Peer IDs are lost, but they are not crucial. */ private static List<Peer> toPeerList(byte[] data) throws InvalidBEncodingException, UnknownHostException { if (data.length % 6 != 0) { throw new InvalidBEncodingException("Invalid peers " + "binary information string!"); } List<Peer> result = new LinkedList<Peer>(); ByteBuffer peers = ByteBuffer.wrap(data); for (int i = 0; i < data.length / 6; i++) { byte[] ipBytes = new byte[4]; peers.get(ipBytes); InetAddress ip = InetAddress.getByAddress(ipBytes); int port = (0xFF & (int) peers.get()) << 8 | (0xFF & (int) peers.get()); result.add(new Peer(new InetSocketAddress(ip, port))); } return result; }
if (ind == -1) { final InetAddress add = InetAddress.getByName(host); instanceList.add(new InetSocketAddress(add, Integer.parseInt(port))); } else { final String hostName = host.substring(0, ind); final String localIp = host.substring(ind + 1); final InetAddress add = InetAddresses.forString(localIp); final InetAddress inetAddress = InetAddress.getByAddress(hostName, add.getAddress()); instanceList.add(new InetSocketAddress(inetAddress, Integer.parseInt(port)));
/** * Create a socket address with the given host and port. The hostname * might be replaced with another host that was set via * {@link #addStaticResolution(String, String)}. The value of * hadoop.security.token.service.use_ip will determine whether the * standard java host resolver is used, or if the fully qualified resolver * is used. * @param host the hostname or IP use to instantiate the object * @param port the port number * @return InetSocketAddress */ public static InetSocketAddress createSocketAddrForHost(String host, int port) { String staticHost = getStaticResolution(host); String resolveHost = (staticHost != null) ? staticHost : host; InetSocketAddress addr; try { InetAddress iaddr = SecurityUtil.getByName(resolveHost); // if there is a static entry for the host, make the returned // address look like the original given host if (staticHost != null) { iaddr = InetAddress.getByAddress(host, iaddr.getAddress()); } addr = new InetSocketAddress(iaddr, port); } catch (UnknownHostException e) { addr = InetSocketAddress.createUnresolved(host, port); } return addr; }
byte[] ipv4 = new byte[4]; System.arraycopy(addr, offset, ipv4, 0, 4); address = InetAddress.getByAddress(ipv4); break; throw new Error(); return new InetSocketAddress(address, port); } catch (UnknownHostException e) { throw new Error("Should never happen", e);
if (addr != null) { try { resolvedAddr = new InetSocketAddress(InetAddress.getByAddress(uri.getHost(), addr), uri.getPort()); } catch (UnknownHostException e) {
if (addr != null) { try { resolvedAddr = new InetSocketAddress(InetAddress.getByAddress(uri.getHost(), addr), uri.getPort()); } catch (UnknownHostException e) {