Serializes a cPacket for transmission on the wire.
Returns the length of data written into buffer.
41 unsigned int startpos =
b.getPos();
42 const ICMPMessage *pkt = check_and_cast<
const ICMPMessage *>(_pkt);
44 switch (pkt->getType()) {
46 PingPayload *pp = check_and_cast<PingPayload *>(pkt->getEncapsulatedPacket());
48 b.writeByte(pkt->getCode());
50 b.writeUint16(pp->getOriginatorId());
51 b.writeUint16(pp->getSeqNo());
52 unsigned int datalen = pp->getDataArraySize();
53 for (
unsigned int i = 0; i < datalen; i++)
54 b.writeByte(pp->getData(i));
55 datalen = (pp->getByteLength() - 4) - datalen;
56 b.fillNBytes(datalen,
'a');
61 PingPayload *pp = check_and_cast<PingPayload *>(pkt->getEncapsulatedPacket());
63 b.writeByte(pkt->getCode());
65 b.writeUint16(pp->getOriginatorId());
66 b.writeUint16(pp->getSeqNo());
67 unsigned int datalen = pp->getDataArraySize();
68 for (
unsigned int i = 0; i < datalen; i++)
69 b.writeByte(pp->getData(i));
70 datalen = (pp->getByteLength() - 4) - datalen;
71 b.fillNBytes(datalen,
'a');
77 b.writeByte(pkt->getCode());
81 Buffer
s(
b,
b.getRemainingSize());
92 Buffer
s(
b,
b.getRemainingSize());
100 throw cRuntimeError(
"Can not serialize ICMP packet: type %d not supported.", pkt->getType());
Definition: ICMPMessage_m.h:69
Definition: ICMPMessage_m.h:66
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SCTPAssociation.h:270
Definition: SerializerBase.h:39
static uint16_t checksum(const void *addr, unsigned int count)
Definition: TCPIPchecksum.h:44
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
Definition: ICMPMessage_m.h:115
Definition: ICMPMessage_m.h:74
static void lookupAndSerialize(const cPacket *pkt, Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
Definition: SerializerBase.cc:88
Definition: ICMPMessage_m.h:72
value< double, units::s > s
Definition: Units.h:1049
Definition: Ieee802Ctrl_m.h:115
#define ICMP_MINLEN
Definition: ip_icmp.h:135
value< double, units::m > b
Definition: Units.h:1054