diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2013-11-04 12:05:07 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2013-11-04 12:05:07 +0100 |
commit | 2bc07f98daabd3778b79b1c7eaf9f7e9d840d0ce (patch) | |
tree | f51a99c0280c179980a33f3c49ae6612b57d3b19 | |
parent | ad20d9868ed348235d96a59ec1a51494b3aac3d7 (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.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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); |