1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Fixed bug triggered by sending DHCP with no options.

This commit is contained in:
Matias Fontanini
2011-08-22 13:08:18 -03:00
parent 88146bac89
commit 7aa6172d8a

View File

@@ -140,18 +140,22 @@ uint32_t Tins::DHCP::header_size() const {
void Tins::DHCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
assert(total_sz >= header_size());
uint8_t *result = new uint8_t[_size], *ptr = result + sizeof(uint32_t);
// Magic cookie
*((uint32_t*)result) = Utils::net_to_host_l(0x63825363);
for(std::list<DHCPOption>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
*(ptr++) = it->option;
*(ptr++) = it->length;
std::memcpy(ptr, it->value, it->length);
ptr += it->length;
uint8_t *result = 0;
if(_size) {
result = new uint8_t[_size];
uint8_t *ptr = result + sizeof(uint32_t);
// Magic cookie
*((uint32_t*)result) = Utils::net_to_host_l(0x63825363);
for(std::list<DHCPOption>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
*(ptr++) = it->option;
*(ptr++) = it->length;
std::memcpy(ptr, it->value, it->length);
ptr += it->length;
}
// End of options
result[_size-1] = END;
vend(result, _size);
}
// End of options
result[_size-1] = END;
vend(result, _size);
BootP::write_serialization(buffer, total_sz, parent);
delete[] result;
}