static AddressFamily addressFamilyFromArg(IRubyObject domain) { AddressFamily addressFamily = null; if(domain instanceof RubyString || domain instanceof RubySymbol) { String domainString = domain.toString(); addressFamily = AddressFamily.valueOf("AF_" + domainString); } else { int domainInt = RubyNumeric.fix2int(domain); addressFamily = AddressFamily.valueOf(domainInt); } return addressFamily; }
static AddressFamily addressFamilyFromArg(IRubyObject domain) { AddressFamily addressFamily = null; if(domain instanceof RubyString || domain instanceof RubySymbol) { String domainString = domain.toString(); addressFamily = AddressFamily.valueOf("AF_" + domainString); } else { int domainInt = RubyNumeric.fix2int(domain); addressFamily = AddressFamily.valueOf(domainInt); } return addressFamily; }
static AddressFamily addressFamilyFromArg(IRubyObject domain) { IRubyObject maybeString = TypeConverter.checkStringType(domain.getRuntime(), domain); if (!maybeString.isNil()) { domain = maybeString; } try { if (domain instanceof RubyString || domain instanceof RubySymbol) { String domainString = domain.toString(); if (domainString.startsWith("AF_")) return AddressFamily.valueOf(domainString); if (domainString.startsWith("PF_")) return AddressFamily.valueOf(ProtocolFamily.valueOf(domainString).intValue()); return AddressFamily.valueOf("AF_" + domainString); } int domainInt = RubyNumeric.fix2int(domain); return AddressFamily.valueOf(domainInt); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(domain.getRuntime(), "invalid address family: " + domain); } }
static AddressFamily addressFamilyFromArg(IRubyObject domain) { IRubyObject maybeString = TypeConverter.checkStringType(domain.getRuntime(), domain); if (!maybeString.isNil()) { domain = maybeString; } try { if (domain instanceof RubyString || domain instanceof RubySymbol) { String domainString = domain.toString(); if (domainString.startsWith("AF_")) return AddressFamily.valueOf(domainString); if (domainString.startsWith("PF_")) return AddressFamily.valueOf(ProtocolFamily.valueOf(domainString).intValue()); return AddressFamily.valueOf("AF_" + domainString); } int domainInt = RubyNumeric.fix2int(domain); return AddressFamily.valueOf(domainInt); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(domain.getRuntime(), "invalid address family: " + domain); } }
public static void validateSockaddr(Ruby runtime, ByteList val) { int high = val.get(0) & 0xff; int low = val.get(1) & 0xff; AddressFamily af = AddressFamily.valueOf((high << 8) + low); if (af != AddressFamily.AF_INET && af != AddressFamily.AF_INET6) { throw runtime.newArgumentError("can't resolve socket address of wrong type"); } }
public static void validateSockaddr(Ruby runtime, ByteList val) { int high = val.get(0) & 0xff; int low = val.get(1) & 0xff; AddressFamily af = AddressFamily.valueOf((high << 8) + low); if (af != AddressFamily.AF_INET && af != AddressFamily.AF_INET6) { throw runtime.newArgumentError("can't resolve socket address of wrong type"); } }
public static SocketAddress sockaddrFromBytes(Ruby runtime, byte[] val) throws IOException { AddressFamily afamily = AddressFamily.valueOf(uint16(val[0], val[1])); if (afamily == null || afamily == AddressFamily.__UNKNOWN_CONSTANT__) { throw runtime.newArgumentError("can't resolve socket address of wrong type"); } int port; switch (afamily) { case AF_INET: port = uint16(val[2], val[3]); Inet4Address inet4Address = (Inet4Address)InetAddress.getByAddress(Helpers.subseq(val, 4, 4)); return new InetSocketAddress(inet4Address, port); case AF_INET6: port = uint16(val[2], val[3]); Inet6Address inet6Address = (Inet6Address)InetAddress.getByAddress(Helpers.subseq(val, 4, 16)); return new InetSocketAddress(inet6Address, port); case AF_UNIX: String path = new String(val, 2, val.length - 2); return new UnixSocketAddress(new File(path)); default: throw runtime.newArgumentError("can't resolve socket address of wrong type"); } }
public static AddressFamily getAddressFamilyFromSockaddr(Ruby runtime, ByteList val) { if (val.length() < 2) { throw runtime.newArgumentError("too short sockaddr"); } int high = val.get(0) & 0xff; int low = val.get(1) & 0xff; return AddressFamily.valueOf((high << 8) + low); }
public static SocketAddress sockaddrFromBytes(Ruby runtime, byte[] val) throws IOException { AddressFamily afamily = AddressFamily.valueOf(uint16(val[0], val[1])); if (afamily == null || afamily == AddressFamily.__UNKNOWN_CONSTANT__) { throw runtime.newArgumentError("can't resolve socket address of wrong type"); } int port; switch (afamily) { case AF_INET: port = uint16(val[2], val[3]); Inet4Address inet4Address = (Inet4Address)InetAddress.getByAddress(Helpers.subseq(val, 4, 4)); return new InetSocketAddress(inet4Address, port); case AF_INET6: port = uint16(val[2], val[3]); Inet6Address inet6Address = (Inet6Address)InetAddress.getByAddress(Helpers.subseq(val, 4, 16)); return new InetSocketAddress(inet6Address, port); case AF_UNIX: String path = new String(val, 2, val.length - 2); return new UnixSocketAddress(new File(path)); default: throw runtime.newArgumentError("can't resolve socket address of wrong type"); } }
public static AddressFamily getAddressFamilyFromSockaddr(Ruby runtime, ByteList val) { if (val.length() < 2) { throw runtime.newArgumentError("too short sockaddr"); } int high = val.get(0) & 0xff; int low = val.get(1) & 0xff; return AddressFamily.valueOf((high << 8) + low); }
static ProtocolFamily protocolFamilyFromArg(IRubyObject protocol) { IRubyObject maybeString = TypeConverter.checkStringType(protocol.getRuntime(), protocol); if (!maybeString.isNil()) { protocol = maybeString; } try { if (protocol instanceof RubyString || protocol instanceof RubySymbol) { String protocolString = protocol.toString(); if (protocolString.startsWith("PF_")) return ProtocolFamily.valueOf(protocolString); if (protocolString.startsWith("AF_")) return ProtocolFamily.valueOf(AddressFamily.valueOf(protocolString).intValue()); return ProtocolFamily.valueOf("PF_" + protocolString); } int protocolInt = RubyNumeric.fix2int(protocol); return ProtocolFamily.valueOf(protocolInt); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(protocol.getRuntime(), "invalid protocol family: " + protocol); } }
static ProtocolFamily protocolFamilyFromArg(IRubyObject protocol) { IRubyObject maybeString = TypeConverter.checkStringType(protocol.getRuntime(), protocol); if (!maybeString.isNil()) { protocol = maybeString; } try { if (protocol instanceof RubyString || protocol instanceof RubySymbol) { String protocolString = protocol.toString(); if (protocolString.startsWith("PF_")) return ProtocolFamily.valueOf(protocolString); if (protocolString.startsWith("AF_")) return ProtocolFamily.valueOf(AddressFamily.valueOf(protocolString).intValue()); return ProtocolFamily.valueOf("PF_" + protocolString); } int protocolInt = RubyNumeric.fix2int(protocol); return ProtocolFamily.valueOf(protocolInt); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(protocol.getRuntime(), "invalid protocol family: " + protocol); } }