GetFirstUnicastIPAddress bug

Topics: Bug Archive
Mar 4, 2016 at 11:41 AM

Could you correct a bug at SocketExtensions.cs GetFirstUnicastIPAddress function that returns Ip adress instead of real IP causes media setup exception.
 public static System.Net.IPAddress GetFirstUnicastIPAddress(System.Net.Sockets.AddressFamily addressFamily)
            //Check for a supported AddressFamily
            switch (addressFamily)
                case System.Net.Sockets.AddressFamily.InterNetwork:
                case System.Net.Sockets.AddressFamily.InterNetworkV6:
                        //If there is no network available use the Loopback adapter.
                        if (false == System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) return addressFamily == System.Net.Sockets.AddressFamily.InterNetwork ? System.Net.IPAddress.Loopback : System.Net.IPAddress.IPv6Loopback;

                        //Iterate for each Network Interface available.
                        foreach (System.Net.NetworkInformation.NetworkInterface networkInterface in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
                            System.Net.IPAddress result = Common.Extensions.NetworkInterface.NetworkInterfaceExtensions.GetFirstUnicastIPAddress(networkInterface, addressFamily);

                            //PATCH : added && !Equals(result, System.Net.IPAddress.None
                            if (result != null && !Equals(result, System.Net.IPAddress.None)) return result;

                        //Could not find an IP.
                        return System.Net.IPAddress.None;
                default: throw new System.NotSupportedException("Only InterNetwork or InterNetworkV6 is supported.");
Mar 4, 2016 at 1:17 PM
Edited Mar 4, 2016 at 5:00 PM
Good catch, Thanks!

111923 should fix this!
Marked as answer by juliusfriedman on 3/4/2016 at 6:17 AM