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...
This commit is contained in:
parent
658d2cf986
commit
230b411de8
@ -149,37 +149,26 @@ int add_option_string(uint8_t *optionptr, uint8_t *string)
|
|||||||
/* add a one to four byte option to a packet */
|
/* add a one to four byte option to a packet */
|
||||||
int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
|
int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
|
||||||
{
|
{
|
||||||
char length = 0;
|
struct dhcp_option *dh;
|
||||||
int i;
|
|
||||||
uint8_t option[2 + 4];
|
|
||||||
uint8_t *u8;
|
|
||||||
uint16_t *u16;
|
|
||||||
uint32_t *u32;
|
|
||||||
uint32_t aligned;
|
|
||||||
u8 = (uint8_t *) &aligned;
|
|
||||||
u16 = (uint16_t *) &aligned;
|
|
||||||
u32 = &aligned;
|
|
||||||
|
|
||||||
for (i = 0; dhcp_options[i].code; i++)
|
for (dh=dhcp_options; dh->code; dh++) {
|
||||||
if (dhcp_options[i].code == code) {
|
if (dh->code == code) {
|
||||||
length = option_lengths[dhcp_options[i].flags & TYPE_MASK];
|
uint8_t option[6], len;
|
||||||
|
|
||||||
|
option[OPT_CODE] = code;
|
||||||
|
len = option_lengths[dh->flags & TYPE_MASK];
|
||||||
|
option[OPT_LEN] = len;
|
||||||
|
if (__BYTE_ORDER == __BIG_ENDIAN)
|
||||||
|
data <<= 8 * (4 - len);
|
||||||
|
/* This memcpy is for broken processors which can't
|
||||||
|
* handle a simple unaligned 32-bit assignment */
|
||||||
|
memcpy(&option[OPT_DATA], &data, 4);
|
||||||
|
return add_option_string(optionptr, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!length) {
|
|
||||||
DEBUG(LOG_ERR, "Could not add option 0x%02x", code);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
option[OPT_CODE] = code;
|
DEBUG(LOG_ERR, "Could not add option 0x%02x", code);
|
||||||
option[OPT_LEN] = length;
|
return 0;
|
||||||
|
|
||||||
switch (length) {
|
|
||||||
case 1: *u8 = data; break;
|
|
||||||
case 2: *u16 = data; break;
|
|
||||||
case 4: *u32 = data; break;
|
|
||||||
}
|
|
||||||
memcpy(option + 2, &aligned, length);
|
|
||||||
return add_option_string(optionptr, option);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user