45 |
|
#ifdef LINUX |
46 |
|
#include <stdio.h> |
47 |
|
#include <sys/types.h> |
48 |
– |
#include <regex.h> |
48 |
|
#include <sys/ioctl.h> |
49 |
|
#include <sys/socket.h> |
50 |
|
#include <net/if.h> |
112 |
|
|
113 |
|
#ifdef ALLBSD |
114 |
|
if(getifaddrs(&net) != 0){ |
115 |
< |
sg_set_error(SG_ERROR_GETIFADDRS, NULL); |
115 |
> |
sg_set_error_with_errno(SG_ERROR_GETIFADDRS, NULL); |
116 |
|
return NULL; |
117 |
|
} |
118 |
|
|
244 |
|
#ifdef LINUX |
245 |
|
f=fopen("/proc/net/dev", "r"); |
246 |
|
if(f==NULL){ |
247 |
< |
sg_set_error(SG_ERROR_OPEN, "/proc/net/dev"); |
247 |
> |
sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/net/dev"); |
248 |
|
return NULL; |
249 |
|
} |
250 |
|
/* read the 2 lines.. Its the title, so we dont care :) */ |
294 |
|
sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin"); |
295 |
|
return NULL; |
296 |
|
#endif |
297 |
+ |
#ifdef HPUX |
298 |
+ |
sg_set_error(SG_ERROR_UNSUPPORTED, "HP-UX"); |
299 |
+ |
return NULL; |
300 |
+ |
#endif |
301 |
|
|
302 |
|
*entries=interfaces; |
303 |
|
|
394 |
|
return diff; |
395 |
|
} |
396 |
|
|
397 |
+ |
int sg_network_io_compare_name(const void *va, const void *vb) { |
398 |
+ |
const sg_network_io_stats *a = (const sg_network_io_stats *)va; |
399 |
+ |
const sg_network_io_stats *b = (const sg_network_io_stats *)vb; |
400 |
+ |
|
401 |
+ |
return strcmp(a->interface_name, b->interface_name); |
402 |
+ |
} |
403 |
+ |
|
404 |
|
/* NETWORK INTERFACE STATS */ |
405 |
|
|
406 |
|
static void network_iface_stat_init(sg_network_iface_stats *s) { |
441 |
|
|
442 |
|
#ifdef ALLBSD |
443 |
|
if(getifaddrs(&net) != 0){ |
444 |
< |
sg_set_error(SG_ERROR_GETIFADDRS, NULL); |
444 |
> |
sg_set_error_with_errno(SG_ERROR_GETIFADDRS, NULL); |
445 |
|
return NULL; |
446 |
|
} |
447 |
|
|
549 |
|
} |
550 |
|
|
551 |
|
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) { |
552 |
< |
sg_set_error(SG_ERROR_SOCKET, NULL); |
552 |
> |
sg_set_error_with_errno(SG_ERROR_SOCKET, NULL); |
553 |
|
return NULL; |
554 |
|
} |
555 |
|
|
608 |
|
#ifdef LINUX |
609 |
|
f = fopen("/proc/net/dev", "r"); |
610 |
|
if(f == NULL){ |
611 |
< |
sg_set_error(SG_ERROR_OPEN, "/proc/net/dev"); |
611 |
> |
sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/net/dev"); |
612 |
|
return NULL; |
613 |
|
} |
614 |
|
|
615 |
|
/* Setup stuff so we can do the ioctl to get the info */ |
616 |
|
if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){ |
617 |
< |
sg_set_error(SG_ERROR_SOCKET, NULL); |
617 |
> |
sg_set_error_with_errno(SG_ERROR_SOCKET, NULL); |
618 |
|
return NULL; |
619 |
|
} |
620 |
|
|
697 |
|
#endif |
698 |
|
*entries = ifaces; |
699 |
|
return network_iface_stats; |
700 |
+ |
} |
701 |
+ |
|
702 |
+ |
int sg_network_iface_compare_name(const void *va, const void *vb) { |
703 |
+ |
const sg_network_iface_stats *a = (const sg_network_iface_stats *)va; |
704 |
+ |
const sg_network_iface_stats *b = (const sg_network_iface_stats *)vb; |
705 |
+ |
|
706 |
+ |
return strcmp(a->interface_name, b->interface_name); |
707 |
|
} |
708 |
|
|