aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/script.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/script.c')
-rw-r--r--networking/udhcp/script.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 68de358e5..33d96e687 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -44,14 +44,15 @@ static int sprintip(char *dest, const char *pre, const uint8_t *ip)
44 44
45 45
46/* really simple implementation, just count the bits */ 46/* really simple implementation, just count the bits */
47static int mton(struct in_addr *mask) 47static int mton(uint32_t mask)
48{ 48{
49 int i; 49 int i = 0;
50 unsigned long bits = ntohl(mask->s_addr); 50 mask = ntohl(mask); /* 111110000-like bit pattern */
51 /* too bad one can't check the carry bit, etc in c bit 51 while (mask) {
52 * shifting */ 52 i++;
53 for (i = 0; i < 32 && !((bits >> i) & 1); i++); 53 mask <<= 1;
54 return 32 - i; 54 }
55 return i;
55} 56}
56 57
57 58
@@ -69,8 +70,8 @@ static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p)
69 type = type_p->flags & TYPE_MASK; 70 type = type_p->flags & TYPE_MASK;
70 optlen = option_lengths[type]; 71 optlen = option_lengths[type];
71 72
72 dest = ret = xmalloc(upper_length(len, type) + strlen(type_p->name) + 2); 73 dest = ret = xmalloc(upper_length(len, type) + strlen(type_p->opt_name) + 2);
73 dest += sprintf(ret, "%s=", type_p->name); 74 dest += sprintf(ret, "%s=", type_p->opt_name);
74 75
75 for (;;) { 76 for (;;) {
76 switch (type) { 77 switch (type) {
@@ -133,7 +134,6 @@ static char **fill_envp(struct dhcpMessage *packet)
133 char **envp; 134 char **envp;
134 char *var; 135 char *var;
135 uint8_t *temp; 136 uint8_t *temp;
136 struct in_addr subnet;
137 char over = 0; 137 char over = 0;
138 138
139 if (packet) { 139 if (packet) {
@@ -179,8 +179,9 @@ static char **fill_envp(struct dhcpMessage *packet)
179 179
180 /* Fill in a subnet bits option for things like /24 */ 180 /* Fill in a subnet bits option for things like /24 */
181 if (dhcp_options[i].code == DHCP_SUBNET) { 181 if (dhcp_options[i].code == DHCP_SUBNET) {
182 uint32_t subnet;
182 memcpy(&subnet, temp, 4); 183 memcpy(&subnet, temp, 4);
183 envp[j++] = xasprintf("mask=%d", mton(&subnet)); 184 envp[j++] = xasprintf("mask=%d", mton(subnet));
184 } 185 }
185 } 186 }
186 if (packet->siaddr) { 187 if (packet->siaddr) {