Inheritance: java.net.InetAddress
Example #1
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;
 }
Example #2
0
        /// <summary>
        /// Compares this object against the specified object. The result is {@code
        /// true} if and only if the argument is not {@code null} and it represents
        /// the same IP address as this object.
        ///
        /// <para> Two instances of {@code InetAddress} represent the same IP address
        /// if the length of the byte arrays returned by {@code getAddress} is the
        /// same for both, and each of the array components is the same for the byte
        /// arrays.
        ///
        /// </para>
        /// </summary>
        /// <param name="obj">   the object to compare against.
        /// </param>
        /// <returns>  {@code true} if the objects are the same; {@code false} otherwise.
        /// </returns>
        /// <seealso cref=     java.net.InetAddress#getAddress() </seealso>
        public override bool Equals(Object obj)
        {
            if (obj == null || !(obj is Inet6Address))
            {
                return(false);
            }

            Inet6Address inetAddr = (Inet6Address)obj;

            return(Holder6.Equals(inetAddr.Holder6));
        }
Example #3
0
        /* check the two Ipv6 addresses and return false if they are both
         * non global address types, but not the same.
         * (ie. one is sitelocal and the other linklocal)
         * return true otherwise.
         */

        private static bool IsDifferentLocalAddressType(sbyte[] thisAddr, sbyte[] otherAddr)
        {
            if (Inet6Address.IsLinkLocalAddress(thisAddr) && !Inet6Address.IsLinkLocalAddress(otherAddr))
            {
                return(false);
            }
            if (Inet6Address.IsSiteLocalAddress(thisAddr) && !Inet6Address.IsSiteLocalAddress(otherAddr))
            {
                return(false);
            }
            return(true);
        }
 public virtual InetAddress LoopbackAddress()
 {
     lock (this)
     {
         if (LoopbackAddress_Renamed == null)
         {
             if (InetAddress.PreferIPv6Address)
             {
                 sbyte[] loopback = new sbyte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
                 LoopbackAddress_Renamed = new Inet6Address("localhost", loopback);
             }
             else
             {
                 LoopbackAddress_Renamed = (new Inet4AddressImpl()).LoopbackAddress();
             }
         }
         return(LoopbackAddress_Renamed);
     }
 }
 public virtual InetAddress AnyLocalAddress()
 {
     lock (this)
     {
         if (AnyLocalAddress_Renamed == null)
         {
             if (InetAddress.PreferIPv6Address)
             {
                 AnyLocalAddress_Renamed = new Inet6Address();
                 AnyLocalAddress_Renamed.Holder().HostName_Renamed = "::";
             }
             else
             {
                 AnyLocalAddress_Renamed = (new Inet4AddressImpl()).AnyLocalAddress();
             }
         }
         return(AnyLocalAddress_Renamed);
     }
 }
Example #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static int deriveNumericScope(byte[] thisAddr, NetworkInterface ifc) throws UnknownHostException
        private static int DeriveNumericScope(sbyte[] thisAddr, NetworkInterface ifc)
        {
            IEnumerator <InetAddress> addresses = ifc.InetAddresses;

            while (addresses.MoveNext())
            {
                InetAddress addr = addresses.Current;
                if (!(addr is Inet6Address))
                {
                    continue;
                }
                Inet6Address ia6_addr = (Inet6Address)addr;
                /* check if site or link local prefixes match */
                if (!IsDifferentLocalAddressType(thisAddr, ia6_addr.Address))
                {
                    /* type not the same, so carry on searching */
                    continue;
                }
                /* found a matching address - return its scope_id */
                return(ia6_addr.ScopeId);
            }
            throw new UnknownHostException("no scope_id found");
        }
Example #7
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;
 }
Example #8
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);
    }
Example #9
0
 internal Inet6AddressHolder(Inet6Address outerInstance)
 {
     this.OuterInstance = outerInstance;
     Ipaddress          = new sbyte[INADDRSZ];
 }