"Fossies" - the Fresh Open Source Software Archive 
Member "vnstat-2.9/src/iflist.c" (28 Jun 2019, 885 Bytes) of package /linux/misc/vnstat-2.9.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "iflist.c" see the
Fossies "Dox" file reference documentation.
1 #include "common.h"
2 #include "iflist.h"
3
4 int 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
30 int 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
43 void 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 }