public static IRubyObject gethostbyaddr(ThreadContext context, IRubyObject[] args) { Ruby runtime = context.runtime; IRubyObject[] ret = new IRubyObject[4]; ret[0] = runtime.newString( Sockaddr.addressFromString(runtime, args[0].convertToString().toString()) .getCanonicalHostName()); ret[1] = runtime.newArray(); ret[2] = runtime.newFixnum(2); // AF_INET ret[3] = args[0]; return runtime.newArrayNoCopy(ret); }
public static IRubyObject gethostbyname(ThreadContext context, IRubyObject hostname) { Ruby runtime = context.runtime; try { InetAddress addr = getRubyInetAddress(hostname.convertToString().getByteList()); IRubyObject[] ret = new IRubyObject[4]; ret[0] = runtime.newString(addr.getCanonicalHostName()); ret[1] = runtime.newArray(); ret[2] = runtime.newFixnum(2); // AF_INET ret[3] = runtime.newString(new ByteList(addr.getAddress())); return runtime.newArrayNoCopy(ret); } catch (UnknownHostException e) { throw sockerr(runtime, "gethostbyname: name or service not known"); } }
protected IRubyObject addrFor(ThreadContext context, InetSocketAddress addr, boolean reverse) { Ruby r = context.runtime; IRubyObject[] ret = new IRubyObject[4]; if (addr.getAddress() instanceof Inet6Address) { ret[0] = r.newString("AF_INET6"); } else { ret[0] = r.newString("AF_INET"); } ret[1] = r.newFixnum(addr.getPort()); String hostAddress = addr.getAddress().getHostAddress(); if (!reverse || doNotReverseLookup(context)) { ret[2] = r.newString(hostAddress); } else { ret[2] = r.newString(addr.getHostName()); } ret[3] = r.newString(hostAddress); return r.newArrayNoCopy(ret); }