6 #include "utils/mono-networkinterfaces.h"
12 /* FIXME: bsds untested */
15 * mono_networkinterface_list:
16 * @size: a pointer to a location where the size of the returned array is stored
18 * Return an array of names for the interfaces currently on the system.
19 * The size of the array is stored in @size.
22 mono_networkinterface_list (int *size)
30 f = fopen ("/proc/net/dev", "r");
34 if (!fgets (buf, sizeof (buf) / sizeof (char), f))
37 if (!fgets (buf, sizeof (buf) / sizeof (char), f))
40 while (fgets (buf, sizeof (buf), f) != NULL) {
42 buf [sizeof(buf) - 1] = 0;
43 if ((ptr = strchr (buf, ':')) == NULL || (*ptr++ = 0, sscanf (buf, "%s", name) != 1))
53 nilist = (void **) g_realloc (nilist, count * sizeof (void*));
54 nilist [i++] = g_strdup (name);
63 nilist = (void **) g_malloc (sizeof (void*));
69 * mono_network_get_data:
70 * @name: name of the interface
71 * @data: description of data to return
73 * Return a data item of a network adapter like bytes sent per sec, etc
74 * according to the @data argumet.
77 mono_network_get_data (char* name, MonoNetworkData data, MonoNetworkError *error)
84 unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
85 rx_fifo, rx_frame, tx_bytes, tx_packets, tx_errs, tx_drops,
86 tx_fifo, tx_colls, tx_carrier, rx_multi;
88 *error = MONO_NETWORK_ERROR_OTHER;
90 f = fopen ("/proc/net/dev", "r");
94 if (!fgets (buf, sizeof (buf) / sizeof (char), f))
97 if (!fgets (buf, sizeof (buf) / sizeof (char), f))
100 while (fgets (buf, sizeof (buf), f) != NULL) {
103 buf [sizeof (buf) - 1] = 0;
104 if ((ptr = strchr (buf, ':')) == NULL ||
105 (*ptr++ = 0, sscanf (buf, "%250s", cname) != 1))
108 if (strcmp (name, cname) != 0) continue;
110 if (sscanf (ptr, "%ld%ld%ld%ld%ld%ld%ld%*d%ld%ld%ld%ld%ld%ld%ld",
111 &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
112 &rx_fifo, &rx_frame, &rx_multi,
113 &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
114 &tx_fifo, &tx_colls, &tx_carrier) != 14)
118 case MONO_NETWORK_BYTESSENT:
120 *error = MONO_NETWORK_ERROR_NONE;
122 case MONO_NETWORK_BYTESREC:
124 *error = MONO_NETWORK_ERROR_NONE;
126 case MONO_NETWORK_BYTESTOTAL:
127 val = rx_bytes + tx_bytes;
128 *error = MONO_NETWORK_ERROR_NONE;