summaryrefslogtreecommitdiff
path: root/iface.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2016-08-17 08:41:52 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-08-17 08:41:52 +0200
commitf46d59e0dc7b54a3f4a7ead2fd2d4258b3f56782 (patch)
tree076ca9422193ee640dc16c69c0923a4c9feeaec1 /iface.c
parentf1081b6b0f47160f83ded689d956bd577819d752 (diff)
llmnrd: Allow to bind to a specific network interface
Add a command line option -i/--interface which allows to bind the llmnrd sockets to a specific interface. If used, requests are only answered on the specified interface. Example: llmnrd -i eth0 Closes #9 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'iface.c')
-rw-r--r--iface.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/iface.c b/iface.c
index 8cb88fc..333a142 100644
--- a/iface.c
+++ b/iface.c
@@ -42,6 +42,7 @@
static bool iface_running = true;
static bool iface_ipv6 = false;
+static unsigned int iface_ifindex = 0;
static pthread_t iface_thread;
static iface_event_handler_t iface_event_handler;
@@ -234,6 +235,13 @@ static void iface_nlmsg_change_addr(const struct nlmsghdr *nlh)
if ((ifa->ifa_flags & (IFA_F_TEMPORARY | IFA_F_TENTATIVE)) != 0)
return;
+ /*
+ * If bound to a specific interface, don't report addresses of any other
+ * interface.
+ */
+ if (iface_ifindex > 0 && index != iface_ifindex)
+ return;
+
if_indextoname(index, ifname);
rta = (struct rtattr *)((const uint8_t *)nlh + NLMSG_SPACE(sizeof(*ifa)));
@@ -388,9 +396,11 @@ static void* iface_run_wrapper(void *data __unused)
return ERR_PTR(iface_run());
}
-int iface_start_thread(bool ipv6)
+int iface_start_thread(bool ipv6, const char *iface)
{
iface_ipv6 = ipv6;
+ if (iface)
+ iface_ifindex = if_nametoindex(iface);
if (pthread_create(&iface_thread, NULL, iface_run_wrapper, NULL) < 0) {
log_err("Failed to start interface monitoring thread\n");