@JRubyMethod public IRubyObject ip_address(ThreadContext context) { if (getAddressFamily() != AF_INET && getAddressFamily() != AF_INET6) { throw SocketUtils.sockerr(context.runtime, "need IPv4 or IPv6 address"); } // TODO: (gf) for IPv6 link-local address this appends a numeric interface index (like MS-Windows), should append interface name on Linux String fullHost = ((InetSocketAddress) socketAddress).getAddress().getHostAddress(); String host = (getAddressFamily() == AF_INET6) ? ipv6_ip() : fullHost; return context.runtime.newString(host); }
@JRubyMethod public IRubyObject ip_address(ThreadContext context) { if (getAddressFamily() != AF_INET && getAddressFamily() != AF_INET6) { throw SocketUtils.sockerr(context.runtime, "need IPv4 or IPv6 address"); } // TODO: (gf) for IPv6 link-local address this appends a numeric interface index (like MS-Windows), should append interface name on Linux String fullHost = ((InetSocketAddress) socketAddress).getAddress().getHostAddress(); String host = (getAddressFamily() == AF_INET6) ? ipv6_ip() : fullHost; return context.runtime.newString(host); }
@JRubyMethod public IRubyObject inspect_sockaddr(ThreadContext context) { if (socketAddress instanceof UnixSocketAddress) { String path = getUnixSocketAddress().path(); return context.runtime.newString(path.startsWith("/") ? path : "UNIX " + path); } int port = getInetSocketAddress().getPort(); if (getInetAddress() instanceof Inet6Address) { String host = ipv6_ip(); String hostPort = port == 0 ? host : "[" + host + "]:" + port; return context.runtime.newString(hostPort); } String portString = port == 0 ? "" : ":" + port; String host = getInetSocketAddress().getAddress().getHostAddress(); return context.runtime.newString(host + portString); }
@JRubyMethod public IRubyObject inspect_sockaddr(ThreadContext context) { if (socketAddress instanceof UnixSocketAddress) { String path = getUnixSocketAddress().path(); return context.runtime.newString(path.startsWith("/") ? path : "UNIX " + path); } int port = getInetSocketAddress().getPort(); if (getInetAddress() instanceof Inet6Address) { String host = ipv6_ip(); String hostPort = port == 0 ? host : "[" + host + "]:" + port; return context.runtime.newString(hostPort); } String portString = port == 0 ? "" : ":" + port; String host = getInetSocketAddress().getAddress().getHostAddress(); return context.runtime.newString(host + portString); }