Merge pull request #1390 from woodsb02/FreeBSDMacNetworkInterfaces
authorMiguel de Icaza <miguel@gnome.org>
Mon, 10 Nov 2014 01:17:50 +0000 (20:17 -0500)
committerMiguel de Icaza <miguel@gnome.org>
Mon, 10 Nov 2014 01:17:50 +0000 (20:17 -0500)
Freebsd to use Mac NetworkInterface code instead of Linux NetworkInterface code

mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs
mcs/class/System/System/Platform.cs
mono/metadata/socket-io.c

index edaa12dafb3aef8dbe606e78e59bc48ffb6aec4d..46cf7d8cbdfcc2ecf543b20e7f1a5fef80052992 100644 (file)
@@ -58,7 +58,7 @@ namespace System.Net.NetworkInformation {
 #else
                        if (runningOnUnix) {
                                try {
-                                       if (Platform.IsMacOS)
+                                       if (Platform.IsMacOS || Platform.IsFreeBSD)
                                                return MacOsNetworkInterface.ImplGetAllNetworkInterfaces ();
                                        else
                                                return LinuxNetworkInterface.ImplGetAllNetworkInterfaces ();
index c45a33e66005cff43b6a826cd74b85c3c8c77128..b687c590f580272959a8304c787d3149524a6838 100644 (file)
@@ -28,36 +28,56 @@ using System.Runtime.InteropServices;
 
 namespace System {
        internal static class Platform {
+               static bool checkedOS;
+               static bool isMacOS;
+               static bool isFreeBSD;
+
 #if MONOTOUCH || XAMMAC
-               public static bool IsMacOS {
-                       get { return true; }
+               private static void CheckOS() {
+                       isMacOS = true;
+                       checkedOS = true;
                }
 #else
                [DllImport ("libc")]
                static extern int uname (IntPtr buf);
-               
-               static bool checkedIsMacOS;
-               static bool isMacOS;
-               
-               public static bool IsMacOS {
-                       get {
-                               if (Environment.OSVersion.Platform != PlatformID.Unix)
-                                       return false;
 
-                               if (!checkedIsMacOS) {
-                                       IntPtr buf = Marshal.AllocHGlobal (8192);
-                                       if (uname (buf) == 0) {
-                                               string os = Marshal.PtrToStringAnsi (buf);
-                                               if (os == "Darwin")
-                                                       isMacOS = true;
-                                       }
-                                       Marshal.FreeHGlobal (buf);
-                                       checkedIsMacOS = true;
+               private static void CheckOS() {
+                       if (Environment.OSVersion.Platform != PlatformID.Unix) {
+                               checkedOS = true;
+                               return;
+                       }
+
+                       IntPtr buf = Marshal.AllocHGlobal (8192);
+                       if (uname (buf) == 0) {
+                               string os = Marshal.PtrToStringAnsi (buf);
+                               switch (os) {
+                               case "Darwin":
+                                       isMacOS = true;
+                                       break;
+                               case "FreeBSD":
+                                       isFreeBSD = true;
+                                       break;
                                }
-                               
-                               return isMacOS;
                        }
+                       Marshal.FreeHGlobal (buf);
+                       checkedOS = true;
                }
 #endif
+
+               public static bool IsMacOS {
+                       get {
+                               if (!checkedOS)
+                                       CheckOS();
+                               return isMacOS;
+                       }
+               }
+
+               public static bool IsFreeBSD {
+                       get {
+                               if (!checkedOS)
+                                       CheckOS();
+                               return isFreeBSD;
+                       }
+               }
        }
 }
index 949164e5548c4e82fcc5f27f9c524c9963c825ba..0b75405bd0acd42aca213b10a011e745d1ecc636 100644 (file)
@@ -13,7 +13,7 @@
 
 #ifndef DISABLE_SOCKETS
 
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__FreeBSD__)
 #define __APPLE_USE_RFC_3542
 #endif
 
 #define AI_ADDRCONFIG 0
 #endif
 
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__FreeBSD__)
 /*
  * We remove this until we have a Darwin implementation
  * that can walk the result of struct ifconf.  The current
@@ -2051,7 +2051,7 @@ static struct in6_addr ipaddress_to_struct_in6_addr(MonoObject *ipaddr)
 #endif /* AF_INET6 */
 #endif
 
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__FreeBSD__)
 
 #if defined(HAVE_GETIFADDRS) && defined(HAVE_IF_NAMETOINDEX)
 static int
@@ -2089,7 +2089,7 @@ get_local_interface_id (int family)
 }
 #endif
 
-#endif /* __APPLE__ */
+#endif /* defined(__APPLE__) || defined(__FreeBSD__) */
 
 void ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal(SOCKET sock, gint32 level, gint32 name, MonoObject *obj_val, MonoArray *byte_val, gint32 int_val, gint32 *error)
 {
@@ -2187,7 +2187,7 @@ void ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal(SOCKET sock, g
                                field=mono_class_get_field_from_name(obj_val->vtable->klass, "ifIndex");
                                mreq6.ipv6mr_interface =*(guint64 *)(((char *)obj_val)+field->offset);
                                
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__FreeBSD__)
                                /*
                                * Bug #5504:
                                *