public static void writeSockaddrHeader(AddressFamily family, DataOutputStream ds) throws IOException { int value = family.intValue(); int high = (value & 0xff00) >> 8; int low = value & 0xff; ds.write((byte)high); ds.write((byte)low); }
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; }
public final String toString() { return description(); } public static AddressFamily valueOf(long value) {
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); } }
private void setDomain(Ruby runtime, IRubyObject domain) { AddressFamily family = SocketUtils.addressFamilyFromArg(domain); if (family == null) { throw SocketUtils.sockerr(runtime, "unknown socket domain " + domain); } soDomain = family; String name = soDomain.name(); if (name.startsWith("pseudo_")) name = name.substring(7); soProtocolFamily = ProtocolFamily.valueOf("PF" + name.substring(2)); }
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); } }
private void setDomain(Ruby runtime, IRubyObject domain) { AddressFamily family = SocketUtils.addressFamilyFromArg(domain); if (family == null) { throw SocketUtils.sockerr(runtime, "unknown socket domain " + domain); } soDomain = family; String name = soDomain.name(); if (name.startsWith("pseudo_")) name = name.substring(7); soProtocolFamily = ProtocolFamily.valueOf("PF" + name.substring(2)); }
public static void writeSockaddrHeader(AddressFamily family, DataOutputStream ds) throws IOException { int value = family.intValue(); int high = (value & 0xff00) >> 8; int low = value & 0xff; ds.write((byte)high); ds.write((byte)low); }
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; }
private void initDomain(Ruby runtime, IRubyObject domain) { AddressFamily family = SocketUtils.addressFamilyFromArg(domain); if (family == null) { throw SocketUtils.sockerr(runtime, "unknown socket domain " + domain); } soDomain = family; soProtocol = ProtocolFamily.valueOf("PF" + soDomain.name().substring(2)); }
public final String toString() { return description(); } public static AddressFamily valueOf(long value) {
public static void writeSockaddrHeader(AddressFamily family, DataOutputStream ds) throws IOException { int value = family.intValue(); int high = (value & 0xff00) >> 8; int low = value & 0xff; ds.write((byte)high); ds.write((byte)low); }
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); } }
private void initDomain(Ruby runtime, IRubyObject domain) { AddressFamily family = SocketUtils.addressFamilyFromArg(domain); if (family == null) { throw SocketUtils.sockerr(runtime, "unknown socket domain " + domain); } soDomain = family; soProtocol = ProtocolFamily.valueOf("PF" + soDomain.name().substring(2)); }
public final String toString() { return description(); } public static AddressFamily valueOf(long value) {
public static void writeSockaddrHeader(AddressFamily family, DataOutputStream ds) throws IOException { int value = family.intValue(); int high = (value & 0xff00) >> 8; int low = value & 0xff; ds.write((byte)high); ds.write((byte)low); }
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 IRubyObject pack_sockaddr_un(ThreadContext context, String unixpath) { final Ruby runtime = context.runtime; ByteBuffer buf = ByteBuffer.allocate(SOCKADDR_UN_SIZE); byte[] path = unixpath.getBytes(); if (path.length > SOCKADDR_UN_PATH) { String errorMsg = "too long unix socket path (%d bytes given but %d bytes max)"; String formattedErrorMsg = String.format(errorMsg, path.length, SOCKADDR_UN_PATH); throw runtime.newArgumentError(formattedErrorMsg); } int afamily = AddressFamily.AF_UNIX.intValue(); int high = (afamily & 0xff00) >> 8; int low = afamily & 0xff; buf.put((byte)high); buf.put((byte)low); buf.put(path); return RubyString.newString(runtime, buf.array()); }
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 IRubyObject pack_sockaddr_un(ThreadContext context, String unixpath) { final Ruby runtime = context.runtime; ByteBuffer buf = ByteBuffer.allocate(SOCKADDR_UN_SIZE); byte[] path = unixpath.getBytes(); if (path.length > SOCKADDR_UN_PATH) { String errorMsg = "too long unix socket path (%d bytes given but %d bytes max)"; String formattedErrorMsg = String.format(errorMsg, path.length, SOCKADDR_UN_PATH); throw runtime.newArgumentError(formattedErrorMsg); } int afamily = AddressFamily.AF_UNIX.intValue(); int high = (afamily & 0xff00) >> 8; int low = afamily & 0xff; buf.put((byte)high); buf.put((byte)low); buf.put(path); return RubyString.newString(runtime, buf.array()); }