diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2013-11-04 17:41:07 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2013-11-04 17:47:08 +0100 |
commit | f9669a929c07800b44feda6c2ec06073da325d52 (patch) | |
tree | d0985bffb39ac861b379a6bce8587ac6d1b85b8c | |
parent | b721541ef780dcdc96daa10299785714c4f8118a (diff) |
owfd: dhcp: add --ipv4/ipv6 option
These options are mandatory and select which DHCP flavor to run. Note that
ipv6 servers are not provided by gdhcp.
All our arguments are IPv6 only! If you pass IPv4 addresses, you must
embed them in ipv6 addresses as usual. This will avoid any IPv4 special
handling in the caller (though internally we still need to distinguish
them).
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
-rw-r--r-- | src/dhcp.h | 2 | ||||
-rw-r--r-- | src/dhcp_config.c | 28 |
2 files changed, 29 insertions, 1 deletions
@@ -42,6 +42,8 @@ struct owfd_dhcp_config { unsigned int client : 1; unsigned int server : 1; + unsigned int ipv4 : 1; + unsigned int ipv6 : 1; char *interface; char *ip_binary; diff --git a/src/dhcp_config.c b/src/dhcp_config.c index 28d050c..599628d 100644 --- a/src/dhcp_config.c +++ b/src/dhcp_config.c @@ -44,6 +44,8 @@ enum { OPT_CLIENT, OPT_SERVER, + OPT_IPV4, + OPT_IPV6, OPT_INTERFACE, OPT_IP_BINARY, @@ -56,7 +58,7 @@ enum { OPT_IP_TO, }; -const char short_options[] = ":hvcsi:"; +const char short_options[] = ":hvcs46i:"; #define OPT(_name, _arg, _val) \ { .name = _name, .has_arg = _arg, .val = LONG_OPT_OFFSET + _val } @@ -68,6 +70,8 @@ const struct option long_options[] = { OPT("client", 0, OPT_CLIENT), OPT("server", 0, OPT_SERVER), + OPT("ipv4", 0, OPT_IPV4), + OPT("ipv6", 0, OPT_IPV6), OPT("interface", 1, OPT_INTERFACE), OPT("ip-binary", 1, OPT_IP_BINARY), @@ -131,6 +135,8 @@ static void show_help(void) "Modus Options:\n" "\t-c, --client [off] Run as DHCP client\n" "\t-s, --server [off] Run as DHCP server\n" + "\t-4, --ipv4 [off] Run via IPv4 DHCP\n" + "\t-6, --ipv6 [off] Run via IPv6 DHCP\n" "\n" "Network Options:\n" "\t-i, --interface <wlan0> [] Wireless interface to run on\n" @@ -237,6 +243,16 @@ int owfd_dhcp_parse_argv(struct owfd_dhcp_config *conf, int argc, char **argv) conf->client = 0; conf->server = 1; break; + case '4': + case OPT(OPT_IPV4): + conf->ipv6 = 0; + conf->ipv4 = 1; + break; + case '6': + case OPT(OPT_IPV6): + conf->ipv4 = 0; + conf->ipv6 = 1; + break; case 'i': case OPT(OPT_INTERFACE): @@ -318,6 +334,16 @@ int owfd_dhcp_parse_argv(struct owfd_dhcp_config *conf, int argc, char **argv) return -EINVAL; } + if (!conf->ipv4 && !conf->ipv6) { + fprintf(stderr, "no --ipv4 or --ipv6 given\n"); + return -EINVAL; + } + + if (conf->ipv6) { + fprintf(stderr, "--ipv6 not implemented by gdhcp, yet\n"); + return -EINVAL; + } + if (!conf->interface) { fprintf(stderr, "no interface given, use: -i <iface>\n"); return -EINVAL; |