According to RFC 2131, the minimum size of the 'options' field is 312
bytes, including the 4 byte magic cookie. There also does not seem to
be any restriction regarding the message length, previously the length
was rounded to a multiple of 64 bytes. The latter might have been
because in BOOTP the options field (or rather vendor-specific area as it
was called back then) had a fixed length of 64 bytes (so max(optlen+4, 64)
might actually have been what was intended), but for DHCP the field is
explicitly variable length, so I don't think it's necessary to pad it.
} dhcp_option_t;
/**
- * DHCP message format, with a maximum size options buffer
+ * DHCP message format, with a minimum size options buffer
*/
typedef struct __attribute__((packed)) {
uint8_t opcode;
char server_hostname[64];
char boot_filename[128];
uint32_t magic_cookie;
- u_char options[252];
+ u_char options[308];
} dhcp_t;
/**
{
dst = this->dst;
}
- len = offsetof(dhcp_t, magic_cookie) + ((optlen + 4) / 64 * 64 + 64);
+ len = offsetof(dhcp_t, magic_cookie) + optlen + 4;
return sendto(this->send, dhcp, len, 0, dst->get_sockaddr(dst),
*dst->get_sockaddr_len(dst)) == len;
}