getifaddrs

Link to this paste: http://bugs.dragonflybsd.org/pastes/432

Added by tuxillo 12 months ago.
Syntax: C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <strings.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <ifaddrs.h>
#include <err.h>

int
main(int argc, char *argv[])
{
        struct ifaddrs *ifa;
        struct if_data ifd;

        if (getifaddrs(&ifa) < 0)
                err(1, "getifaddrs");

        for(; ifa->ifa_next != NULL; ifa = ifa->ifa_next) {
                printf("%s\n", ifa->ifa_name);
                if (ifa->ifa_data != NULL) {
                        bcopy(ifa->ifa_data, &ifd, sizeof(ifd));
                        printf("\t%lu:\n", ifd.ifi_ipackets);
                }

        }

        return 0;
}

Download