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 |
201 |
|
* (although they do track packets in/out). */ |
202 |
+ |
/* FIXME: Show packet counts when byte counts |
203 |
+ |
* not available. */ |
204 |
|
continue; |
205 |
|
} |
206 |
|
|
207 |
+ |
/* Create new network_stats */ |
208 |
|
network_stats=network_stat_malloc((interfaces+1), &sizeof_network_stats, network_stats); |
209 |
|
if(network_stats==NULL){ |
210 |
|
return NULL; |
211 |
|
} |
212 |
|
network_stat_ptr=network_stats+interfaces; |
213 |
+ |
|
214 |
+ |
/* Finish reading rx */ |
215 |
|
network_stat_ptr->rx=knp->VALTYPE; |
216 |
|
|
217 |
< |
if((knp=kstat_data_lookup(ksp, WLOOKUP))==NULL){ |
217 |
> |
/* Read tx */ |
218 |
> |
if((knp=kstat_data_lookup(ksp, LTX))==NULL){ |
219 |
|
continue; |
220 |
|
} |
221 |
|
network_stat_ptr->tx=knp->VALTYPE; |
222 |
+ |
|
223 |
+ |
/* Read ipackets */ |
224 |
+ |
if((knp=kstat_data_lookup(ksp, LIPACKETS))==NULL){ |
225 |
+ |
continue; |
226 |
+ |
} |
227 |
+ |
network_stat_ptr->ipackets=knp->VALTYPE; |
228 |
+ |
|
229 |
+ |
/* Read opackets */ |
230 |
+ |
if((knp=kstat_data_lookup(ksp, LOPACKETS))==NULL){ |
231 |
+ |
continue; |
232 |
+ |
} |
233 |
+ |
network_stat_ptr->opackets=knp->VALTYPE; |
234 |
+ |
|
235 |
+ |
/* Read ierrors */ |
236 |
+ |
if((knp=kstat_data_lookup(ksp, "ierrors"))==NULL){ |
237 |
+ |
continue; |
238 |
+ |
} |
239 |
+ |
network_stat_ptr->ierrors=knp->value.ui32; |
240 |
+ |
|
241 |
+ |
/* Read oerrors */ |
242 |
+ |
if((knp=kstat_data_lookup(ksp, "oerrors"))==NULL){ |
243 |
+ |
continue; |
244 |
+ |
} |
245 |
+ |
network_stat_ptr->oerrors=knp->value.ui32; |
246 |
+ |
|
247 |
+ |
/* Read collisions */ |
248 |
+ |
if((knp=kstat_data_lookup(ksp, "collisions"))==NULL){ |
249 |
+ |
continue; |
250 |
+ |
} |
251 |
+ |
network_stat_ptr->collisions=knp->value.ui32; |
252 |
+ |
|
253 |
+ |
/* Read interface name */ |
254 |
|
if(network_stat_ptr->interface_name!=NULL){ |
255 |
|
free(network_stat_ptr->interface_name); |
256 |
|
} |
257 |
|
network_stat_ptr->interface_name=strdup(ksp->ks_name); |
258 |
|
|
259 |
+ |
/* Store systime */ |
260 |
|
network_stat_ptr->systime=time(NULL); |
261 |
+ |
|
262 |
|
interfaces++; |
263 |
|
} |
264 |
|
} |
282 |
|
interfaces=0; |
283 |
|
|
284 |
|
while((fgets(line, sizeof(line), f)) != NULL){ |
285 |
< |
if((regexec(®ex, line, 4, line_match, 0))!=0){ |
285 |
> |
if((regexec(®ex, line, 9, line_match, 0))!=0){ |
286 |
|
continue; |
287 |
|
} |
288 |
|
network_stats=network_stat_malloc((interfaces+1), &sizeof_network_stats, network_stats); |
322 |
|
} |
323 |
|
|
324 |
|
long long transfer_diff(long long new, long long old){ |
325 |
< |
#if defined(SOL7) || defined(LINUX) || defined(FREEBSD) || defined(DFBSD) |
326 |
< |
#define MAXVAL 4294967296LL |
325 |
> |
#if defined(SOL7) || defined(LINUX) || defined(FREEBSD) || defined(DFBSD) || defined(OPENBSD) |
326 |
> |
/* 32-bit quantities, so we must explicitly deal with wraparound. */ |
327 |
> |
#define MAXVAL 0x100000000LL |
328 |
> |
if (new >= old) { |
329 |
> |
return new - old; |
330 |
> |
} else { |
331 |
> |
return MAXVAL + new - old; |
332 |
> |
} |
333 |
|
#else |
334 |
< |
#define MAXVAL 18446744073709551616LL |
334 |
> |
/* 64-bit quantities, so plain subtraction works. */ |
335 |
> |
return new - old; |
336 |
|
#endif |
285 |
– |
long long result; |
286 |
– |
if(new>=old){ |
287 |
– |
result = (new-old); |
288 |
– |
}else{ |
289 |
– |
result = (MAXVAL+(new-old)); |
290 |
– |
} |
291 |
– |
|
292 |
– |
return result; |
293 |
– |
|
337 |
|
} |
338 |
|
|
339 |
|
network_stat_t *get_network_stats_diff(int *entries) { |
340 |
|
static network_stat_t *diff = NULL; |
341 |
|
static int diff_count = 0; |
342 |
< |
network_stat_t *src, *dest; |
342 |
> |
network_stat_t *src = NULL, *dest; |
343 |
|
int i, j, new_count; |
344 |
|
|
345 |
|
if (network_stats == NULL) { |
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 */ |