version 1.21, 2014/06/23 03:46:17 |
version 1.22, 2014/08/14 12:34:04 |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include "netstat.h" |
#include "netstat.h" |
|
|
static void print_bw_meter(struct bw_meter *bw_meter, int *banner_printed); |
|
|
|
static char * |
static char * |
pktscale(u_long n) |
pktscale(u_long n) |
{ |
{ |
|
|
|
|
printf("\n"); |
printf("\n"); |
|
|
/* Print the bw meter information */ |
|
{ |
|
struct bw_meter bw_meter, *bwm; |
|
int banner_printed2 = 0; |
|
|
|
bwm = mfc.mfc_bw_meter; |
|
while (bwm) { |
|
kread((u_long)bwm, |
|
&bw_meter, |
|
sizeof bw_meter); |
|
print_bw_meter(&bw_meter, |
|
&banner_printed2); |
|
bwm = bw_meter.bm_mfc_next; |
|
} |
|
#if 0 /* Don't ever print it? */ |
|
if (! banner_printed2) |
|
printf("\n No Bandwidth Meters\n"); |
|
#endif |
|
} |
|
|
|
nmfc++; |
nmfc++; |
} |
} |
} |
} |
|
|
|
|
printf("\n"); |
printf("\n"); |
nflag = saved_nflag; |
nflag = saved_nflag; |
} |
|
|
|
static void |
|
print_bw_meter(struct bw_meter *bw_meter, int *banner_printed) |
|
{ |
|
char s0[256], s1[256], s2[256], s3[256]; |
|
struct timeval now, end, delta; |
|
|
|
gettimeofday(&now, NULL); |
|
|
|
if (! *banner_printed) { |
|
printf(" Bandwidth Meters\n"); |
|
printf(" %-30s", "Measured(Start|Packets|Bytes)"); |
|
printf(" %s", "Type"); |
|
printf(" %-30s", "Thresh(Interval|Packets|Bytes)"); |
|
printf(" Remain"); |
|
printf("\n"); |
|
*banner_printed = 1; |
|
} |
|
|
|
/* The measured values */ |
|
if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS) |
|
snprintf(s1, sizeof s1, "%llu", |
|
bw_meter->bm_measured.b_packets); |
|
else |
|
snprintf(s1, sizeof s1, "?"); |
|
if (bw_meter->bm_flags & BW_METER_UNIT_BYTES) |
|
snprintf(s2, sizeof s2, "%llu", bw_meter->bm_measured.b_bytes); |
|
else |
|
snprintf(s2, sizeof s2, "?"); |
|
snprintf(s0, sizeof s0, "%lld.%ld|%s|%s", |
|
(long long)bw_meter->bm_start_time.tv_sec, |
|
bw_meter->bm_start_time.tv_usec, |
|
s1, s2); |
|
printf(" %-30s", s0); |
|
|
|
/* The type of entry */ |
|
snprintf(s0, sizeof s0, "%s", "?"); |
|
if (bw_meter->bm_flags & BW_METER_GEQ) |
|
snprintf(s0, sizeof s0, "%s", ">="); |
|
else if (bw_meter->bm_flags & BW_METER_LEQ) |
|
snprintf(s0, sizeof s0, "%s", "<="); |
|
printf(" %-3s", s0); |
|
|
|
/* The threshold values */ |
|
if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS) |
|
snprintf(s1, sizeof s1, "%llu", |
|
bw_meter->bm_threshold.b_packets); |
|
else |
|
snprintf(s1, sizeof s1, "?"); |
|
if (bw_meter->bm_flags & BW_METER_UNIT_BYTES) |
|
snprintf(s2, sizeof s2, "%llu", |
|
bw_meter->bm_threshold.b_bytes); |
|
else |
|
snprintf(s2, sizeof s2, "?"); |
|
snprintf(s0, sizeof s0, "%lld.%ld|%s|%s", |
|
(long long)bw_meter->bm_threshold.b_time.tv_sec, |
|
bw_meter->bm_threshold.b_time.tv_usec, |
|
s1, s2); |
|
printf(" %-30s", s0); |
|
|
|
/* Remaining time */ |
|
timeradd(&bw_meter->bm_start_time, |
|
&bw_meter->bm_threshold.b_time, &end); |
|
if (timercmp(&now, &end, <=)) { |
|
timersub(&end, &now, &delta); |
|
snprintf(s3, sizeof s3, "%lld.%ld", |
|
(long long)delta.tv_sec, delta.tv_usec); |
|
} else { |
|
/* Negative time */ |
|
timersub(&now, &end, &delta); |
|
snprintf(s3, sizeof s3, "-%lld.%ld", |
|
(long long)delta.tv_sec, delta.tv_usec); |
|
} |
|
printf(" %s", s3); |
|
|
|
printf("\n"); |
|
} |
} |
|
|
void |
void |