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.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 3029b1367..97c1d30c3 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -37,7 +37,8 @@ static inline int upper_length(int length, int opt_index)
37} 37}
38 38
39 39
40static int sprintip(char *dest, const char *pre, const uint8_t *ip) 40/* note: ip is a pointer to an IP in network order, possibly misaliged */
41static int sprint_nip(char *dest, const char *pre, const uint8_t *ip)
41{ 42{
42 return sprintf(dest, "%s%d.%d.%d.%d", pre, ip[0], ip[1], ip[2], ip[3]); 43 return sprintf(dest, "%s%d.%d.%d.%d", pre, ip[0], ip[1], ip[2], ip[3]);
43} 44}
@@ -76,12 +77,12 @@ static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p,
76 for (;;) { 77 for (;;) {
77 switch (type) { 78 switch (type) {
78 case OPTION_IP_PAIR: 79 case OPTION_IP_PAIR:
79 dest += sprintip(dest, "", option); 80 dest += sprint_nip(dest, "", option);
80 *dest++ = '/'; 81 *dest++ = '/';
81 option += 4; 82 option += 4;
82 optlen = 4; 83 optlen = 4;
83 case OPTION_IP: /* Works regardless of host byte order. */ 84 case OPTION_IP: /* Works regardless of host byte order. */
84 dest += sprintip(dest, "", option); 85 dest += sprint_nip(dest, "", option);
85 break; 86 break;
86 case OPTION_BOOLEAN: 87 case OPTION_BOOLEAN:
87 dest += sprintf(dest, *option ? "yes" : "no"); 88 dest += sprintf(dest, *option ? "yes" : "no");
@@ -145,7 +146,7 @@ static char **fill_envp(struct dhcpMessage *packet)
145 num_options++; /* for mton */ 146 num_options++; /* for mton */
146 } 147 }
147 } 148 }
148 if (packet->siaddr) 149 if (packet->siaddr_nip)
149 num_options++; 150 num_options++;
150 temp = get_option(packet, DHCP_OPTION_OVERLOAD); 151 temp = get_option(packet, DHCP_OPTION_OVERLOAD);
151 if (temp) 152 if (temp)
@@ -164,7 +165,7 @@ static char **fill_envp(struct dhcpMessage *packet)
164 return envp; 165 return envp;
165 166
166 *curr = xmalloc(sizeof("ip=255.255.255.255")); 167 *curr = xmalloc(sizeof("ip=255.255.255.255"));
167 sprintip(*curr, "ip=", (uint8_t *) &packet->yiaddr); 168 sprint_nip(*curr, "ip=", (uint8_t *) &packet->yiaddr);
168 putenv(*curr++); 169 putenv(*curr++);
169 170
170 opt_name = dhcp_option_strings; 171 opt_name = dhcp_option_strings;
@@ -187,9 +188,9 @@ static char **fill_envp(struct dhcpMessage *packet)
187 opt_name += strlen(opt_name) + 1; 188 opt_name += strlen(opt_name) + 1;
188 i++; 189 i++;
189 } 190 }
190 if (packet->siaddr) { 191 if (packet->siaddr_nip) {
191 *curr = xmalloc(sizeof("siaddr=255.255.255.255")); 192 *curr = xmalloc(sizeof("siaddr=255.255.255.255"));
192 sprintip(*curr, "siaddr=", (uint8_t *) &packet->siaddr); 193 sprint_nip(*curr, "siaddr=", (uint8_t *) &packet->siaddr_nip);
193 putenv(*curr++); 194 putenv(*curr++);
194 } 195 }
195 if (!(over & FILE_FIELD) && packet->file[0]) { 196 if (!(over & FILE_FIELD) && packet->file[0]) {