public virtual void leaveGroup(SocketAddress arg0, NetworkInterface arg1) { throw null; }
 public virtual void setNetworkInterface(NetworkInterface value) { throw null; }
示例#3
0
文件: java.net.cs 项目: Zolo49/ikvm
 private static NetworkInterfaceInfo GetInterfaces()
 {
     // Since many of the methods in java.net.NetworkInterface end up calling this method and the underlying stuff this is
     // based on isn't very quick either, we cache the array for a couple of seconds.
     if (cache != null && DateTime.UtcNow - cachedSince < new TimeSpan(0, 0, 5))
     {
         return cache;
     }
     NetworkInterface[] ifaces = NetworkInterface.GetAllNetworkInterfaces();
     // on Mono (on Windows) we need to filter out the network interfaces that don't have any IP properties
     ifaces = Array.FindAll(ifaces, IsValid);
     Array.Sort(ifaces, Compare);
     java.net.NetworkInterface[] ret = new java.net.NetworkInterface[ifaces.Length];
     int eth = 0;
     int tr = 0;
     int fddi = 0;
     int lo = 0;
     int ppp = 0;
     int sl = 0;
     int net = 0;
     for (int i = 0; i < ifaces.Length; i++)
     {
         string name;
         switch (ifaces[i].NetworkInterfaceType)
         {
             case NetworkInterfaceType.Ethernet:
                 name = "eth" + eth++;
                 break;
             case NetworkInterfaceType.TokenRing:
                 name = "tr" + tr++;
                 break;
             case NetworkInterfaceType.Fddi:
                 name = "fddi" + fddi++;
                 break;
             case NetworkInterfaceType.Loopback:
                 if (lo > 0)
                 {
                     continue;
                 }
                 name = "lo";
                 lo++;
                 break;
             case NetworkInterfaceType.Ppp:
                 name = "ppp" + ppp++;
                 break;
             case NetworkInterfaceType.Slip:
                 name = "sl" + sl++;
                 break;
             default:
                 name = "net" + net++;
                 break;
         }
         java.net.NetworkInterface netif = new java.net.NetworkInterface();
         ret[i] = netif;
         netif._set1(name, ifaces[i].Description, GetIndex(ifaces[i]));
         UnicastIPAddressInformationCollection uipaic = ifaces[i].GetIPProperties().UnicastAddresses;
         List<java.net.InetAddress> addresses = new List<java.net.InetAddress>();
         List<java.net.InterfaceAddress> bindings = new List<java.net.InterfaceAddress>();
         for (int j = 0; j < uipaic.Count; j++)
         {
             IPAddress addr = uipaic[j].Address;
             if (addr.AddressFamily == AddressFamily.InterNetwork)
             {
                 java.net.Inet4Address address = new java.net.Inet4Address(null, addr.GetAddressBytes());
                 java.net.InterfaceAddress binding = new java.net.InterfaceAddress();
                 short mask = 32;
                 java.net.Inet4Address broadcast = null;
                 IPAddress v4mask;
                 try
                 {
                     v4mask = uipaic[j].IPv4Mask;
                 }
                 catch (NotImplementedException)
                 {
                     // Mono (as of 2.6.7) doesn't implement the IPv4Mask property
                     v4mask = null;
                 }
                 if (v4mask != null && !v4mask.Equals(IPAddress.Any))
                 {
                     broadcast = new java.net.Inet4Address(null, -1);
                     mask = 0;
                     foreach (byte b in v4mask.GetAddressBytes())
                     {
                         mask += (short)java.lang.Integer.bitCount(b);
                     }
                 }
                 else if (address.isLoopbackAddress())
                 {
                     mask = 8;
                     broadcast = new java.net.Inet4Address(null, 0xffffff);
                 }
                 binding._set(address, broadcast, mask);
                 addresses.Add(address);
                 bindings.Add(binding);
             }
             else if (Java_java_net_InetAddressImplFactory.isIPv6Supported())
             {
                 int scope = 0;
                 if (addr.IsIPv6LinkLocal || addr.IsIPv6SiteLocal)
                 {
                     scope = (int)addr.ScopeId;
                 }
                 java.net.Inet6Address ia6 = new java.net.Inet6Address();
                 ia6._holder().ipaddress = addr.GetAddressBytes();
                 if (scope != 0)
                 {
                     ia6._holder().scope_id = scope;
                     ia6._holder().scope_id_set = true;
                     ia6._holder().scope_ifname = netif;
                     ia6._holder().scope_ifname_set = true;
                 }
                 java.net.InterfaceAddress binding = new java.net.InterfaceAddress();
                 // TODO where do we get the IPv6 subnet prefix length?
                 short mask = 128;
                 binding._set(ia6, null, mask);
                 addresses.Add(ia6);
                 bindings.Add(binding);
             }
         }
         netif._set2(addresses.ToArray(), bindings.ToArray(), new java.net.NetworkInterface[0]);
     }
     NetworkInterfaceInfo nii = new NetworkInterfaceInfo();
     nii.dotnetInterfaces = ifaces;
     nii.javaInterfaces = ret;
     cache = nii;
     cachedSince = DateTime.UtcNow;
     return nii;
 }
示例#4
0
    private static NetworkInterfaceInfo GetInterfaces()
    {
        // Since many of the methods in java.net.NetworkInterface end up calling this method and the underlying stuff this is
        // based on isn't very quick either, we cache the array for a couple of seconds.
        if (cache != null && DateTime.UtcNow - cachedSince < new TimeSpan(0, 0, 5))
        {
            return(cache);
        }
        NetworkInterface[] ifaces = NetworkInterface.GetAllNetworkInterfaces();
        // on Mono (on Windows) we need to filter out the network interfaces that don't have any IP properties
        ifaces = Array.FindAll(ifaces, IsValid);
        Array.Sort(ifaces, Compare);
        java.net.NetworkInterface[] ret = new java.net.NetworkInterface[ifaces.Length];
        int eth  = 0;
        int tr   = 0;
        int fddi = 0;
        int lo   = 0;
        int ppp  = 0;
        int sl   = 0;
        int net  = 0;

        for (int i = 0; i < ifaces.Length; i++)
        {
            string name;
            switch (ifaces[i].NetworkInterfaceType)
            {
            case NetworkInterfaceType.Ethernet:
                name = "eth" + eth++;
                break;

            case NetworkInterfaceType.TokenRing:
                name = "tr" + tr++;
                break;

            case NetworkInterfaceType.Fddi:
                name = "fddi" + fddi++;
                break;

            case NetworkInterfaceType.Loopback:
                if (lo > 0)
                {
                    continue;
                }
                name = "lo";
                lo++;
                break;

            case NetworkInterfaceType.Ppp:
                name = "ppp" + ppp++;
                break;

            case NetworkInterfaceType.Slip:
                name = "sl" + sl++;
                break;

            default:
                name = "net" + net++;
                break;
            }
            java.net.NetworkInterface netif = new java.net.NetworkInterface();
            ret[i] = netif;
            netif._set1(name, ifaces[i].Description, GetIndex(ifaces[i]));
            UnicastIPAddressInformationCollection uipaic    = ifaces[i].GetIPProperties().UnicastAddresses;
            List <java.net.InetAddress>           addresses = new List <java.net.InetAddress>();
            List <java.net.InterfaceAddress>      bindings  = new List <java.net.InterfaceAddress>();
            for (int j = 0; j < uipaic.Count; j++)
            {
                IPAddress addr = uipaic[j].Address;
                if (addr.AddressFamily == AddressFamily.InterNetwork)
                {
                    java.net.Inet4Address     address = new java.net.Inet4Address(null, addr.GetAddressBytes());
                    java.net.InterfaceAddress binding = new java.net.InterfaceAddress();
                    short mask = 32;
                    java.net.Inet4Address broadcast = null;
                    IPAddress             v4mask;
                    try
                    {
                        v4mask = uipaic[j].IPv4Mask;
                    }
                    catch (NotImplementedException)
                    {
                        // Mono (as of 2.6.7) doesn't implement the IPv4Mask property
                        v4mask = null;
                    }
                    if (v4mask != null && !v4mask.Equals(IPAddress.Any))
                    {
                        broadcast = new java.net.Inet4Address(null, -1);
                        mask      = 0;
                        foreach (byte b in v4mask.GetAddressBytes())
                        {
                            mask += (short)java.lang.Integer.bitCount(b);
                        }
                    }
                    else if (address.isLoopbackAddress())
                    {
                        mask      = 8;
                        broadcast = new java.net.Inet4Address(null, 0xffffff);
                    }
                    binding._set(address, broadcast, mask);
                    addresses.Add(address);
                    bindings.Add(binding);
                }
                else if (Java_java_net_InetAddressImplFactory.isIPv6Supported())
                {
                    int scope = 0;
                    if (addr.IsIPv6LinkLocal || addr.IsIPv6SiteLocal)
                    {
                        scope = (int)addr.ScopeId;
                    }
                    java.net.Inet6Address ia6 = new java.net.Inet6Address();
                    ia6._holder().ipaddress   = addr.GetAddressBytes();
                    if (scope != 0)
                    {
                        ia6._holder().scope_id         = scope;
                        ia6._holder().scope_id_set     = true;
                        ia6._holder().scope_ifname     = netif;
                        ia6._holder().scope_ifname_set = true;
                    }
                    java.net.InterfaceAddress binding = new java.net.InterfaceAddress();
                    // TODO where do we get the IPv6 subnet prefix length?
                    short mask = 128;
                    binding._set(ia6, null, mask);
                    addresses.Add(ia6);
                    bindings.Add(binding);
                }
            }
            netif._set2(addresses.ToArray(), bindings.ToArray(), new java.net.NetworkInterface[0]);
        }
        NetworkInterfaceInfo nii = new NetworkInterfaceInfo();

        nii.dotnetInterfaces = ifaces;
        nii.javaInterfaces   = ret;
        cache       = nii;
        cachedSince = DateTime.UtcNow;
        return(nii);
    }
示例#5
0
        /// <summary>
        /// restore the state of this object from stream
        /// including the scope information, only if the
        /// scoped interface name is valid on this system
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException
        private void ReadObject(ObjectInputStream s)
        {
            NetworkInterface scope_ifname = null;

            if (this.GetType().ClassLoader != null)
            {
                throw new SecurityException("invalid address type");
            }

            ObjectInputStream.GetField gf = s.ReadFields();
            sbyte[] ipaddress             = (sbyte[])gf.Get("ipaddress", null);
            int     scope_id         = (int)gf.Get("scope_id", -1);
            bool    scope_id_set     = (bool)gf.Get("scope_id_set", false);
            bool    scope_ifname_set = (bool)gf.Get("scope_ifname_set", false);
            String  ifname           = (String)gf.Get("ifname", null);

            if (ifname != null && !"".Equals(ifname))
            {
                try
                {
                    scope_ifname = NetworkInterface.GetByName(ifname);
                    if (scope_ifname == null)
                    {
                        /* the interface does not exist on this system, so we clear
                         * the scope information completely */
                        scope_id_set     = false;
                        scope_ifname_set = false;
                        scope_id         = 0;
                    }
                    else
                    {
                        scope_ifname_set = true;
                        try
                        {
                            scope_id = DeriveNumericScope(ipaddress, scope_ifname);
                        }
                        catch (UnknownHostException)
                        {
                            // typically should not happen, but it may be that
                            // the machine being used for deserialization has
                            // the same interface name but without IPv6 configured.
                        }
                    }
                }
                catch (SocketException)
                {
                }
            }

            /* if ifname was not supplied, then the numeric info is used */

            ipaddress = ipaddress.clone();

            // Check that our invariants are satisfied
            if (ipaddress.Length != INADDRSZ)
            {
                throw new InvalidObjectException("invalid address length: " + ipaddress.Length);
            }

            if (Holder_Renamed.Family != IPv6)
            {
                throw new InvalidObjectException("invalid address family type");
            }

            Inet6AddressHolder h = new Inet6AddressHolder(this, ipaddress, scope_id, scope_id_set, scope_ifname, scope_ifname_set);

            UNSAFE.putObject(this, FIELDS_OFFSET, h);
        }
示例#6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: Inet6Address(String hostName, byte addr[] , NetworkInterface nif) throws UnknownHostException
        internal Inet6Address(String hostName, sbyte[] addr, NetworkInterface nif)
        {
            Holder6 = new Inet6AddressHolder(this);
            Initif(hostName, addr, nif);
        }
示例#7
0
 internal Inet6AddressHolder(Inet6Address outerInstance, sbyte[] ipaddress, int scope_id, bool scope_id_set, NetworkInterface ifname, bool scope_ifname_set)
 {
     this.OuterInstance    = outerInstance;
     this.Ipaddress        = ipaddress;
     this.Scope_id         = scope_id;
     this.Scope_id_set     = scope_id_set;
     this.Scope_ifname_set = scope_ifname_set;
     this.Scope_ifname     = ifname;
 }