public int getPort() { return socketAddress instanceof InetSocketAddress ? getInetSocketAddress().getPort() : -1; }
public int getPort() { return socketAddress instanceof InetSocketAddress ? getInetSocketAddress().getPort() : -1; }
public Inet4Address getInet4Address() { InetSocketAddress in = getInetSocketAddress(); if (in != null && in.getAddress() instanceof Inet4Address) { return (Inet4Address) in.getAddress(); } return null; }
public Inet6Address getInet6Address() { InetSocketAddress in = getInetSocketAddress(); if (in != null && in.getAddress() instanceof Inet6Address) { return (Inet6Address) in.getAddress(); } return null; }
public Inet6Address getInet6Address() { InetSocketAddress in = getInetSocketAddress(); if (in != null && in.getAddress() instanceof Inet6Address) { return (Inet6Address) in.getAddress(); } return null; }
public Inet4Address getInet4Address() { InetSocketAddress in = getInetSocketAddress(); if (in != null && in.getAddress() instanceof Inet4Address) { return (Inet4Address) in.getAddress(); } return null; }
@JRubyMethod(name = "ipv6_linklocal?") public IRubyObject ipv6_linklocal_p(ThreadContext context) { return context.runtime.newBoolean(getInetSocketAddress().getAddress().isLinkLocalAddress()); }
@JRubyMethod(name = "ipv6_linklocal?") public IRubyObject ipv6_linklocal_p(ThreadContext context) { return context.runtime.newBoolean(getInetSocketAddress().getAddress().isLinkLocalAddress()); }
@JRubyMethod(name = "ipv6_loopback?") public IRubyObject ipv6_loopback_p(ThreadContext context) { if (getAddressFamily() == AF_INET6) { return context.runtime.newBoolean(getInetSocketAddress().getAddress().isLoopbackAddress()); } return context.runtime.newBoolean(false); }
@JRubyMethod(name = "ipv6_loopback?") public IRubyObject ipv6_loopback_p(ThreadContext context) { if (getAddressFamily() == AF_INET6) { return context.runtime.newBoolean(getInetSocketAddress().getAddress().isLoopbackAddress()); } return context.runtime.newBoolean(false); }
@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); }
@JRubyMethod public IRubyObject canonname(ThreadContext context) { if (socketAddress instanceof InetSocketAddress) { return context.runtime.newString(getInetSocketAddress().getAddress().getCanonicalHostName()); } else if (socketAddress instanceof UnixSocketAddress) { return context.runtime.newString(getUnixSocketAddress().path()); } throw context.runtime.newNotImplementedError("canonname not implemented for socket address: " + socketAddress); }
@JRubyMethod public IRubyObject canonname(ThreadContext context) { if (socketAddress instanceof InetSocketAddress) { return context.runtime.newString(getInetSocketAddress().getAddress().getCanonicalHostName()); } else if (socketAddress instanceof UnixSocketAddress) { return context.runtime.newString(getUnixSocketAddress().path()); } throw context.runtime.newNotImplementedError("canonname not implemented for socket address: " + socketAddress); }
@JRubyMethod(optional = 1) public IRubyObject getnameinfo(ThreadContext context, IRubyObject[] args) { Ruby runtime = context.runtime; RubyString hostname; InetSocketAddress inet = getInetSocketAddress(); if (inet != null) { hostname = runtime.newString(inet.getHostName()); } else { UnixSocketAddress unix = getUnixSocketAddress(); hostname = runtime.newString(unix.path()); } RubyString rubyService = null; if (args.length > 0) { int flags = args[0].convertToInteger().getIntValue(); if ((flags & NameInfo.NI_NUMERICSERV.intValue()) != 0) { rubyService = runtime.newString(Integer.toString(getPort())); } } if (rubyService == null) { Service service = Service.getServiceByPort(getPort(), protocol.getName()); rubyService = runtime.newString(service.getName()); } return runtime.newArray(hostname, rubyService); }
@JRubyMethod(optional = 1) public IRubyObject getnameinfo(ThreadContext context, IRubyObject[] args) { Ruby runtime = context.runtime; RubyString hostname; InetSocketAddress inet = getInetSocketAddress(); if (inet != null) { hostname = runtime.newString(inet.getHostName()); } else { UnixSocketAddress unix = getUnixSocketAddress(); hostname = runtime.newString(unix.path()); } RubyString rubyService = null; if (args.length > 0) { int flags = args[0].convertToInteger().getIntValue(); if ((flags & NameInfo.NI_NUMERICSERV.intValue()) != 0) { rubyService = runtime.newString(Integer.toString(getPort())); } } if (rubyService == null) { Service service = Service.getServiceByPort(getPort(), protocol.getName()); rubyService = runtime.newString(service.getName()); } return runtime.newArray(hostname, rubyService); }
IRubyObject sockaddr = args[2]; if (sockaddr instanceof Addrinfo) { sockAddress = ((Addrinfo) sockaddr).getInetSocketAddress(); if (sockAddress == null) { throw SocketUtils.sockerr(runtime, "need AF_INET or AF_INET6 address");
IRubyObject sockaddr = args[2]; if (sockaddr instanceof Addrinfo) { sockAddress = ((Addrinfo) sockaddr).getInetSocketAddress(); if (sockAddress == null) { throw SocketUtils.sockerr(runtime, "need AF_INET or AF_INET6 address");