77 |
|
net_stats->interface_name=NULL; |
78 |
|
net_stats->tx=0; |
79 |
|
net_stats->rx=0; |
80 |
+ |
net_stats->ipackets=0; |
81 |
+ |
net_stats->opackets=0; |
82 |
+ |
net_stats->ierrors=0; |
83 |
+ |
net_stats->oerrors=0; |
84 |
+ |
net_stats->collisions=0; |
85 |
|
net_stats++; |
86 |
|
} |
87 |
|
} |
129 |
|
/* Horrible big enough, but it should be easily big enough */ |
130 |
|
char line[8096]; |
131 |
|
regex_t regex; |
132 |
< |
regmatch_t line_match[4]; |
132 |
> |
regmatch_t line_match[9]; |
133 |
|
#endif |
134 |
|
#ifdef ALLBSD |
135 |
|
struct ifaddrs *net, *net_ptr; |
156 |
|
if(network_stat_ptr->interface_name==NULL) return NULL; |
157 |
|
net_data=(struct if_data *)net_ptr->ifa_data; |
158 |
|
network_stat_ptr->rx=net_data->ifi_ibytes; |
159 |
< |
network_stat_ptr->tx=net_data->ifi_obytes; |
159 |
> |
network_stat_ptr->tx=net_data->ifi_obytes; |
160 |
> |
network_stat_ptr->ipackets=net_data->ifi_ipackets; |
161 |
> |
network_stat_ptr->opackets=net_data->ifi_opackets; |
162 |
> |
network_stat_ptr->ierrors=net_data->ifi_ierrors; |
163 |
> |
network_stat_ptr->oerrors=net_data->ifi_oerrors; |
164 |
> |
network_stat_ptr->collisions=net_data->ifi_collisions; |
165 |
|
network_stat_ptr->systime=time(NULL); |
166 |
|
interfaces++; |
167 |
|
} |
180 |
|
kstat_read(kc, ksp, NULL); |
181 |
|
|
182 |
|
#ifdef SOL7 |
183 |
< |
#define RLOOKUP "rbytes" |
184 |
< |
#define WLOOKUP "obytes" |
183 |
> |
#define LRX "rbytes" |
184 |
> |
#define LTX "obytes" |
185 |
> |
#define LIPACKETS "ipackets" |
186 |
> |
#define LOPACKETS "opackets" |
187 |
|
#define VALTYPE value.ui32 |
188 |
|
#else |
189 |
< |
#define RLOOKUP "rbytes64" |
190 |
< |
#define WLOOKUP "obytes64" |
189 |
> |
#define LRX "rbytes64" |
190 |
> |
#define LTX "obytes64" |
191 |
> |
#define LIPACKETS "ipackets64" |
192 |
> |
#define LOPACKETS "opackets64" |
193 |
|
#define VALTYPE value.ui64 |
194 |
|
#endif |
195 |
|
|
196 |
< |
if((knp=kstat_data_lookup(ksp, RLOOKUP))==NULL){ |
196 |
> |
/* Read rx */ |
197 |
> |
if((knp=kstat_data_lookup(ksp, LRX))==NULL){ |
198 |
|
/* This is a network interface, but it doesn't |
199 |
|
* have the rbytes/obytes values; for instance, |
200 |
|
* the loopback devices have this behaviour |
202 |
|
continue; |
203 |
|
} |
204 |
|
|
205 |
+ |
/* Create new network_stats */ |
206 |
|
network_stats=network_stat_malloc((interfaces+1), &sizeof_network_stats, network_stats); |
207 |
|
if(network_stats==NULL){ |
208 |
|
return NULL; |
209 |
|
} |
210 |
|
network_stat_ptr=network_stats+interfaces; |
211 |
+ |
|
212 |
+ |
/* Finish reading rx */ |
213 |
|
network_stat_ptr->rx=knp->VALTYPE; |
214 |
|
|
215 |
< |
if((knp=kstat_data_lookup(ksp, WLOOKUP))==NULL){ |
215 |
> |
/* Read tx */ |
216 |
> |
if((knp=kstat_data_lookup(ksp, LTX))==NULL){ |
217 |
|
continue; |
218 |
|
} |
219 |
|
network_stat_ptr->tx=knp->VALTYPE; |
220 |
+ |
|
221 |
+ |
/* Read ipackets */ |
222 |
+ |
if((knp=kstat_data_lookup(ksp, LIPACKETS))==NULL){ |
223 |
+ |
continue; |
224 |
+ |
} |
225 |
+ |
network_stat_ptr->ipackets=knp->VALTYPE; |
226 |
+ |
|
227 |
+ |
/* Read opackets */ |
228 |
+ |
if((knp=kstat_data_lookup(ksp, LOPACKETS))==NULL){ |
229 |
+ |
continue; |
230 |
+ |
} |
231 |
+ |
network_stat_ptr->opackets=knp->VALTYPE; |
232 |
+ |
|
233 |
+ |
/* Read ierrors */ |
234 |
+ |
if((knp=kstat_data_lookup(ksp, "ierrors"))==NULL){ |
235 |
+ |
continue; |
236 |
+ |
} |
237 |
+ |
network_stat_ptr->ierrors=knp->value.ui32; |
238 |
+ |
|
239 |
+ |
/* Read oerrors */ |
240 |
+ |
if((knp=kstat_data_lookup(ksp, "oerrors"))==NULL){ |
241 |
+ |
continue; |
242 |
+ |
} |
243 |
+ |
network_stat_ptr->oerrors=knp->value.ui32; |
244 |
+ |
|
245 |
+ |
/* Read collisions */ |
246 |
+ |
if((knp=kstat_data_lookup(ksp, "collisions"))==NULL){ |
247 |
+ |
continue; |
248 |
+ |
} |
249 |
+ |
network_stat_ptr->collisions=knp->value.ui32; |
250 |
+ |
|
251 |
+ |
/* Read interface name */ |
252 |
|
if(network_stat_ptr->interface_name!=NULL){ |
253 |
|
free(network_stat_ptr->interface_name); |
254 |
|
} |
255 |
|
network_stat_ptr->interface_name=strdup(ksp->ks_name); |
256 |
|
|
257 |
+ |
/* Store systime */ |
258 |
|
network_stat_ptr->systime=time(NULL); |
259 |
+ |
|
260 |
|
interfaces++; |
261 |
|
} |
262 |
|
} |
273 |
|
fgets(line, sizeof(line), f); |
274 |
|
|
275 |
|
|
276 |
< |
if((regcomp(®ex, "^[[:space:]]*([^:]+):[[:space:]]*([[:digit:]]+)[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+([[:digit:]]+)", REG_EXTENDED))!=0){ |
276 |
> |
if((regcomp(®ex, "^ *([^:]+): *([0-9]+) +([0-9]+) +([0-9]+) +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +([0-9]+) +([0-9]+) +([0-9]+) +[0-9]+ +[0-9]+ +([0-9]+)", REG_EXTENDED))!=0){ |
277 |
|
return NULL; |
278 |
|
} |
279 |
|
|
280 |
|
interfaces=0; |
281 |
|
|
282 |
|
while((fgets(line, sizeof(line), f)) != NULL){ |
283 |
< |
if((regexec(®ex, line, 4, line_match, 0))!=0){ |
283 |
> |
if((regexec(®ex, line, 9, line_match, 0))!=0){ |
284 |
|
continue; |
285 |
|
} |
286 |
|
network_stats=network_stat_malloc((interfaces+1), &sizeof_network_stats, network_stats); |
295 |
|
|
296 |
|
network_stat_ptr->interface_name=get_string_match(line, &line_match[1]); |
297 |
|
network_stat_ptr->rx=get_ll_match(line, &line_match[2]); |
298 |
< |
network_stat_ptr->tx=get_ll_match(line, &line_match[3]); |
298 |
> |
network_stat_ptr->tx=get_ll_match(line, &line_match[5]); |
299 |
> |
network_stat_ptr->ipackets=get_ll_match(line, &line_match[3]); |
300 |
> |
network_stat_ptr->opackets=get_ll_match(line, &line_match[6]); |
301 |
> |
network_stat_ptr->ierrors=get_ll_match(line, &line_match[4]); |
302 |
> |
network_stat_ptr->oerrors=get_ll_match(line, &line_match[7]); |
303 |
> |
network_stat_ptr->collisions=get_ll_match(line, &line_match[8]); |
304 |
|
network_stat_ptr->systime=time(NULL); |
305 |
|
|
306 |
|
interfaces++; |
321 |
|
|
322 |
|
long long transfer_diff(long long new, long long old){ |
323 |
|
#if defined(SOL7) || defined(LINUX) || defined(FREEBSD) || defined(DFBSD) |
324 |
< |
#define MAXVAL 4294967296LL |
324 |
> |
#define MAXVAL 0xffffffffLL |
325 |
|
#else |
326 |
< |
#define MAXVAL 18446744073709551616LL |
326 |
> |
#define MAXVAL 0xffffffffffffffffLL |
327 |
|
#endif |
328 |
|
long long result; |
329 |
|
if(new>=old){ |
364 |
|
dest->interface_name = strdup(src->interface_name); |
365 |
|
dest->rx = src->rx; |
366 |
|
dest->tx = src->tx; |
367 |
+ |
dest->ipackets = src->ipackets; |
368 |
+ |
dest->opackets = src->opackets; |
369 |
+ |
dest->ierrors = src->ierrors; |
370 |
+ |
dest->oerrors = src->oerrors; |
371 |
+ |
dest->collisions = src->collisions; |
372 |
|
dest->systime = src->systime; |
373 |
|
} |
374 |
|
|
399 |
|
difference. */ |
400 |
|
dest->rx = transfer_diff(src->rx, dest->rx); |
401 |
|
dest->tx = transfer_diff(src->tx, dest->tx); |
402 |
+ |
dest->ipackets = transfer_diff(src->ipackets, dest->ipackets); |
403 |
+ |
dest->opackets = transfer_diff(src->opackets, dest->opackets); |
404 |
+ |
dest->ierrors = transfer_diff(src->ierrors, dest->ierrors); |
405 |
+ |
dest->oerrors = transfer_diff(src->oerrors, dest->oerrors); |
406 |
+ |
dest->collisions = transfer_diff(src->collisions, dest->collisions); |
407 |
|
dest->systime = src->systime - dest->systime; |
408 |
|
} |
409 |
|
|
545 |
|
case(IFM_1000_SX): |
546 |
|
case(IFM_1000_LX): |
547 |
|
case(IFM_1000_CX): |
548 |
< |
#ifdef IFM_1000_TX |
549 |
< |
case(IFM_1000_TX): /* FreeBSD 4 and others? */ |
548 |
> |
#if defined(IFM_1000_TX) && !defined(OPENBSD) |
549 |
> |
case(IFM_1000_TX): /* FreeBSD 4 and others (but NOT OpenBSD)? */ |
550 |
|
#endif |
551 |
|
#ifdef IFM_1000_FX |
552 |
|
case(IFM_1000_FX): /* FreeBSD 4 */ |