2 #include "utils/mono-networkinterfaces.h"
8 /* FIXME: bsds untested */
11 * mono_networkinterface_list:
12 * @size: a pointer to a location where the size of the returned array is stored
14 * Return an array of names for the interfaces currently on the system.
15 * The size of the array is stored in @size.
18 mono_networkinterface_list (int *size
)
26 f
= fopen ("/proc/net/dev", "r");
30 if (!fgets (buf
, sizeof (buf
) / sizeof (char), f
))
33 if (!fgets (buf
, sizeof (buf
) / sizeof (char), f
))
36 while (fgets (buf
, sizeof (buf
), f
) != NULL
) {
38 buf
[sizeof(buf
) - 1] = 0;
39 if ((ptr
= strchr (buf
, ':')) == NULL
|| (*ptr
++ = 0, sscanf (buf
, "%s", name
) != 1))
49 nilist
= (void **) g_realloc (nilist
, count
* sizeof (void*));
50 nilist
[i
++] = g_strdup (name
);
59 nilist
= (void **) g_malloc (sizeof (void*));
65 * mono_network_get_data:
66 * @name: name of the interface
67 * @data: description of data to return
69 * Return a data item of a network adapter like bytes sent per sec, etc
70 * according to the @data argumet.
73 mono_network_get_data (char* name
, MonoNetworkData data
, MonoNetworkError
*error
)
80 unsigned long rx_bytes
, rx_packets
, rx_errs
, rx_drops
,
81 rx_fifo
, rx_frame
, tx_bytes
, tx_packets
, tx_errs
, tx_drops
,
82 tx_fifo
, tx_colls
, tx_carrier
, rx_multi
;
84 *error
= MONO_NETWORK_ERROR_OTHER
;
86 f
= fopen ("/proc/net/dev", "r");
90 if (!fgets (buf
, sizeof (buf
) / sizeof (char), f
))
93 if (!fgets (buf
, sizeof (buf
) / sizeof (char), f
))
96 while (fgets (buf
, sizeof (buf
), f
) != NULL
) {
99 buf
[sizeof (buf
) - 1] = 0;
100 if ((ptr
= strchr (buf
, ':')) == NULL
||
101 (*ptr
++ = 0, sscanf (buf
, "%250s", cname
) != 1))
104 if (strcmp (name
, cname
) != 0) continue;
106 if (sscanf (ptr
, "%ld%ld%ld%ld%ld%ld%ld%*d%ld%ld%ld%ld%ld%ld%ld",
107 &rx_bytes
, &rx_packets
, &rx_errs
, &rx_drops
,
108 &rx_fifo
, &rx_frame
, &rx_multi
,
109 &tx_bytes
, &tx_packets
, &tx_errs
, &tx_drops
,
110 &tx_fifo
, &tx_colls
, &tx_carrier
) != 14)
114 case MONO_NETWORK_BYTESSENT
:
116 *error
= MONO_NETWORK_ERROR_NONE
;
118 case MONO_NETWORK_BYTESREC
:
120 *error
= MONO_NETWORK_ERROR_NONE
;
122 case MONO_NETWORK_BYTESTOTAL
:
123 val
= rx_bytes
+ tx_bytes
;
124 *error
= MONO_NETWORK_ERROR_NONE
;