vnstat  2.9
About: vnStat is a console-based network traffic monitor (using the /proc filesystem).
  Fossies Dox: vnstat-2.9.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

iflist.c
Go to the documentation of this file.
1#include "common.h"
2#include "iflist.h"
3
4int iflistadd(iflist **ifl, const char *iface, const uint32_t bandwidth)
5{
6 iflist *newif = NULL, *ifl_iterator = *ifl;
7
8 newif = malloc(sizeof(iflist));
9 if (newif == NULL) {
10 return 0;
11 }
12
13 newif->next = NULL;
14
15 if (*ifl != NULL) {
16 while (ifl_iterator->next != NULL) {
17 ifl_iterator = ifl_iterator->next;
18 }
19 ifl_iterator->next = newif;
20 } else {
21 *ifl = newif;
22 }
23
24 strncpy_nt(newif->interface, iface, 32);
25 newif->bandwidth = bandwidth;
26
27 return 1;
28}
29
30int iflistsearch(iflist **ifl, const char *iface)
31{
32 iflist *ifl_iterator = *ifl;
33
34 while (ifl_iterator != NULL) {
35 if (strcmp(iface, ifl_iterator->interface) == 0) {
36 return 1;
37 }
38 ifl_iterator = ifl_iterator->next;
39 }
40 return 0;
41}
42
43void iflistfree(iflist **ifl)
44{
45 iflist *ifl_prev;
46
47 while (*ifl != NULL) {
48 ifl_prev = *ifl;
49 *ifl = (*ifl)->next;
50 free(ifl_prev);
51 }
52}
char * strncpy_nt(char *dest, const char *src, size_t n)
Definition: common.c:253
int iflistsearch(iflist **ifl, const char *iface)
Definition: iflist.c:30
void iflistfree(iflist **ifl)
Definition: iflist.c:43
int iflistadd(iflist **ifl, const char *iface, const uint32_t bandwidth)
Definition: iflist.c:4
Definition: iflist.h:4
struct iflist * next
Definition: iflist.h:7
char interface[32]
Definition: iflist.h:5
uint32_t bandwidth
Definition: iflist.h:6