INET Framework for OMNeT++/OMNEST
inet::serializer::ARPSerializer Class Reference

Converts between ARPPacket and binary (network byte order) ARP header. More...

#include <ARPSerializer.h>

Inheritance diagram for inet::serializer::ARPSerializer:
inet::serializer::SerializerBase

Public Member Functions

 ARPSerializer (const char *name=nullptr)
 
int serialize (const ARPPacket *pkt, unsigned char *buf, unsigned int bufsize)
 Serializes an ARPPacket for transmission on the wire. More...
 
ARPPacketparse (const unsigned char *buf, unsigned int bufsize)
 Puts a packet sniffed from the wire into an ARPPacket. More...
 
- Public Member Functions inherited from inet::serializer::SerializerBase
 SerializerBase (const char *name=nullptr)
 
void serializePacket (const cPacket *pkt, Buffer &b, Context &context)
 
cPacket * deserializePacket (const Buffer &b, Context &context)
 

Protected Member Functions

virtual void serialize (const cPacket *pkt, Buffer &b, Context &context) override
 Serializes an ARPPacket for transmission on the wire. More...
 
virtual cPacket * deserialize (const Buffer &b, Context &context) override
 Puts a packet sniffed from the wire into an ARPPacket. More...
 
MACAddress readMACAddress (const Buffer &b, unsigned int size)
 
IPv4Address readIPv4Address (const Buffer &b, unsigned int size)
 

Additional Inherited Members

- Static Public Member Functions inherited from inet::serializer::SerializerBase
static SerializerBaselookupSerializer (const cPacket *pkt, Context &context, ProtocolGroup group, int id)
 
static void lookupAndSerialize (const cPacket *pkt, Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
 
static SerializerBaselookupDeserializer (Context &context, ProtocolGroup group, int id)
 
static cPacket * lookupAndDeserialize (const Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
 

Detailed Description

Converts between ARPPacket and binary (network byte order) ARP header.

Constructor & Destructor Documentation

inet::serializer::ARPSerializer::ARPSerializer ( const char *  name = nullptr)
inline
49 : SerializerBase(name) {}
SerializerBase(const char *name=nullptr)
Definition: SerializerBase.h:84

Member Function Documentation

cPacket * inet::serializer::ARPSerializer::deserialize ( const Buffer b,
Context context 
)
overrideprotectedvirtual

Puts a packet sniffed from the wire into an ARPPacket.

Implements inet::serializer::SerializerBase.

79 {
80  ARPPacket *pkt = new ARPPacket("parsed ARP");
81 
82  uint16_t x;
83  x = b.readUint16(); // 1
84  if (x != 1)
85  pkt->setBitError(true);
86  x = b.readUint16(); // ETHERTYPE_IP
87  if (x != ETHERTYPE_IPv4)
88  pkt->setBitError(true);
89  uint8_t n = b.readByte(); //ar_hln
90  uint8_t m = b.readByte(); //ar_pln
91  pkt->setOpcode(b.readUint16()); // arphdr->ar_op
92  MACAddress temp;
93  pkt->setSrcMACAddress(readMACAddress(b, n));
94  pkt->setSrcIPAddress(readIPv4Address(b, m)); // ar_spa
95  pkt->setDestMACAddress(readMACAddress(b, n));
96  pkt->setDestIPAddress(readIPv4Address(b, m)); // ar_tpa
97  pkt->setByteLength(b.getPos());
98  return pkt;
99 }
IPv4Address readIPv4Address(const Buffer &b, unsigned int size)
Definition: ARPSerializer.cc:54
MACAddress readMACAddress(const Buffer &b, unsigned int size)
Definition: ARPSerializer.cc:46
Definition: Ieee802Ctrl_m.h:115
value< double, units::m > b
Definition: Units.h:1054
value< double, units::m > m
Definition: Units.h:1047
ARPPacket* inet::serializer::ARPSerializer::parse ( const unsigned char *  buf,
unsigned int  bufsize 
)
inline

Puts a packet sniffed from the wire into an ARPPacket.

63  { Buffer b(const_cast<unsigned char *>(buf), bufsize); Context c; return check_and_cast<ARPPacket *>(deserialize(b, c)); }
virtual cPacket * deserialize(const Buffer &b, Context &context) override
Puts a packet sniffed from the wire into an ARPPacket.
Definition: ARPSerializer.cc:78
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
value< double, units::m > b
Definition: Units.h:1054
IPv4Address inet::serializer::ARPSerializer::readIPv4Address ( const Buffer b,
unsigned int  size 
)
protected

Referenced by deserialize().

55 {
56  unsigned int curpos = b.getPos();
57  IPv4Address addr = b.readIPv4Address();
58  b.seek(curpos + size);
59  return addr;
60 }
value< double, units::m > b
Definition: Units.h:1054
MACAddress inet::serializer::ARPSerializer::readMACAddress ( const Buffer b,
unsigned int  size 
)
protected

Referenced by deserialize().

47 {
48  unsigned int curpos = b.getPos();
49  MACAddress addr = b.readMACAddress();
50  b.seek(curpos + size);
51  return addr;
52 }
value< double, units::m > b
Definition: Units.h:1054
void inet::serializer::ARPSerializer::serialize ( const cPacket *  pkt,
Buffer b,
Context context 
)
overrideprotectedvirtual

Serializes an ARPPacket for transmission on the wire.

Returns the length of data written into buffer.

Implements inet::serializer::SerializerBase.

63 {
64  const ARPPacket *pkt = check_and_cast<const ARPPacket *>(_pkt);
65  b.writeUint16(1); //ethernet
66  b.writeUint16(ETHERTYPE_IPv4);
67  b.writeByte(ETHER_ADDR_LEN);
68  b.writeByte(4); // size of IPv4 address
69  b.writeUint16(pkt->getOpcode());
70  b.writeMACAddress(pkt->getSrcMACAddress());
71  b.writeIPv4Address(pkt->getSrcIPAddress());
72  b.writeMACAddress(pkt->getDestMACAddress());
73  b.writeIPv4Address(pkt->getDestIPAddress());
74  if (pkt->getEncapsulatedPacket())
75  throw cRuntimeError("ARPSerializer: encapsulated packet not supported!");
76 }
#define ETHER_ADDR_LEN
Definition: ethernethdr.h:26
Definition: Ieee802Ctrl_m.h:115
value< double, units::m > b
Definition: Units.h:1054
int inet::serializer::ARPSerializer::serialize ( const ARPPacket pkt,
unsigned char *  buf,
unsigned int  bufsize 
)
inline

Serializes an ARPPacket for transmission on the wire.

Returns the length of data written into buffer.

57  { Buffer b(buf, bufsize); Context c; serialize(pkt, b, c); return b.getPos(); }
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
virtual void serialize(const cPacket *pkt, Buffer &b, Context &context) override
Serializes an ARPPacket for transmission on the wire.
Definition: ARPSerializer.cc:62
value< double, units::m > b
Definition: Units.h:1054

The documentation for this class was generated from the following files: