summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2013-11-04 12:05:07 +0100
committerDavid Herrmann <dh.herrmann@gmail.com>2013-11-04 12:05:07 +0100
commit2bc07f98daabd3778b79b1c7eaf9f7e9d840d0ce (patch)
treef51a99c0280c179980a33f3c49ae6612b57d3b19
parentad20d9868ed348235d96a59ec1a51494b3aac3d7 (diff)
owfd: dhcp: resolve interface name during setup
Resolve the interface name and retrieve the ifindex during setup. We can now print useful error-messages early if the name is invalid. The index is cached so we don't have to call it twice. Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
-rw-r--r--src/dhcp.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/dhcp.c b/src/dhcp.c
index 3894563..f564569 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -38,10 +38,12 @@
#include <unistd.h>
#include "dhcp.h"
#include "gdhcp/gdhcp.h"
+#include "shared.h"
#include "shl_log.h"
struct owfd_dhcp {
struct owfd_dhcp_config config;
+ int ifindex;
GMainLoop *loop;
int sfd;
@@ -116,6 +118,14 @@ static int owfd_dhcp_setup(struct owfd_dhcp *dhcp)
sigset_t mask;
struct sigaction sig;
+ dhcp->ifindex = if_name_to_index(dhcp->config.interface);
+ if (dhcp->ifindex < 0) {
+ r = -EINVAL;
+ log_error("cannot find interface %s (%d)",
+ dhcp->config.interface, dhcp->ifindex);
+ goto error;
+ }
+
dhcp->loop = g_main_loop_new(NULL, FALSE);
sigemptyset(&mask);