mirror of
https://github.com/mfontanini/libtins
synced 2026-01-27 12:14:26 +01:00
Added DHCP and BootP constructors from uint8_t buffer. Normalized IP destination and source address getters/setters.
This commit is contained in:
21
src/dhcp.cpp
21
src/dhcp.cpp
@@ -19,6 +19,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
#include "utils.h"
|
||||
@@ -36,6 +37,26 @@ Tins::DHCP::DHCP() : _size(sizeof(uint32_t) + 1) {
|
||||
hlen(6);
|
||||
}
|
||||
|
||||
Tins::DHCP::DHCP(const uint8_t *buffer, uint32_t total_sz) : BootP(buffer, total_sz, 0) {
|
||||
buffer += BootP::header_size();
|
||||
total_sz -= BootP::header_size();
|
||||
uint8_t args[2];
|
||||
while(total_sz) {
|
||||
for(unsigned i(0); i < 2; ++i) {
|
||||
args[i] = *(buffer++);
|
||||
total_sz--;
|
||||
if(!total_sz)
|
||||
throw std::runtime_error("Not enought size for a DHCP header in the buffer.");
|
||||
}
|
||||
// Not enough size for this option
|
||||
if(total_sz < args[1])
|
||||
throw std::runtime_error("Not enought size for a DHCP header in the buffer.");
|
||||
add_option((Options)args[0], args[1], buffer);
|
||||
buffer += args[1];
|
||||
total_sz -= args[1];
|
||||
}
|
||||
}
|
||||
|
||||
Tins::DHCP::~DHCP() {
|
||||
while(_options.size()) {
|
||||
delete[] _options.front().value;
|
||||
|
||||
Reference in New Issue
Block a user