void setTcpMd5Sig(InetAddress address, byte[] key) throws IOException { final NativeInetAddress a = NativeInetAddress.newInstance(address); setTcpMd5Sig(intValue(), a.address(), a.scopeId(), key); }
public static NativeInetAddress newInstance(InetAddress addr) { byte[] bytes = addr.getAddress(); if (addr instanceof Inet6Address) { return new NativeInetAddress(bytes, ((Inet6Address) addr).getScopeId()); } else { // convert to ipv4 mapped ipv6 address; return new NativeInetAddress(ipv4MappedIpv6Address(bytes)); } }
public static InetSocketAddress address(byte[] addr, int offset, int len) { final int port = decodeInt(addr, offset + len - 4); final InetAddress address; byte[] ipv6 = new byte[16]; System.arraycopy(addr, offset, ipv6, 0, 16); int scopeId = decodeInt(addr, offset + len - 8); address = Inet6Address.getByAddress(null, ipv6, scopeId); break;
public final InetSocketAddress remoteAddress() { byte[] addr = remoteAddress(fd); // addr may be null if getpeername failed. // See https://github.com/netty/netty/issues/3328 return addr == null ? null : address(addr, 0, addr.length); }
/** * Init this instance and return {@code true} if the init was successful. */ private boolean init(ByteBuf buf, InetSocketAddress recipient) { array.clear(); if (!array.add(buf)) { return false; } // always start from offset 0 memoryAddress = array.memoryAddress(0); count = array.count(); InetAddress address = recipient.getAddress(); if (address instanceof Inet6Address) { addr = address.getAddress(); scopeId = ((Inet6Address) address).getScopeId(); } else { addr = ipv4MappedIpv6Address(address.getAddress()); scopeId = 0; } port = recipient.getPort(); return true; } }
public final boolean connect(SocketAddress socketAddress) throws IOException { int res; if (socketAddress instanceof InetSocketAddress) { InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; NativeInetAddress address = NativeInetAddress.newInstance(inetSocketAddress.getAddress()); res = connect(fd, address.address, address.scopeId, inetSocketAddress.getPort()); } else if (socketAddress instanceof DomainSocketAddress) { DomainSocketAddress unixDomainSocketAddress = (DomainSocketAddress) socketAddress; res = connectDomainSocket(fd, unixDomainSocketAddress.path().getBytes(CharsetUtil.UTF_8)); } else { throw new Error("Unexpected SocketAddress implementation " + socketAddress); } if (res < 0) { if (res == ERRNO_EINPROGRESS_NEGATIVE) { // connect not complete yet need to wait for EPOLLOUT event return false; } throwConnectException("connect", CONNECT_REFUSED_EXCEPTION, res); } return true; }
public final InetSocketAddress localAddress() { byte[] addr = localAddress(fd); // addr may be null if getpeername failed. // See https://github.com/netty/netty/issues/3328 return addr == null ? null : address(addr, 0, addr.length); }
public final int sendTo(ByteBuffer buf, int pos, int limit, InetAddress addr, int port) throws IOException { // just duplicate the toNativeInetAddress code here to minimize object creation as this method is expected // to be called frequently byte[] address; int scopeId; if (addr instanceof Inet6Address) { address = addr.getAddress(); scopeId = ((Inet6Address) addr).getScopeId(); } else { // convert to ipv4 mapped ipv6 address; scopeId = 0; address = ipv4MappedIpv6Address(addr.getAddress()); } int res = sendTo(fd, buf, pos, limit, address, scopeId, port); if (res >= 0) { return res; } if (res == ERROR_ECONNREFUSED_NEGATIVE) { throw new PortUnreachableException("sendTo failed"); } return ioResult("sendTo", res, SEND_TO_CONNECTION_RESET_EXCEPTION, SEND_TO_CLOSED_CHANNEL_EXCEPTION); }
public final void bind(SocketAddress socketAddress) throws IOException { if (socketAddress instanceof InetSocketAddress) { InetSocketAddress addr = (InetSocketAddress) socketAddress; NativeInetAddress address = NativeInetAddress.newInstance(addr.getAddress()); int res = bind(fd, address.address, address.scopeId, addr.getPort()); if (res < 0) { throw newIOException("bind", res); } } else if (socketAddress instanceof DomainSocketAddress) { DomainSocketAddress addr = (DomainSocketAddress) socketAddress; int res = bindDomainSocket(fd, addr.path().getBytes(CharsetUtil.UTF_8)); if (res < 0) { throw newIOException("bind", res); } } else { throw new Error("Unexpected SocketAddress implementation " + socketAddress); } }
void setTcpMd5Sig(InetAddress address, byte[] key) throws IOException { final NativeInetAddress a = NativeInetAddress.newInstance(address); setTcpMd5Sig(intValue(), a.address(), a.scopeId(), key); }
public final InetSocketAddress remoteAddress() { byte[] addr = remoteAddress(fd); // addr may be null if getpeername failed. // See https://github.com/netty/netty/issues/3328 return addr == null ? null : address(addr, 0, addr.length); }
public static NativeInetAddress newInstance(InetAddress addr) { byte[] bytes = addr.getAddress(); if (addr instanceof Inet6Address) { return new NativeInetAddress(bytes, ((Inet6Address) addr).getScopeId()); } else { // convert to ipv4 mapped ipv6 address; return new NativeInetAddress(ipv4MappedIpv6Address(bytes)); } }
public final int sendToAddresses(long memoryAddress, int length, InetAddress addr, int port) throws IOException { // just duplicate the toNativeInetAddress code here to minimize object creation as this method is expected // to be called frequently byte[] address; int scopeId; if (addr instanceof Inet6Address) { address = addr.getAddress(); scopeId = ((Inet6Address) addr).getScopeId(); } else { // convert to ipv4 mapped ipv6 address; scopeId = 0; address = ipv4MappedIpv6Address(addr.getAddress()); } int res = sendToAddresses(fd, memoryAddress, length, address, scopeId, port); if (res >= 0) { return res; } if (res == ERROR_ECONNREFUSED_NEGATIVE) { throw new PortUnreachableException("sendToAddresses failed"); } return ioResult("sendToAddresses", res, CONNECTION_RESET_EXCEPTION_SENDMSG, SEND_TO_ADDRESSES_CLOSED_CHANNEL_EXCEPTION); }
public final boolean connect(SocketAddress socketAddress) throws IOException { int res; if (socketAddress instanceof InetSocketAddress) { InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; NativeInetAddress address = NativeInetAddress.newInstance(inetSocketAddress.getAddress()); res = connect(fd, address.address, address.scopeId, inetSocketAddress.getPort()); } else if (socketAddress instanceof DomainSocketAddress) { DomainSocketAddress unixDomainSocketAddress = (DomainSocketAddress) socketAddress; res = connectDomainSocket(fd, unixDomainSocketAddress.path().getBytes(CharsetUtil.UTF_8)); } else { throw new Error("Unexpected SocketAddress implementation " + socketAddress); } if (res < 0) { if (res == ERRNO_EINPROGRESS_NEGATIVE) { // connect not complete yet need to wait for EPOLLOUT event return false; } throwConnectException("connect", CONNECT_REFUSED_EXCEPTION, res); } return true; }
public static InetSocketAddress address(byte[] addr, int offset, int len) { final int port = decodeInt(addr, offset + len - 4); final InetAddress address; byte[] ipv6 = new byte[16]; System.arraycopy(addr, offset, ipv6, 0, 16); int scopeId = decodeInt(addr, offset + len - 8); address = Inet6Address.getByAddress(null, ipv6, scopeId); break;
void setTcpMd5Sig(InetAddress address, byte[] key) throws IOException { final NativeInetAddress a = NativeInetAddress.newInstance(address); setTcpMd5Sig(intValue(), a.address(), a.scopeId(), key); }
public final InetSocketAddress localAddress() { byte[] addr = localAddress(fd); // addr may be null if getpeername failed. // See https://github.com/netty/netty/issues/3328 return addr == null ? null : address(addr, 0, addr.length); }
public static NativeInetAddress newInstance(InetAddress addr) { byte[] bytes = addr.getAddress(); if (addr instanceof Inet6Address) { return new NativeInetAddress(bytes, ((Inet6Address) addr).getScopeId()); } else { // convert to ipv4 mapped ipv6 address; return new NativeInetAddress(ipv4MappedIpv6Address(bytes)); } }
public final int sendToAddress(long memoryAddress, int pos, int limit, InetAddress addr, int port) throws IOException { // just duplicate the toNativeInetAddress code here to minimize object creation as this method is expected // to be called frequently byte[] address; int scopeId; if (addr instanceof Inet6Address) { address = addr.getAddress(); scopeId = ((Inet6Address) addr).getScopeId(); } else { // convert to ipv4 mapped ipv6 address; scopeId = 0; address = ipv4MappedIpv6Address(addr.getAddress()); } int res = sendToAddress(fd, memoryAddress, pos, limit, address, scopeId, port); if (res >= 0) { return res; } if (res == ERROR_ECONNREFUSED_NEGATIVE) { throw new PortUnreachableException("sendToAddress failed"); } return ioResult("sendToAddress", res, SEND_TO_ADDRESS_CONNECTION_RESET_EXCEPTION, SEND_TO_ADDRESS_CLOSED_CHANNEL_EXCEPTION); }
public final void bind(SocketAddress socketAddress) throws IOException { if (socketAddress instanceof InetSocketAddress) { InetSocketAddress addr = (InetSocketAddress) socketAddress; NativeInetAddress address = NativeInetAddress.newInstance(addr.getAddress()); int res = bind(fd, address.address, address.scopeId, addr.getPort()); if (res < 0) { throw newIOException("bind", res); } } else if (socketAddress instanceof DomainSocketAddress) { DomainSocketAddress addr = (DomainSocketAddress) socketAddress; int res = bindDomainSocket(fd, addr.path().getBytes(CharsetUtil.UTF_8)); if (res < 0) { throw newIOException("bind", res); } } else { throw new Error("Unexpected SocketAddress implementation " + socketAddress); } }