summaryrefslogtreecommitdiff
path: root/llmnrd.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 /llmnrd.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 'llmnrd.c')
-rw-r--r--llmnrd.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/llmnrd.c b/llmnrd.c
index 866e919..2bc4a20 100644
--- a/llmnrd.c
+++ b/llmnrd.c
@@ -39,9 +39,10 @@
#include "llmnr.h"
#include "llmnr-packet.h"
-static const char *short_opts = "H:p:6dhV";
+static const char *short_opts = "H:i:p:6dhV";
static const struct option long_opts[] = {
{ "hostname", required_argument, NULL, 'H' },
+ { "interface", required_argument, NULL, 'i' },
{ "port", required_argument, NULL, 'p' },
{ "ipv6", no_argument, NULL, '6' },
{ "daemonize", no_argument, NULL, 'd' },
@@ -55,6 +56,7 @@ static void __noreturn usage_and_exit(int status)
fprintf(stdout, "Usage: llmnrd [OPTIONS]\n"
"Options:\n"
" -H, --hostname NAME set hostname to respond with (default: system hostname)\n"
+ " -i, --interface DEV bind socket to a specific interface, e.g. eth0\n"
" -p, --port NUM set port number to listen on (default: %d)\n"
" -6, --ipv6 enable LLMNR name resolution over IPv6\n"
" -d, --daemonize run as daemon in the background\n"
@@ -113,6 +115,7 @@ int main(int argc, char **argv)
long num_arg;
bool daemonize = false, ipv6 = false;
char *hostname = NULL;
+ char *iface = NULL;
uint16_t port = LLMNR_UDP_PORT;
while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
@@ -123,6 +126,9 @@ int main(int argc, char **argv)
case 'H':
hostname = xstrdup(optarg);
break;
+ case 'i':
+ iface = xstrdup(optarg);
+ break;
case 'p':
num_arg = strtol(optarg, NULL, 0);
if (num_arg < 0 || num_arg > UINT16_MAX) {
@@ -164,10 +170,10 @@ int main(int argc, char **argv)
}
}
- if (llmnr_init(hostname, port, ipv6) < 0)
+ if (llmnr_init(hostname, port, ipv6, iface) < 0)
goto out;
- if (iface_start_thread(ipv6) < 0)
+ if (iface_start_thread(ipv6, iface) < 0)
goto out;
ret = llmnr_run();