summaryrefslogtreecommitdiff
path: root/networking/udhcp
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-09-08 03:22:09 +0000
committerRob Landley <rob@landley.net>2005-09-08 03:22:09 +0000
commit230b411de87219f8a59e5d4061d7908cd44ed4d7 (patch)
tree53edbc78f93d74f86d9c76ed0536161aac7d4392 /networking/udhcp
parent658d2cf98616e377fdcf8cde380fec10d966a689 (diff)
downloadbusybox-w32-230b411de87219f8a59e5d4061d7908cd44ed4d7.tar.gz
busybox-w32-230b411de87219f8a59e5d4061d7908cd44ed4d7.tar.bz2
busybox-w32-230b411de87219f8a59e5d4061d7908cd44ed4d7.zip
Fix the warning by rewriting the function to be smaller and simpler.
I'd appreciate somebody on a __BIG_ENDIAN platform testing this out; I haven't got the hardware...
Diffstat (limited to 'networking/udhcp')
-rw-r--r--networking/udhcp/options.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index ae9819413..000f86c79 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -149,37 +149,26 @@ int add_option_string(uint8_t *optionptr, uint8_t *string)
149/* add a one to four byte option to a packet */ 149/* add a one to four byte option to a packet */
150int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data) 150int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
151{ 151{
152 char length = 0; 152 struct dhcp_option *dh;
153 int i; 153
154 uint8_t option[2 + 4]; 154 for (dh=dhcp_options; dh->code; dh++) {
155 uint8_t *u8; 155 if (dh->code == code) {
156 uint16_t *u16; 156 uint8_t option[6], len;
157 uint32_t *u32; 157
158 uint32_t aligned; 158 option[OPT_CODE] = code;
159 u8 = (uint8_t *) &aligned; 159 len = option_lengths[dh->flags & TYPE_MASK];
160 u16 = (uint16_t *) &aligned; 160 option[OPT_LEN] = len;
161 u32 = &aligned; 161 if (__BYTE_ORDER == __BIG_ENDIAN)
162 162 data <<= 8 * (4 - len);
163 for (i = 0; dhcp_options[i].code; i++) 163 /* This memcpy is for broken processors which can't
164 if (dhcp_options[i].code == code) { 164 * handle a simple unaligned 32-bit assignment */
165 length = option_lengths[dhcp_options[i].flags & TYPE_MASK]; 165 memcpy(&option[OPT_DATA], &data, 4);
166 return add_option_string(optionptr, option);
166 } 167 }
167
168 if (!length) {
169 DEBUG(LOG_ERR, "Could not add option 0x%02x", code);
170 return 0;
171 } 168 }
172 169
173 option[OPT_CODE] = code; 170 DEBUG(LOG_ERR, "Could not add option 0x%02x", code);
174 option[OPT_LEN] = length; 171 return 0;
175
176 switch (length) {
177 case 1: *u8 = data; break;
178 case 2: *u16 = data; break;
179 case 4: *u32 = data; break;
180 }
181 memcpy(option + 2, &aligned, length);
182 return add_option_string(optionptr, option);
183} 172}
184 173
185 174