1 |
Network Statistics |
2 |
|
3 |
All network statistics return a network_stat_t structure. |
4 |
|
5 |
typedef struct{ |
6 |
char *interface_name; |
7 |
long long tx; |
8 |
long long rx; |
9 |
time_t systime; |
10 |
}network_stat_t; |
11 |
|
12 |
Interface name is the name known to the OS. E.g. eth0 on linux. |
13 |
tx is a long long with the number of bytes transmitted. |
14 |
rx is a long long with the number of bytes recieved. |
15 |
sysname is time_t covering the time the amount of data in rx/tx was |
16 |
generated. |
17 |
|
18 |
|
19 |
network_stat_t *get_network_stats(int *entries); |
20 |
|
21 |
network_stat_t *get_network_stats_diff(int *entries); |
22 |
|
23 |
Both calls takes a pointer to a int, entries. This is filled with the number |
24 |
of network interfaces the machine has. You need to know this to know how |
25 |
many network_stat_t how many network_stat_t have been returned. |
26 |
|
27 |
get_network_stats returns the network traffic stored in the kernel. E.g. |
28 |
since bootup as long as the way it is stored in the kernel can store a large |
29 |
enough number. Solaris 7 can not, it only stores it in a 32bit int, so it |
30 |
can only store upto 4gb before it will wrap around. Solaris 8 upwards stores |
31 |
it in a 64bit int and so is a very large number :) |
32 |
|
33 |
get_network_stats_diff is the same as get_network_stats except it will |
34 |
return the difference since the last call. So, for instance a call to |
35 |
get_network_stats_diff is made, and called again 5 seconds later. Over that |
36 |
time, 20 bytes of traffic was transmitted and 10 bytes received. Tx will |
37 |
store 20, rx will store 10 and systime will store 5. This function copes |
38 |
with wrap arounds by the O/S so should be seemless to use. |
39 |
|
40 |
Bugs: |
41 |
get_network_stats_diff on very first call will return the same as |
42 |
get_network_stats. After first call it will always return the difference. |
43 |
|
44 |
Very basic example in examples/network_traffic.c |
45 |
|