@JRubyMethod(meta = true) public static IRubyObject tcp(ThreadContext context, IRubyObject recv, IRubyObject arg0, IRubyObject arg1) { Addrinfo addrinfo = new Addrinfo(context.runtime, (RubyClass)recv); addrinfo.initializeCommon(context.runtime, arg0, null, null, arg1); return addrinfo; }
@JRubyMethod(required = 1, optional = 4) public IRubyObject initialize(ThreadContext context, IRubyObject[] args) { switch (args.length) { case 1: return initialize(context, args[0]); case 2: return initialize(context, args[0], args[1]); case 3: return initialize(context, args[0], args[1], args[2]); } IRubyObject _sockaddr = args[0]; IRubyObject _family = args[1]; IRubyObject _socktype = args[2]; IRubyObject _protocol = args[3]; initializeCommon(context.runtime, _sockaddr, _family, _socktype, _protocol); return context.nil; }
public static InetSocketAddress addressFromArg(ThreadContext context, IRubyObject arg) { InetSocketAddress iaddr; if (arg instanceof Addrinfo) { Addrinfo addrinfo = (Addrinfo)arg; if (!addrinfo.ip_p(context).isTrue()) { throw context.runtime.newTypeError("not an INET or INET6 address: " + addrinfo); } iaddr = new InetSocketAddress(addrinfo.getInetAddress(), addrinfo.getPort()); } else { iaddr = addressFromSockaddr_in(context, arg); } return iaddr; }
public static InetSocketAddress addressFromArg(ThreadContext context, IRubyObject arg) { InetSocketAddress iaddr; if (arg instanceof Addrinfo) { Addrinfo addrinfo = (Addrinfo)arg; iaddr = new InetSocketAddress(addrinfo.getInetAddress(), addrinfo.getPort()); } else { iaddr = addressFromSockaddr_in(context, arg); } return iaddr; }
@JRubyMethod(visibility = Visibility.PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject _sockaddr) { initializeCommon(context, _sockaddr, null, null, null); return context.nil; }
@Override protected IRubyObject addrFor(ThreadContext context, InetSocketAddress addr, boolean reverse) { final Ruby runtime = context.runtime; return new Addrinfo(runtime, runtime.getClass("Addrinfo"), addr.getAddress(), addr.getPort(), Sock.SOCK_DGRAM); }
@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(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); }
int _port = service.convertToInteger().getIntValue(); if (!nodename.isNil()) inetAddress = getRubyInetAddress(nodename); if (inetAddress == null) inetAddress = getRubyInetAddress(numericnode); inetAddress = getRubyInetAddress(sockaddr); if (inetAddress == null) { if (getInetAddress() instanceof Inet4Address) { this.pfamily = PF_INET; } else { setSockAndProtocol(sock); } catch (IOException ioe) { ioe.printStackTrace();
@JRubyMethod public IRubyObject local_address(ThreadContext context) { Ruby runtime = context.runtime; InetSocketAddress address = getInetSocketAddress(); if (address != null) { SocketType socketType = SocketType.forChannel(getChannel()); return new Addrinfo(runtime, runtime.getClass("Addrinfo"), address, socketType.getSocketType(), socketType); } UnixSocketAddress unix = getUnixSocketAddress(); return Addrinfo.unix(context, runtime.getClass("Addrinfo"), runtime.newString(unix.path())); }
@JRubyMethod(name = "ipv4_multicast?") public IRubyObject ipv4_multicast_p(ThreadContext context) { if (getAddressFamily() == AF_INET) { return context.runtime.newBoolean(getInet4Address().isMulticastAddress()); } return context.fals; }
@JRubyMethod(name = "ipv6_unspecified?") public IRubyObject ipv6_unspecified_p(ThreadContext context) { if (getAddressFamily() == AF_INET6) { return context.runtime.newBoolean(getInet6Address().getHostAddress().equals("::")); } return context.fals; }
public void load(final Ruby runtime, boolean wrap) throws IOException { runtime.defineClass("SocketError", runtime.getStandardError(), runtime.getStandardError().getAllocator()); RubyBasicSocket.createBasicSocket(runtime); RubySocket.createSocket(runtime); RubyServerSocket.createServerSocket(runtime); if (runtime.getInstanceConfig().isNativeEnabled() && !Platform.IS_WINDOWS) { RubyUNIXSocket.createUNIXSocket(runtime); RubyUNIXServer.createUNIXServer(runtime); } RubyIPSocket.createIPSocket(runtime); RubyTCPSocket.createTCPSocket(runtime); RubyTCPServer.createTCPServer(runtime); RubyUDPSocket.createUDPSocket(runtime); Addrinfo.createAddrinfo(runtime); Option.createOption(runtime); Ifaddr.createIfaddr(runtime); } }
@JRubyMethod(name = "ipv6_v4mapped?") public IRubyObject ipv6_v4mapped_p(ThreadContext context) { Inet6Address in6 = getInet6Address(); return context.runtime.newBoolean(in6 != null && // Java always converts mapped ipv6 addresses to ipv4 form in6.getHostAddress().indexOf(":") == -1); }
private String ipv6_ip() { if (getAddressFamily() != AF_INET6) return null; InetAddress in = getInetAddress(); if (in.isLoopbackAddress()) return "::1"; return SocketUtilsIPV6.getIPV6Address(in.getHostAddress()); }
public int getPort() { return socketAddress instanceof InetSocketAddress ? getInetSocketAddress().getPort() : -1; }
@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); }
public Addrinfo(Ruby runtime, RubyClass cls, SocketAddress socketAddress) { super(runtime, cls); this.socketAddress = socketAddress; this.pfamily = ProtocolFamily.valueOf(getAddressFamily().intValue()); setSockAndProtocol(Sock.SOCK_STREAM); }
@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 unix_path(ThreadContext context) { if (getAddressFamily() != AF_UNIX) { throw SocketUtils.sockerr(context.runtime, "need AF_UNIX address"); } return context.runtime.newString(getUnixSocketAddress().path()); }