private String ipv6_ip() { if (getAddressFamily() != AF_INET6) return null; InetAddress in = getInetAddress(); if (in.isLoopbackAddress()) return "::1"; return SocketUtilsIPV6.getIPV6Address(in.getHostAddress()); }
private void setNetmask(InterfaceAddress it) throws Exception { if ( ( isLoopback || ( it.getNetworkPrefixLength() != 0 ) ) && ( address instanceof Inet4Address) ) { String subnet = ipAddress() + "/" + it.getNetworkPrefixLength(); if ( isLoopback ) { subnet = ipAddress() + "/8"; // because getNetworkPrefixLength() incorrectly returns 0 for IPv4 loopback } SubnetUtils utils = new SubnetUtils(subnet); netmask = utils.getInfo().getNetmask(); } else if ( (it.getNetworkPrefixLength() != 0 ) && ( address instanceof Inet6Address) ) { netmask = SocketUtilsIPV6.getIPV6NetMask(ipAddress() + "/" + it.getNetworkPrefixLength()); } }
private void setNetmask(InterfaceAddress it) throws Exception { if ( ( isLoopback || ( it.getNetworkPrefixLength() != 0 ) ) && ( address instanceof Inet4Address) ) { String subnet = ipAddress() + "/" + it.getNetworkPrefixLength(); if ( isLoopback ) { subnet = ipAddress() + "/8"; // because getNetworkPrefixLength() incorrectly returns 0 for IPv4 loopback } SubnetUtils utils = new SubnetUtils(subnet); netmask = utils.getInfo().getNetmask(); } else if ( (it.getNetworkPrefixLength() != 0 ) && ( address instanceof Inet6Address) ) { netmask = SocketUtilsIPV6.getIPV6NetMask(ipAddress() + "/" + it.getNetworkPrefixLength()); } }
private String ipv6_ip() { if (getAddressFamily() != AF_INET6) return null; InetAddress in = getInetAddress(); if (in.isLoopbackAddress()) return "::1"; return SocketUtilsIPV6.getIPV6Address(in.getHostAddress()); }
public static RubyArray unpack_sockaddr_in(ThreadContext context, ByteList val) { final Ruby runtime = context.runtime; AddressFamily af = getAddressFamilyFromSockaddr(runtime, val); if (af != AddressFamily.AF_INET && af != AddressFamily.AF_INET6) { throw runtime.newArgumentError("not an AF_INET/AF_INET6 sockaddr"); } int port = ((val.get(2)&0xff) << 8) + (val.get(3)&0xff); final StringBuilder formatAddr = new StringBuilder(); RubyString ip; if (af == AddressFamily.AF_INET) { formatAddr.append(val.get(4) & 0xff) .append('.') .append(val.get(5) & 0xff) .append('.') .append(val.get(6) & 0xff) .append('.') .append(val.get(7) & 0xff); ip = RubyString.newString(runtime, formatAddr); } else { // if af == AddressFamily.AF_INET6 for (int i = 4; i <= 19; i++) { if (i != 4 && i % 2 == 0) formatAddr.append(':'); formatAddr.append(Integer.toHexString(val.get(i) & 0xff | 0x100).substring(1)); } ip = RubyString.newString(runtime, SocketUtilsIPV6.getIPV6Address(formatAddr.toString())); } return RubyArray.newArray(runtime, runtime.newFixnum(port), ip); }
public static RubyArray unpack_sockaddr_in(ThreadContext context, ByteList val) { final Ruby runtime = context.runtime; AddressFamily af = getAddressFamilyFromSockaddr(runtime, val); if (af != AddressFamily.AF_INET && af != AddressFamily.AF_INET6) { throw runtime.newArgumentError("not an AF_INET/AF_INET6 sockaddr"); } int port = ((val.get(2)&0xff) << 8) + (val.get(3)&0xff); final StringBuilder formatAddr = new StringBuilder(); RubyString ip; if (af == AddressFamily.AF_INET) { formatAddr.append(val.get(4) & 0xff) .append('.') .append(val.get(5) & 0xff) .append('.') .append(val.get(6) & 0xff) .append('.') .append(val.get(7) & 0xff); ip = RubyString.newString(runtime, formatAddr); } else { // if af == AddressFamily.AF_INET6 for (int i = 4; i <= 19; i++) { if (i != 4 && i % 2 == 0) formatAddr.append(':'); formatAddr.append(Integer.toHexString(val.get(i) & 0xff | 0x100).substring(1)); } ip = RubyString.newString(runtime, SocketUtilsIPV6.getIPV6Address(formatAddr.toString())); } return RubyArray.newArray(runtime, runtime.newFixnum(port), ip); }