uint32_t PDU::size() const { uint32_t sz = header_size() + trailer_size(); const PDU *ptr(_inner_pdu); while(ptr) { sz += ptr->header_size() + ptr->trailer_size(); ptr = ptr->inner_pdu(); } return sz; }
void PDU::serialize(uint8_t *buffer, uint32_t total_sz, const PDU *parent) { uint32_t sz = header_size() + trailer_size(); /* Must not happen... */ #ifdef TINS_DEBUG assert(total_sz >= sz); #endif prepare_for_serialize(parent); if(_inner_pdu) _inner_pdu->serialize(buffer + header_size(), total_sz - sz, this); write_serialization(buffer, total_sz, parent); }
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); } }
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); }
blargg_err_t Spc_Emu::track_info_( track_info_t* out, int ) const { get_spc_info( header(), trailer(), trailer_size(), out ); return 0; }