internal static int SameHost()

in src/Trinity.Core/Utilities/Network/NetworkUtility.cs [50:121]


        internal static int SameHost(IPAddress ipA, IPAddress ipB)
        {
            byte[] x_bytes = ipA.GetAddressBytes();
            byte[] y_bytes = ipB.GetAddressBytes();

            if (x_bytes.Length < y_bytes.Length)
                return -1;
            if (x_bytes.Length > y_bytes.Length)
                return 1;
            if (x_bytes.Length == 4) //ipv4
            {
                int int_x = BitConverter.ToInt32(x_bytes, 0);
                int int_y = BitConverter.ToInt32(y_bytes, 0);

                if (int_x == int_y)
                    return 0;

                if (int_x == V4Loopback)
                {
                    return NetworkUtility.IsMyIPAddress(ipB) ? 0 : -1;
                }

                if (int_y == V4Loopback)
                {
                    return NetworkUtility.IsMyIPAddress(ipA) ? 0 : 1;
                }

                if (int_x < int_y)
                    return -1;
                if (int_x > int_y)
                    return 1;
                return 0;
            }
            else
            {
                if (x_bytes.Length == 16)
                {
                    long long1_x = BitConverter.ToInt64(x_bytes, 0);
                    long long1_y = BitConverter.ToInt64(y_bytes, 0);
                    long long2_x = BitConverter.ToInt64(x_bytes, 8);
                    long long2_y = BitConverter.ToInt64(y_bytes, 8);

                    if (long1_x == long1_y && long2_x == long2_y)
                        return 0;

                    if (long1_x == V6LoopbackLower && long2_x == V6LoopbackHigher)
                    {
                        return NetworkUtility.IsMyIPAddress(ipB) ? 0 : -1;
                    }

                    if (long1_y == V6LoopbackLower && long2_y == V6LoopbackHigher)
                    {
                        return NetworkUtility.IsMyIPAddress(ipA) ? 0 : 1;
                    }

                    if (long1_x < long1_y)
                        return -1;
                    if (long1_x > long1_y)
                        return 1;

                    if (long2_x < long2_y)
                        return -1;
                    if (long2_x > long2_y)
                        return 1;
                    return 0;
                }
                else
                {
                    throw new Exception("Invalid IPAddress Exception.");
                }
            }
        }