public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new Ifaddr(runtime, klazz); } });
public Ifaddr(Ruby runtime, RubyClass metaClass, NetworkInterface ni, InterfaceAddress it) throws Exception { super(runtime, metaClass); this.isUp = ni.isUp(); this.name = ni.getDisplayName(); this.isLoopback = ni.isLoopback(); this.isPointToPoint = ni.isPointToPoint(); this.networkInterface = ni; this.isLink = false; this.address = it.getAddress(); this.broadcast = it.getBroadcast(); this.interfaceAddress = it; setAddr(runtime); setNetmask(it); setIndex(ni); setInspectString(ni); }
public Ifaddr(Ruby runtime, RubyClass metaClass, NetworkInterface ni) throws Exception { super(runtime, metaClass); this.isUp = ni.isUp(); this.name = ni.getDisplayName(); this.isLoopback = ni.isLoopback(); this.isPointToPoint = ni.isPointToPoint(); this.networkInterface = ni; this.isLink = true; setAddr(runtime); setIndex(ni); setInspectString(ni); }
flagStatus += " " + addr.packet_inspect(); } else { if (!ipAddress().equals("")) { flagStatus += " " + ipAddress(); flagStatus += " broadcast=" + getBroadcastAsString();
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()); } }
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); } }
public Ifaddr(Ruby runtime, RubyClass metaClass, NetworkInterface ni) throws Exception { super(runtime, metaClass); this.isUp = ni.isUp(); this.name = ni.getDisplayName(); this.isLoopback = ni.isLoopback(); this.isPointToPoint = ni.isPointToPoint(); this.networkInterface = ni; this.isLink = true; setAddr(runtime); setIndex(ni); setInspectString(ni); }
flagStatus += " " + addr.packet_inspect(); } else { if (!ipAddress().equals("")) { flagStatus += " " + ipAddress(); flagStatus += " broadcast=" + getBroadcastAsString();
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()); } }
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); } }
public Ifaddr(Ruby runtime, RubyClass metaClass, NetworkInterface ni, InterfaceAddress it) throws Exception { super(runtime, metaClass); this.isUp = ni.isUp(); this.name = ni.getDisplayName(); this.isLoopback = ni.isLoopback(); this.isPointToPoint = ni.isPointToPoint(); this.networkInterface = ni; this.isLink = false; this.address = it.getAddress(); this.broadcast = it.getBroadcast(); this.interfaceAddress = it; setAddr(runtime); setNetmask(it); setIndex(ni); setInspectString(ni); }
public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new Ifaddr(runtime, klazz); } });
@JRubyMethod(meta = true) public static IRubyObject getifaddrs(ThreadContext context, IRubyObject recv) { RubyArray list = RubyArray.newArray(context.runtime); try { Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); RubyClass Ifaddr = (RubyClass) context.runtime.getClassFromPath("Socket::Ifaddr"); while (en.hasMoreElements()) { NetworkInterface ni = en.nextElement(); // create interface link layer ifaddr list.append(new Ifaddr(context.runtime, Ifaddr, ni)); for ( InterfaceAddress ia : ni.getInterfaceAddresses() ) { list.append(new Ifaddr(context.runtime, Ifaddr, ni, ia)); } } } catch (Exception ex) { if ( ex instanceof RaiseException ) throw (RaiseException) ex; throw SocketUtils.sockerr_with_trace(context.runtime, "getifaddrs: " + ex.toString(), ex.getStackTrace()); } return list; }
@JRubyMethod(meta = true) public static IRubyObject getifaddrs(ThreadContext context, IRubyObject recv) { RubyArray list = RubyArray.newArray(context.runtime); try { Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); RubyClass Ifaddr = (RubyClass) context.runtime.getClassFromPath("Socket::Ifaddr"); while (en.hasMoreElements()) { NetworkInterface ni = en.nextElement(); // create interface link layer ifaddr list.append(new Ifaddr(context.runtime, Ifaddr, ni)); for ( InterfaceAddress ia : ni.getInterfaceAddresses() ) { list.append(new Ifaddr(context.runtime, Ifaddr, ni, ia)); } } } catch (Exception ex) { if ( ex instanceof RaiseException ) throw (RaiseException) ex; throw SocketUtils.sockerr_with_trace(context.runtime, "getifaddrs: " + ex.toString(), ex.getStackTrace()); } return list; }