Merge pull request #4710 from Unity-Technologies/additional-config-checks
[mono.git] / mono / utils / mono-networkinterfaces.c
index a05ad99a4662a34ca259dd1d3ea971c832aae789..f86bd651ee74be0b7507e7743a6bf4e1873a70ac 100644 (file)
@@ -1,3 +1,7 @@
+/**
+ * \file
+ */
+
 #include "config.h"
 #include "utils/mono-networkinterfaces.h"
 
@@ -9,10 +13,9 @@
 
 /**
  * mono_networkinterface_list:
- * @size: a pointer to a location where the size of the returned array is stored
- *
- * Return an array of names for the interfaces currently on the system.
- * The size of the array is stored in @size.
+ * \param size a pointer to a location where the size of the returned array is stored
+ * \returns an array of names for the interfaces currently on the system.
+ * The size of the array is stored in \p size.
  */
 gpointer*
 mono_networkinterface_list (int *size)
@@ -46,7 +49,7 @@ mono_networkinterface_list (int *size)
                                count *= 2;
                }
 
-               nilist = g_realloc (nilist, count * sizeof (void*));
+               nilist = (void **) g_realloc (nilist, count * sizeof (void*));
                nilist [i++] = g_strdup (name);
        }
 
@@ -55,17 +58,18 @@ mono_networkinterface_list (int *size)
        if (size)
                *size = i;
 
+       if (!nilist)
+               nilist = (void **) g_malloc (sizeof (void*));
        nilist [i] = NULL;
        return nilist;
 }
 
 /**
  * mono_network_get_data:
- * @name: name of the interface
- * @data: description of data to return
- *
- * Return a data item of a network adapter like bytes sent per sec, etc
- * according to the @data argumet.
+ * \param name name of the interface
+ * \param data description of data to return
+ * \return a data item of a network adapter like bytes sent per sec, etc
+ * according to the \p data argumet.
  */
 gint64
 mono_network_get_data (char* name, MonoNetworkData data, MonoNetworkError *error)
@@ -79,8 +83,7 @@ mono_network_get_data (char* name, MonoNetworkData data, MonoNetworkError *error
                rx_fifo, rx_frame, tx_bytes, tx_packets, tx_errs, tx_drops,
                tx_fifo, tx_colls, tx_carrier, rx_multi;
 
-       if (error)
-               *error = MONO_NETWORK_ERROR_OTHER;
+       *error = MONO_NETWORK_ERROR_OTHER;
 
        f = fopen ("/proc/net/dev", "r");
        if (!f) 
@@ -97,7 +100,7 @@ mono_network_get_data (char* name, MonoNetworkData data, MonoNetworkError *error
                char *ptr;
                buf [sizeof (buf) - 1] = 0;
                if ((ptr = strchr (buf, ':')) == NULL ||
-                               (*ptr++ = 0, sscanf (buf, "%s", cname) != 1))
+                               (*ptr++ = 0, sscanf (buf, "%250s", cname) != 1))
                        goto out;
 
                if (strcmp (name, cname) != 0) continue;