void Callback::call( const dht::message::Message& m, dht::Node& node) const { _callback( payload_type(m,node),*this); }
void Dot1Q::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) { uint32_t trailer = trailer_size(); #ifdef TINS_DEBUG assert(total_sz >= sizeof(_header) + trailer); #endif if ((payload_type() == 0) && inner_pdu()) { Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type( inner_pdu()->pdu_type() ); payload_type(static_cast<uint16_t>(flag)); } std::memcpy(buffer, &_header, sizeof(_header)); buffer += sizeof(_header); if(inner_pdu()) buffer += inner_pdu()->size(); std::fill(buffer, buffer + trailer, 0); }
EthernetII::EthernetII(const uint8_t *buffer, uint32_t total_sz) { if(total_sz < sizeof(ethhdr)) throw malformed_packet(); memcpy(&_eth, buffer, sizeof(ethhdr)); buffer += sizeof(ethhdr); total_sz -= sizeof(ethhdr); if(total_sz) { inner_pdu( Internals::pdu_from_flag( (Constants::Ethernet::e)payload_type(), buffer, total_sz ) ); } }
void EthernetII::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) { #ifdef TINS_DEBUG assert(total_sz >= header_size() + trailer_size()); #endif /* Inner type defaults to IP */ if (inner_pdu()) { Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type( inner_pdu()->pdu_type() ); payload_type(static_cast<uint16_t>(flag)); } memcpy(buffer, &_eth, sizeof(ethhdr)); uint32_t trailer = trailer_size(); if (trailer) { uint32_t trailer_offset = header_size(); if (inner_pdu()) trailer_offset += inner_pdu()->size(); memset(buffer + trailer_offset, 0, trailer); } }