diff options
author | Denis Vlasenko | 2007-11-29 08:17:45 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-11-29 08:17:45 +0000 |
commit | b539c8452f823a377bf629cf0e44ccda4a16c6c4 (patch) | |
tree | e131460f8227136ba2a76b1cc57efb491bd2f548 /networking/udhcp/script.c | |
parent | 64309f8669f08f2c3c16a3b5bf82d9cae84ec388 (diff) | |
download | busybox-b539c8452f823a377bf629cf0e44ccda4a16c6c4.zip busybox-b539c8452f823a377bf629cf0e44ccda4a16c6c4.tar.gz |
dhcp: heed TODO item - divorced options from their string descriptions
code shrink while at it.
function old new delta
dhcp_option_strings - 258 +258
udhcp_run_script 1135 1174 +39
dhcp_option_lengths - 11 +11
udhcp_add_simple_option 93 92 -1
packet_num 4 - -4
read_opt 746 739 -7
udhcp_option_lengths 11 - -11
udhcpc_main 2590 2494 -96
dhcp_options 490 70 -420
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 1/4 up/down: 308/-539) Total: -231 bytes
text data bss dec hex filename
775309 929 9100 785338 bfbba busybox_old
775098 929 9084 785111 bfad7 busybox_unstripped
Diffstat (limited to 'networking/udhcp/script.c')
-rw-r--r-- | networking/udhcp/script.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c index 33d96e6..8a18898 100644 --- a/networking/udhcp/script.c +++ b/networking/udhcp/script.c @@ -33,7 +33,7 @@ static const uint8_t max_option_length[] = { static inline int upper_length(int length, int opt_index) { return max_option_length[opt_index] * - (length / option_lengths[opt_index]); + (length / dhcp_option_lengths[opt_index]); } @@ -57,7 +57,7 @@ static int mton(uint32_t mask) /* Allocate and fill with the text of option 'option'. */ -static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p) +static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p, const char *opt_name) { int len, type, optlen; uint16_t val_u16; @@ -68,10 +68,10 @@ static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p) len = option[OPT_LEN - 2]; type = type_p->flags & TYPE_MASK; - optlen = option_lengths[type]; + optlen = dhcp_option_lengths[type]; - dest = ret = xmalloc(upper_length(len, type) + strlen(type_p->opt_name) + 2); - dest += sprintf(ret, "%s=", type_p->opt_name); + dest = ret = xmalloc(upper_length(len, type) + strlen(opt_name) + 2); + dest += sprintf(ret, "%s=", opt_name); for (;;) { switch (type) { @@ -133,6 +133,7 @@ static char **fill_envp(struct dhcpMessage *packet) int i, j; char **envp; char *var; + const char *opt_name; uint8_t *temp; char over = 0; @@ -171,11 +172,13 @@ static char **fill_envp(struct dhcpMessage *packet) envp[j] = xmalloc(sizeof("ip=255.255.255.255")); sprintip(envp[j++], "ip=", (uint8_t *) &packet->yiaddr); - for (i = 0; dhcp_options[i].code; i++) { + opt_name = dhcp_option_strings; + i = 0; + while (*opt_name) { temp = get_option(packet, dhcp_options[i].code); if (!temp) - continue; - envp[j++] = alloc_fill_opts(temp, &dhcp_options[i]); + goto next; + envp[j++] = alloc_fill_opts(temp, &dhcp_options[i], opt_name); /* Fill in a subnet bits option for things like /24 */ if (dhcp_options[i].code == DHCP_SUBNET) { @@ -183,6 +186,9 @@ static char **fill_envp(struct dhcpMessage *packet) memcpy(&subnet, temp, 4); envp[j++] = xasprintf("mask=%d", mton(subnet)); } + next: + opt_name += strlen(opt_name) + 1; + i++; } if (packet->siaddr) { envp[j] = xmalloc(sizeof("siaddr=255.255.255.255")); |