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 toRemoteAddress(PoolKey key) throws UnknownHostException { final InetAddress inetAddr = InetAddress.getByAddress( key.host, NetUtil.createByteArrayFromIpAddressString(key.ipAddr)); return new InetSocketAddress(inetAddr, key.port); }
byte[] ipBytes = NetUtil.createByteArrayFromIpAddressString(lineParts.get(0));
byte[] ipBytes = NetUtil.createByteArrayFromIpAddressString(lineParts.get(0));
@Override public void encodeAsByteBuf(ByteBuf byteBuf) { byteBuf.writeByte(protocolVersion().byteValue()); byteBuf.writeByte(cmdType.byteValue()); byteBuf.writeByte(0x00); byteBuf.writeByte(addressType.byteValue()); switch (addressType) { case IPv4: { byteBuf.writeBytes(NetUtil.createByteArrayFromIpAddressString(host)); byteBuf.writeShort(port); break; } case DOMAIN: { byteBuf.writeByte(host.length()); byteBuf.writeCharSequence(host, CharsetUtil.US_ASCII); byteBuf.writeShort(port); break; } case IPv6: { byteBuf.writeBytes(NetUtil.createByteArrayFromIpAddressString(host)); byteBuf.writeShort(port); break; } } } }
@Override protected void encode(ChannelHandlerContext ctx, Socks4CommandResponse msg, ByteBuf out) throws Exception { out.writeByte(0); out.writeByte(msg.status().byteValue()); out.writeShort(msg.dstPort()); out.writeBytes(msg.dstAddr() == null? IPv4_HOSTNAME_ZEROED : NetUtil.createByteArrayFromIpAddressString(msg.dstAddr())); } }
case IPv4: { byte[] hostContent = host == null ? IPv4_HOSTNAME_ZEROED : NetUtil.createByteArrayFromIpAddressString(host); byteBuf.writeBytes(hostContent); byteBuf.writeShort(port); ? IPv6_HOSTNAME_ZEROED : NetUtil.createByteArrayFromIpAddressString(host); byteBuf.writeBytes(hostContent); byteBuf.writeShort(port);
@Override public void encodeAddress(Socks5AddressType addrType, String addrValue, ByteBuf out) throws Exception { final byte typeVal = addrType.byteValue(); if (typeVal == Socks5AddressType.IPv4.byteValue()) { if (addrValue != null) { out.writeBytes(NetUtil.createByteArrayFromIpAddressString(addrValue)); } else { out.writeInt(0); } } else if (typeVal == Socks5AddressType.DOMAIN.byteValue()) { if (addrValue != null) { out.writeByte(addrValue.length()); out.writeCharSequence(addrValue, CharsetUtil.US_ASCII); } else { out.writeByte(1); out.writeByte(0); } } else if (typeVal == Socks5AddressType.IPv6.byteValue()) { if (addrValue != null) { out.writeBytes(NetUtil.createByteArrayFromIpAddressString(addrValue)); } else { out.writeLong(0); out.writeLong(0); } } else { throw new EncoderException("unsupported addrType: " + (addrType.byteValue() & 0xFF)); } } };
byte[] addr = NetUtil.createByteArrayFromIpAddressString(uri.getHost()); if (addr != null) { try {
byte[] addr = NetUtil.createByteArrayFromIpAddressString(uri.getHost()); if (addr != null) { try {
/** * Hook designed for extensibility so one can pass a different cache on each resolution attempt * instead of using the global one. */ protected void doResolveAll(String inetHost, DnsRecord[] additionals, Promise<List<InetAddress>> promise, DnsCache resolveCache) throws Exception { if (inetHost == null || inetHost.isEmpty()) { // If an empty hostname is used we should use "localhost", just like InetAddress.getAllByName(...) does. promise.setSuccess(Collections.singletonList(loopbackAddress())); return; } final byte[] bytes = NetUtil.createByteArrayFromIpAddressString(inetHost); if (bytes != null) { // The unresolvedAddress was created via a String that contains an ipaddress. promise.setSuccess(Collections.singletonList(InetAddress.getByAddress(bytes))); return; } final String hostname = hostname(inetHost); InetAddress hostsFileEntry = resolveHostsFileEntry(hostname); if (hostsFileEntry != null) { promise.setSuccess(Collections.singletonList(hostsFileEntry)); return; } if (!doResolveAllCached(hostname, additionals, promise, resolveCache, resolvedInternetProtocolFamilies)) { doResolveAllUncached(hostname, additionals, promise, resolveCache); } }
@Override protected void decode(ChannelHandlerContext ctx, HAProxyMessage msg, List<Object> out) throws Exception { if (logger.isDebugEnabled()) { logger.debug("PROXY message {}: {}:{} -> {}:{} (next: {})", msg.protocolVersion().name(), msg.sourceAddress(), msg.sourcePort(), msg.destinationAddress(), msg.destinationPort(), proxiedCandidates); } final ChannelPipeline p = ctx.pipeline(); final InetAddress src = InetAddress.getByAddress( NetUtil.createByteArrayFromIpAddressString(msg.sourceAddress())); final InetAddress dst = InetAddress.getByAddress( NetUtil.createByteArrayFromIpAddressString(msg.destinationAddress())); final ProxiedAddresses proxiedAddresses = ProxiedAddresses.of(new InetSocketAddress(src, msg.sourcePort()), new InetSocketAddress(dst, msg.destinationPort())); configurePipeline(p, proxiedCandidates, proxiedAddresses); p.remove(this); } }
if (hostname == null || NetUtil.createByteArrayFromIpAddressString(hostname) != null) { hostname = config.getAddress().getHost();
@Override protected void encode(ChannelHandlerContext ctx, Socks4CommandRequest msg, ByteBuf out) throws Exception { out.writeByte(msg.version().byteValue()); out.writeByte(msg.type().byteValue()); out.writeShort(msg.dstPort()); if (NetUtil.isValidIpV4Address(msg.dstAddr())) { out.writeBytes(NetUtil.createByteArrayFromIpAddressString(msg.dstAddr())); ByteBufUtil.writeAscii(out, msg.userId()); out.writeByte(0); } else { out.writeBytes(IPv4_DOMAIN_MARKER); ByteBufUtil.writeAscii(out, msg.userId()); out.writeByte(0); ByteBufUtil.writeAscii(out, msg.dstAddr()); out.writeByte(0); } } }
/** * Hook designed for extensibility so one can pass a different cache on each resolution attempt * instead of using the global one. */ protected void doResolveAll(String inetHost, DnsRecord[] additionals, Promise<List<InetAddress>> promise, DnsCache resolveCache) throws Exception { if (inetHost == null || inetHost.isEmpty()) { // If an empty hostname is used we should use "localhost", just like InetAddress.getAllByName(...) does. promise.setSuccess(Collections.singletonList(loopbackAddress())); return; } final byte[] bytes = NetUtil.createByteArrayFromIpAddressString(inetHost); if (bytes != null) { // The unresolvedAddress was created via a String that contains an ipaddress. promise.setSuccess(Collections.singletonList(InetAddress.getByAddress(bytes))); return; } final String hostname = hostname(inetHost); InetAddress hostsFileEntry = resolveHostsFileEntry(hostname); if (hostsFileEntry != null) { promise.setSuccess(Collections.singletonList(hostsFileEntry)); return; } if (!doResolveAllCached(hostname, additionals, promise, resolveCache, resolvedInternetProtocolFamilies)) { doResolveAllUncached(hostname, additionals, promise, resolveCache); } }
/** * Hook designed for extensibility so one can pass a different cache on each resolution attempt * instead of using the global one. */ protected void doResolve(String inetHost, DnsRecord[] additionals, Promise<InetAddress> promise, DnsCache resolveCache) throws Exception { if (inetHost == null || inetHost.isEmpty()) { // If an empty hostname is used we should use "localhost", just like InetAddress.getByName(...) does. promise.setSuccess(loopbackAddress()); return; } final byte[] bytes = NetUtil.createByteArrayFromIpAddressString(inetHost); if (bytes != null) { // The inetHost is actually an ipaddress. promise.setSuccess(InetAddress.getByAddress(bytes)); return; } final String hostname = hostname(inetHost); InetAddress hostsFileEntry = resolveHostsFileEntry(hostname); if (hostsFileEntry != null) { promise.setSuccess(hostsFileEntry); return; } if (!doResolveCached(hostname, additionals, promise, resolveCache)) { doResolveUncached(hostname, additionals, promise, resolveCache); } }
RedisConnection connection = connectionFuture.syncUninterruptibly().getNow(); if (cfg.getNodeAddresses().size() == 1 && NetUtil.createByteArrayFromIpAddressString(addr.getHost()) == null) { configEndpointHostName = addr.getHost(); isConfigEndpoint = true;
RedisConnection connection = connectionFuture.syncUninterruptibly().getNow(); if (cfg.getNodeAddresses().size() == 1 && NetUtil.createByteArrayFromIpAddressString(addr.getHost()) == null) { configEndpointHostName = addr.getHost(); isConfigEndpoint = true;
/** * Hook designed for extensibility so one can pass a different cache on each resolution attempt * instead of using the global one. */ protected void doResolve(String inetHost, DnsRecord[] additionals, Promise<InetAddress> promise, DnsCache resolveCache) throws Exception { if (inetHost == null || inetHost.isEmpty()) { // If an empty hostname is used we should use "localhost", just like InetAddress.getByName(...) does. promise.setSuccess(loopbackAddress()); return; } final byte[] bytes = NetUtil.createByteArrayFromIpAddressString(inetHost); if (bytes != null) { // The inetHost is actually an ipaddress. promise.setSuccess(InetAddress.getByAddress(bytes)); return; } final String hostname = hostname(inetHost); InetAddress hostsFileEntry = resolveHostsFileEntry(hostname); if (hostsFileEntry != null) { promise.setSuccess(hostsFileEntry); return; } if (!doResolveCached(hostname, additionals, promise, resolveCache)) { doResolveUncached(hostname, additionals, promise, resolveCache); } }