23 |
|
* a total |
24 |
|
* Takes several arguments : |
25 |
|
* -d <number> Takes the number of seconds to wait to get traffic sent since last call |
26 |
< |
* Note, this is not network traffic per second. Its the traffic since last |
27 |
< |
* call. If you want it traffic per second averaged over time since last call |
26 |
> |
* Note, this is not network traffic per second. Its the traffic since last |
27 |
> |
* call. If you want it traffic per second averaged over time since last call |
28 |
|
* You need to divide against the time since last time this was called. The time |
29 |
|
* between 2 calls is stored in systime in the network_stat_t structure. |
30 |
|
* -b Display in bytes |
31 |
|
* -k Display in kilobytes |
32 |
< |
* -m Display in megabytes |
32 |
> |
* -m Display in megabytes |
33 |
|
*/ |
34 |
|
|
35 |
|
#include <stdio.h> |
68 |
|
} |
69 |
|
} |
70 |
|
|
71 |
< |
/* We are not intrested in the amount of traffic ever transmitted, just differences. |
71 |
> |
/* Initialise statgrab */ |
72 |
> |
statgrab_init(); |
73 |
> |
|
74 |
> |
/* Drop setuid/setgid privileges. */ |
75 |
> |
if (statgrab_drop_privileges() != 0) { |
76 |
> |
perror("Error. Failed to drop privileges"); |
77 |
> |
return 1; |
78 |
> |
} |
79 |
> |
|
80 |
> |
/* We are not interested in the amount of traffic ever transmitted, just differences. |
81 |
|
* Because of this, we do nothing for the very first call. |
82 |
|
*/ |
83 |
< |
|
83 |
> |
|
84 |
|
network_stats = get_network_stats_diff(&num_network_stats); |
85 |
|
if (network_stats == NULL){ |
86 |
|
perror("Error. Failed to get network stats"); |
89 |
|
|
90 |
|
/* Clear the screen ready for display the network stats */ |
91 |
|
printf("\033[2J"); |
92 |
< |
|
92 |
> |
|
93 |
|
/* Keep getting the network stats */ |
94 |
|
while ( (network_stats = get_network_stats_diff(&num_network_stats)) != NULL){ |
95 |
|
int x; |
109 |
|
break; |
110 |
|
case 'k': |
111 |
|
printf("\033[%d;2H%-25s : %5lld k", line_number++, "Network Interface Rx", (network_stats->rx / 1024)); |
112 |
< |
printf("\033[%d;2H%-25s : %5lld", line_number++, "Network Interface Tx", (network_stats->tx / 1024)); |
113 |
< |
break; |
112 |
> |
printf("\033[%d;2H%-25s : %5lld", line_number++, "Network Interface Tx", (network_stats->tx / 1024)); |
113 |
> |
break; |
114 |
|
case 'm': |
115 |
|
printf("\033[%d;2H%-25s : %5.2f m", line_number++, "Network Interface Rx", network_stats->rx / (1024.00*1024.00)); |
116 |
|
printf("\033[%d;2H%-25s : %5.2f m", line_number++, "Network Interface Tx", network_stats->tx / (1024.00*1024.00)); |
117 |
|
} |
118 |
|
printf("\033[%d;2H%-25s : %ld ", line_number++, "Network Interface systime", (long) network_stats->systime); |
119 |
< |
|
119 |
> |
|
120 |
|
/* Add a blank line between interfaces */ |
121 |
|
line_number++; |
122 |
|
|
128 |
|
* to keep track of the orginal pointer to free later */ |
129 |
|
network_stats++; |
130 |
|
} |
131 |
< |
|
131 |
> |
|
132 |
|
printf("\033[%d;2H%-25s : %-10s", line_number++, "Network Interface Name", "Total Network IO"); |
133 |
|
switch(units){ |
134 |
|
case 'b': |
144 |
|
printf("\033[%d;2H%-25s : %5.2f m", line_number++, "Network Total Tx", (total_tx / (1024.00*1024.00))); |
145 |
|
break; |
146 |
|
} |
147 |
< |
|
147 |
> |
|
148 |
|
fflush(stdout); |
149 |
|
|
150 |
|
sleep(delay); |