1 |
|
/* |
2 |
|
* i-scream central monitoring system |
3 |
< |
* http://www.i-scream.org.uk |
4 |
< |
* Copyright (C) 2000-2002 i-scream |
3 |
> |
* http://www.i-scream.org |
4 |
> |
* Copyright (C) 2000-2003 i-scream |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or |
7 |
|
* modify it under the terms of the GNU General Public License |
36 |
|
#include <regex.h> |
37 |
|
#include "tools.h" |
38 |
|
#endif |
39 |
+ |
#ifdef ALLBSD |
40 |
+ |
#include <sys/types.h> |
41 |
+ |
#include <sys/socket.h> |
42 |
+ |
#include <ifaddrs.h> |
43 |
+ |
#include <net/if.h> |
44 |
+ |
#endif |
45 |
|
|
46 |
|
static network_stat_t *network_stats=NULL; |
47 |
|
static int interfaces=0; |
101 |
|
regex_t regex; |
102 |
|
regmatch_t line_match[4]; |
103 |
|
#endif |
104 |
+ |
#ifdef ALLBSD |
105 |
+ |
struct ifaddrs *net, *net_ptr; |
106 |
+ |
struct if_data *net_data; |
107 |
+ |
#endif |
108 |
|
|
109 |
+ |
#ifdef ALLBSD |
110 |
+ |
if(getifaddrs(&net) != 0){ |
111 |
+ |
return NULL; |
112 |
+ |
} |
113 |
+ |
|
114 |
+ |
interfaces=0; |
115 |
+ |
|
116 |
+ |
for(net_ptr=net;net_ptr!=NULL;net_ptr=net_ptr->ifa_next){ |
117 |
+ |
if(net_ptr->ifa_addr->sa_family != AF_LINK) continue; |
118 |
+ |
network_stats=network_stat_malloc((interfaces+1), &sizeof_network_stats, network_stats); |
119 |
+ |
if(network_stats==NULL){ |
120 |
+ |
return NULL; |
121 |
+ |
} |
122 |
+ |
network_stat_ptr=network_stats+interfaces; |
123 |
+ |
|
124 |
+ |
if(network_stat_ptr->interface_name!=NULL) free(network_stat_ptr->interface_name); |
125 |
+ |
network_stat_ptr->interface_name=strdup(net_ptr->ifa_name); |
126 |
+ |
if(network_stat_ptr->interface_name==NULL) return NULL; |
127 |
+ |
net_data=(struct if_data *)net_ptr->ifa_data; |
128 |
+ |
network_stat_ptr->rx=net_data->ifi_ibytes; |
129 |
+ |
network_stat_ptr->tx=net_data->ifi_obytes; |
130 |
+ |
network_stat_ptr->systime=time(NULL); |
131 |
+ |
interfaces++; |
132 |
+ |
} |
133 |
+ |
freeifaddrs(net); |
134 |
+ |
#endif |
135 |
+ |
|
136 |
|
#ifdef SOLARIS |
137 |
|
if ((kc = kstat_open()) == NULL) { |
138 |
|
return NULL; |
224 |
|
regfree(®ex); |
225 |
|
|
226 |
|
#endif |
227 |
+ |
|
228 |
+ |
#ifdef CYGWIN |
229 |
+ |
return NULL; |
230 |
+ |
#endif |
231 |
+ |
|
232 |
|
*entries=interfaces; |
233 |
|
|
234 |
|
return network_stats; |
235 |
|
} |
236 |
|
|
237 |
|
long long transfer_diff(long long new, long long old){ |
238 |
< |
#ifdef SOL7 |
239 |
< |
#define MAXVAL 4294967296 |
238 |
> |
#if defined(SOL7) || defined(LINUX) || defined(FREEBSD) |
239 |
> |
#define MAXVAL 4294967296LL |
240 |
|
#else |
241 |
< |
#define MAXVAL 18446744073709551616 |
241 |
> |
#define MAXVAL 18446744073709551616LL |
242 |
|
#endif |
243 |
|
long long result; |
244 |
|
if(new>=old){ |
284 |
|
network_stats_diff_ptr++; |
285 |
|
} |
286 |
|
network_stats_ptr=get_network_stats(&ifaces); |
287 |
+ |
if (network_stats_ptr == NULL) { |
288 |
+ |
return NULL; |
289 |
+ |
} |
290 |
|
network_stats_diff_ptr=network_stats_diff; |
291 |
|
|
292 |
|
for(x=0;x<sizeof_net_stats_diff;x++){ |