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 /networking/udhcp | |
parent | 43b9235f66aa56bb884c13443d9e7d56003b5c36 (diff) | |
download | busybox-w32-bcdec1a8b8bf9fb3ea4de96d153b203e12e035fd.tar.gz busybox-w32-bcdec1a8b8bf9fb3ea4de96d153b203e12e035fd.tar.bz2 busybox-w32-bcdec1a8b8bf9fb3ea4de96d153b203e12e035fd.zip |
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>
Diffstat (limited to 'networking/udhcp')
-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) | |||
195 | return &client6_data.env_ptr[client6_data.env_idx++]; | 195 | return &client6_data.env_ptr[client6_data.env_idx++]; |
196 | } | 196 | } |
197 | 197 | ||
198 | static char *string_option_to_env(uint8_t *option, uint8_t *option_end) | ||
199 | { | ||
200 | const char *ptr, *name = NULL; | ||
201 | unsigned val_len; | ||
202 | int i; | ||
203 | |||
204 | ptr = d6_option_strings; | ||
205 | i = 0; | ||
206 | while (*ptr) { | ||
207 | if (d6_optflags[i].code == option[1]) { | ||
208 | name = ptr; | ||
209 | goto found; | ||
210 | } | ||
211 | ptr += strlen(ptr) + 1; | ||
212 | i++; | ||
213 | } | ||
214 | bb_error_msg("can't find option name for 0x%x, skipping", option[1]); | ||
215 | return NULL; | ||
216 | |||
217 | found: | ||
218 | val_len = (option[2] << 8) | option[3]; | ||
219 | if (val_len + &option[D6_OPT_DATA] > option_end) { | ||
220 | bb_error_msg("option data exceeds option length"); | ||
221 | return NULL; | ||
222 | } | ||
223 | return xasprintf("%s=%.*s", name, val_len, (char*)option + 4); | ||
224 | } | ||
225 | |||
198 | /* put all the parameters into the environment */ | 226 | /* put all the parameters into the environment */ |
199 | static void option_to_env(uint8_t *option, uint8_t *option_end) | 227 | static void option_to_env(uint8_t *option, uint8_t *option_end) |
200 | { | 228 | { |