6 #include "utils/mono-networkinterfaces.h"
12 /* FIXME: bsds untested */
15 * mono_networkinterface_list:
16 * \param size a pointer to a location where the size of the returned array is stored
17 * \returns an array of names for the interfaces currently on the system.
18 * The size of the array is stored in \p size.
21 mono_networkinterface_list (int *size)
29 f = fopen ("/proc/net/dev", "r");
33 if (!fgets (buf, sizeof (buf) / sizeof (char), f))
36 if (!fgets (buf, sizeof (buf) / sizeof (char), f))
39 while (fgets (buf, sizeof (buf), f) != NULL) {
41 buf [sizeof(buf) - 1] = 0;
42 if ((ptr = strchr (buf, ':')) == NULL || (*ptr++ = 0, sscanf (buf, "%s", name) != 1))
52 nilist = (void **) g_realloc (nilist, count * sizeof (void*));
53 nilist [i++] = g_strdup (name);
62 nilist = (void **) g_malloc (sizeof (void*));
68 * mono_network_get_data:
69 * \param name name of the interface
70 * \param data description of data to return
71 * \return a data item of a network adapter like bytes sent per sec, etc
72 * according to the \p data argumet.
75 mono_network_get_data (char* name, MonoNetworkData data, MonoNetworkError *error)
82 unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
83 rx_fifo, rx_frame, tx_bytes, tx_packets, tx_errs, tx_drops,
84 tx_fifo, tx_colls, tx_carrier, rx_multi;
86 *error = MONO_NETWORK_ERROR_OTHER;
88 f = fopen ("/proc/net/dev", "r");
92 if (!fgets (buf, sizeof (buf) / sizeof (char), f))
95 if (!fgets (buf, sizeof (buf) / sizeof (char), f))
98 while (fgets (buf, sizeof (buf), f) != NULL) {
101 buf [sizeof (buf) - 1] = 0;
102 if ((ptr = strchr (buf, ':')) == NULL ||
103 (*ptr++ = 0, sscanf (buf, "%250s", cname) != 1))
106 if (strcmp (name, cname) != 0) continue;
108 if (sscanf (ptr, "%ld%ld%ld%ld%ld%ld%ld%*d%ld%ld%ld%ld%ld%ld%ld",
109 &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
110 &rx_fifo, &rx_frame, &rx_multi,
111 &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
112 &tx_fifo, &tx_colls, &tx_carrier) != 14)
116 case MONO_NETWORK_BYTESSENT:
118 *error = MONO_NETWORK_ERROR_NONE;
120 case MONO_NETWORK_BYTESREC:
122 *error = MONO_NETWORK_ERROR_NONE;
124 case MONO_NETWORK_BYTESTOTAL:
125 val = rx_bytes + tx_bytes;
126 *error = MONO_NETWORK_ERROR_NONE;