From: Michael Tremer Date: Sun, 4 Feb 2018 17:11:16 +0000 (+0000) Subject: libnetwork: Get index for interfaces X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d1f1b577378e953337c11fc471e7bece9c38e5fb;p=people%2Fjschlag%2Fnetwork.git libnetwork: Get index for interfaces Signed-off-by: Michael Tremer --- diff --git a/configure.ac b/configure.ac index 309ff79..faec66b 100644 --- a/configure.ac +++ b/configure.ac @@ -98,6 +98,7 @@ AC_SUBST([OUR_LDFLAGS], $with_ldflags) AC_CHECK_HEADERS_ONCE([ ctype.h errno.h + net/if.h stdarg.h stdio.h stdlib.h diff --git a/src/libnetwork/interface.c b/src/libnetwork/interface.c index 383941c..02ccbdc 100644 --- a/src/libnetwork/interface.c +++ b/src/libnetwork/interface.c @@ -19,6 +19,7 @@ #############################################################################*/ #include +#include #include #include @@ -31,6 +32,7 @@ struct network_interface { struct network_ctx* ctx; int refcount; + unsigned int index; char* name; }; @@ -39,6 +41,12 @@ NETWORK_EXPORT int network_interface_new(struct network_ctx* ctx, if (!name) return -EINVAL; + unsigned int index = if_nametoindex(name); + if (!index) { + ERROR(ctx, "Could not find interface %s\n", name); + return -ENODEV; + } + struct network_interface* i = calloc(1, sizeof(*i)); if (!i) return -ENOMEM; @@ -46,6 +54,7 @@ NETWORK_EXPORT int network_interface_new(struct network_ctx* ctx, // Initialise object i->ctx = network_ref(ctx); i->refcount = 1; + i->index = index; i->name = strdup(name); DEBUG(i->ctx, "Allocated network interface at %p\n", i);