From 72bc39afb1fdab56f26acf36c229e943b426b16e Mon Sep 17 00:00:00 2001 From: hev Date: Sun, 30 Jun 2024 16:23:12 +0800 Subject: [PATCH] HevConf: Add support for IP address values in `-i` parameter. Fixes #66 --- README.md | 2 +- src/hev-conf.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6ca4209..9b91d4b 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Options: -6 use IPv6 -u UDP mode -d run as daemon - -i network interface + -i network interface or IP address -k seconds between each keep-alive -s [:port] domain name or address of STUN server -h [:port] domain name or address of HTTP server diff --git a/src/hev-conf.c b/src/hev-conf.c index 4afaccd..36a9d7f 100644 --- a/src/hev-conf.c +++ b/src/hev-conf.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include "hev-misc.h" @@ -17,7 +19,7 @@ #include "hev-conf.h" static int mode = SOCK_STREAM; -static int type = AF_UNSPEC; +static int type = AF_INET; static int keep; static int dmon; static int tmsec; @@ -48,7 +50,7 @@ hev_conf_help (void) " -6 use IPv6\n" " -u UDP mode\n" " -d run as daemon\n" - " -i network interface\n" + " -i network interface or IP address\n" " -k seconds between each keep-alive\n" " -s [:port] domain name or address of STUN server\n" " -h [:port] domain name or address of HTTP server\n" @@ -70,6 +72,7 @@ int hev_conf_init (int argc, char *argv[]) { int opt; + struct sockaddr_in6 sa; while ((opt = getopt (argc, argv, "46udk:s:h:e:f:b:T:t:p:i:")) != -1) { switch (opt) { @@ -141,7 +144,12 @@ hev_conf_init (int argc, char *argv[]) bport = "0"; } - baddr = (type == AF_INET6) ? "::" : "0.0.0.0"; + if (iface && inet_pton (type, iface, &sa)) { + baddr = iface; + iface = NULL; + } else { + baddr = (type == AF_INET6) ? "::" : "0.0.0.0"; + } if (tmsec <= 0) { tmsec = 120000;