public static String toAddressString(InetSocketAddress address) { return address.getAddress().getHostAddress() + ":" + address.getPort(); }
/** * get remote host. * * @return remote host */ public String getRemoteHost() { return remoteAddress == null ? null : remoteAddress.getAddress() == null ? remoteAddress.getHostName() : NetUtils.filterLocalHost(remoteAddress.getAddress().getHostAddress()); }
@Override public Channel getChannel(InetSocketAddress remoteAddress) { String host = remoteAddress.getAddress() != null ? remoteAddress.getAddress().getHostAddress() : remoteAddress.getHostName(); int port = remoteAddress.getPort(); Channel channel = super.getChannel(remoteAddress); if (channel == null) { for (Map.Entry<URL, Client> entry : clients.entrySet()) { URL url = entry.getKey(); if (url.getIp().equals(host) && url.getPort() == port) { return entry.getValue(); } } } return channel; }
/** {@inheritDoc} */ @Override public Collection<InetSocketAddress> getExternalAddresses(InetSocketAddress addr) throws IgniteCheckedException { InetSocketAddress inetSockAddr = inetSockAddrMap.get(addr); if (inetSockAddr != null) return Collections.singletonList(inetSockAddr); InetAddress inetAddr = inetAddrMap.get(addr.getAddress()); if (inetAddr != null) return Collections.singletonList(new InetSocketAddress(inetAddr, addr.getPort())); return Collections.emptyList(); }
public Proxy toProxyAddress() { before(); InetSocketAddress address = new InetSocketAddress(inetSocketAddress.getAddress() .getCanonicalHostName(), getPort()); return new Proxy(Proxy.Type.HTTP, address); }
public AbstractRemotingServer(int port) { this(new InetSocketAddress(port).getAddress().getHostAddress(), port); }
@Override public void serialize(InetSocketAddress value, JsonGenerator jgen, SerializerProvider provider) throws IOException { InetAddress addr = value.getAddress(); String str = addr == null ? value.getHostName() : addr.toString().trim(); int ix = str.indexOf('/'); if (ix >= 0) { if (ix == 0) { // missing host name; use address str = addr instanceof Inet6Address ? "[" + str.substring(1) + "]" // bracket IPv6 addresses with : str.substring(1); } else { // otherwise use name str = str.substring(0, ix); } } jgen.writeString(str + ":" + value.getPort()); }
public MCMPConfig(Builder builder) { this.managementSocketAddress = new InetSocketAddress(builder.managementHost, builder.managementPort); if (managementSocketAddress.isUnresolved()) { throw UndertowLogger.PROXY_REQUEST_LOGGER.unableToResolveModClusterManagementHost(builder.managementHost); } if (managementSocketAddress.getAddress().isAnyLocalAddress()) { throw UndertowLogger.PROXY_REQUEST_LOGGER.cannotUseWildcardAddressAsModClusterManagementHost(builder.managementHost); } if (builder.advertiseBuilder != null) { this.advertiseConfig = new AdvertiseConfig(builder.advertiseBuilder, this); } else { this.advertiseConfig = null; } }
/** * Encodes an IP address and port to be included in URL. in particular, this method makes * sure that IPv6 addresses have the proper formatting to be included in URLs. * * @param address The socket address with the IP address and port. * @return The proper URL string encoded IP address and port. */ public static String socketAddressToUrlString(InetSocketAddress address) { if (address.isUnresolved()) { throw new IllegalArgumentException("Address cannot be resolved: " + address.getHostString()); } return ipAddressAndPortToUrlString(address.getAddress(), address.getPort()); }
@Test public void testLiteralIPNoReverseNS() { byte size = 30; HostProvider hostProvider = getHostProviderUnresolved(size); for (int i = 0; i < size; i++) { InetSocketAddress next = hostProvider.next(0); assertThat(next, instanceOf(InetSocketAddress.class)); assertFalse(next.isUnresolved()); assertTrue(next.toString().startsWith("/")); // Do NOT trigger the reverse name service lookup. String hostname = next.getHostString(); // In this case, the hostname equals literal IP address. assertEquals(next.getAddress().getHostAddress(), hostname); } }
@Override public MasterSlaveEntry getEntry(InetSocketAddress address) { for (MasterSlaveEntry entry : client2entry.values()) { InetSocketAddress addr = entry.getClient().getAddr(); if (addr.getAddress().equals(address.getAddress()) && addr.getPort() == address.getPort()) { return entry; } } return null; }
@Override public int compare(InetSocketAddress addr1, InetSocketAddress addr2) { if (addr1.equals(addr2)) { return 0; } if (!addr1.isUnresolved() && !addr2.isUnresolved()) { if (addr1.getAddress().getClass() == addr2.getAddress().getClass()) { return 0; } return preferredAddressType.isAssignableFrom(addr1.getAddress().getClass()) ? -1 : 1; } if (addr1.isUnresolved() && addr2.isUnresolved()) { return 0; } return addr1.isUnresolved() ? 1 : -1; } }
public static String getAmHostNameFromAddress(InetSocketAddress address, Configuration conf) { if (!HiveConf.getBoolVar(conf, HiveConf.ConfVars.LLAP_DAEMON_AM_USE_FQDN)) { return address.getHostName(); } InetAddress ia = address.getAddress(); // getCanonicalHostName would either return FQDN, or an IP. return (ia == null) ? address.getHostName() : ia.getCanonicalHostName(); }
@Override public ExchangeChannel getExchangeChannel(InetSocketAddress remoteAddress) { String host = remoteAddress.getAddress() != null ? remoteAddress.getAddress().getHostAddress() : remoteAddress.getHostName(); int port = remoteAddress.getPort(); ExchangeChannel channel = super.getExchangeChannel(remoteAddress); if (channel == null) { for (Map.Entry<URL, ExchangeClient> entry : clients.entrySet()) { URL url = entry.getKey(); if (url.getIp().equals(host) && url.getPort() == port) { return entry.getValue(); } } } return channel; }
public static String toAddressString(InetSocketAddress address) { return address.getAddress().getHostAddress() + ":" + address.getPort(); }
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()); }
/** * get remote host. * * @return remote host */ public String getRemoteHost() { return remoteAddress == null ? null : remoteAddress.getAddress() == null ? remoteAddress.getHostName() : NetUtils.filterLocalHost(remoteAddress.getAddress().getHostAddress()); }
public NetEndpoint(String host, int port) { this.host = host; this.port = port; inetSocketAddress = new InetSocketAddress(host, port); inetAddress = inetSocketAddress.getAddress(); hostAndPort = host + ":" + port; }
@Override public void serialize(InetSocketAddress value, JsonGenerator jgen, SerializerProvider provider) throws IOException { InetAddress addr = value.getAddress(); String str = addr == null ? value.getHostName() : addr.toString().trim(); int ix = str.indexOf('/'); if (ix >= 0) { if (ix == 0) { // missing host name; use address str = addr instanceof Inet6Address ? "[" + str.substring(1) + "]" // bracket IPv6 addresses with : str.substring(1); } else { // otherwise use name str = str.substring(0, ix); } } jgen.writeString(str + ":" + value.getPort()); }
this.dnsServer = new InetSocketAddress(options.getHost(), options.getPort()); if (this.dnsServer.isUnresolved()) { throw new IllegalArgumentException("Cannot resolve the host to a valid ip address"); channel = transport.datagramChannel(this.dnsServer.getAddress() instanceof Inet4Address ? InternetProtocolFamily.IPv4 : InternetProtocolFamily.IPv6); channel.config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true); MaxMessagesRecvByteBufAllocator bufAllocator = channel.config().getRecvByteBufAllocator();