10 #include <arpa/inet.h> 24 return reinterpret_cast<void *
>(
25 reinterpret_cast<uint8_t *
>(
this) +
sizeof(
struct Ethernet));
28 static std::string
addrToStr(std::array<uint8_t, 6> addr) {
29 std::stringstream str;
30 str << std::hex << static_cast<int>(addr[0]) <<
":" << std::hex
31 << static_cast<int>(addr[1]) <<
":" << std::hex << static_cast<int>(addr[2])
32 <<
":" << std::hex << static_cast<int>(addr[3]) <<
":" << std::hex
33 <<
static_cast<int>(addr[4]) <<
":" << std::hex << static_cast<int>(addr[5]);
52 void setEthertype(uint16_t type) { this->ethertype = htons(type); }
55 memcpy(this->srcMac.data(), addr.data(), 6);
59 memcpy(this->destMac.data(), addr.data(), 6);
62 } __attribute__((packed));
150 return reinterpret_cast<void *
>(
reinterpret_cast<uint8_t *
>(
this) + 4 *
ihl());
154 std::stringstream str;
155 str << (addr >> 24) <<
"." << ((addr >> 16) & 0xff) <<
"." << ((addr >> 8) & 0xff)
156 <<
"." << (addr & 0xff);
164 void setLength(uint16_t len) { this->total_length = htons(len); }
166 uint16_t
getLength() {
return ntohs(this->total_length); }
171 uint16_t *hdr_cast =
reinterpret_cast<uint16_t *
>(
this);
174 for (uint8_t i = 0; i < (this->
ihl() * 4); i++) {
175 result += ntohs(hdr_cast[i]);
176 if (result & (1 << 16)) {
182 this->checksum = htons(~result);
185 } __attribute__((packed));
202 return reinterpret_cast<void *
>(
203 reinterpret_cast<uint8_t *
>(
this) +
sizeof(
struct Tcp));
206 } __attribute__((packed));
249 return reinterpret_cast<void *
>(
250 reinterpret_cast<uint8_t *
>(
this) +
sizeof(
struct Udp));
253 } __attribute__((packed));
260 } __attribute__((packed));