diff options
author | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2018-05-14 14:29:11 +1000 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-05-14 10:46:00 +0200 |
commit | bcdec1a8b8bf9fb3ea4de96d153b203e12e035fd (patch) | |
tree | 332059063249009610ee676388392099606a0a74 | |
parent | 43b9235f66aa56bb884c13443d9e7d56003b5c36 (diff) | |
download | busybox-bcdec1a8b8bf9fb3ea4de96d153b203e12e035fd.tar.gz |
udhcpc6: add DHCPv6 env helper
Add string_option_to_env() to easily generate environment variables for
known simple options.
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/udhcp/d6_dhcpc.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 85d9da724..fa1568b5f 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -195,6 +195,34 @@ static char** new_env(void) return &client6_data.env_ptr[client6_data.env_idx++]; } +static char *string_option_to_env(uint8_t *option, uint8_t *option_end) +{ + const char *ptr, *name = NULL; + unsigned val_len; + int i; + + ptr = d6_option_strings; + i = 0; + while (*ptr) { + if (d6_optflags[i].code == option[1]) { + name = ptr; + goto found; + } + ptr += strlen(ptr) + 1; + i++; + } + bb_error_msg("can't find option name for 0x%x, skipping", option[1]); + return NULL; + + found: + val_len = (option[2] << 8) | option[3]; + if (val_len + &option[D6_OPT_DATA] > option_end) { + bb_error_msg("option data exceeds option length"); + return NULL; + } + return xasprintf("%s=%.*s", name, val_len, (char*)option + 4); +} + /* put all the parameters into the environment */ static void option_to_env(uint8_t *option, uint8_t *option_end) { |