PcapPlusPlus  20.08
IgmpLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_IGMP_LAYER
2 #define PACKETPP_IGMP_LAYER
3 
4 #include "Layer.h"
5 #include "IpAddress.h"
6 #include <vector>
7 
9 
14 namespace pcpp
15 {
16 
22 {
24  uint8_t type;
26  uint8_t maxResponseTime;
28  uint16_t checksum;
30  uint32_t groupAddress;
31 };
32 
33 
39 {
41  uint8_t type;
43  uint8_t maxResponseTime;
45  uint16_t checksum;
47  uint32_t groupAddress;
49  uint8_t s_qrv;
51  uint8_t qqic;
53  uint16_t numOfSources;
54 };
55 
56 
62 {
64  uint8_t type;
66  uint8_t reserved1;
68  uint16_t checksum;
70  uint16_t reserved2;
73 };
74 
75 
82 {
84  uint8_t recordType;
86  uint8_t auxDataLen;
88  uint16_t numOfSources;
90  uint32_t multicastAddress;
92  uint8_t sourceAddresses[];
93 
98 
102  uint16_t getSourceAddressCount() const;
103 
110  IPv4Address getSourceAddressAtIndex(int index) const;
111 
115  size_t getRecordLen() const;
116 };
117 
118 
123 {
152 };
153 
154 
161 class IgmpLayer : public Layer
162 {
163 protected:
164 
165  IgmpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ProtocolType igmpVer) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = igmpVer; }
166 
167  IgmpLayer(IgmpType type, const IPv4Address& groupAddr, uint8_t maxResponseTime, ProtocolType igmpVer);
168 
169  uint16_t calculateChecksum();
170 
171  size_t getHeaderSizeByVerAndType(ProtocolType igmpVer, IgmpType igmpType) const;
172 public:
173 
174  virtual ~IgmpLayer() {}
175 
180  igmp_header* getIgmpHeader() const { return (igmp_header*)m_Data; }
181 
186 
191  void setGroupAddress(const IPv4Address& groupAddr);
192 
197  IgmpType getType() const;
198 
203  void setType(IgmpType type);
204 
213  static ProtocolType getIGMPVerFromData(uint8_t* data, size_t dataLen, bool& isQuery);
214 
215 
216  // implement abstract methods
217 
221  void parseNextLayer() {}
222 
226  size_t getHeaderLen() const { return sizeof(igmp_header); }
227 
228  std::string toString() const;
229 
231 };
232 
233 
238 class IgmpV1Layer : public IgmpLayer
239 {
240 public:
247  IgmpV1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
248  : IgmpLayer(data, dataLen, prevLayer, packet, IGMPv1) {}
249 
256  IgmpV1Layer(IgmpType type, const IPv4Address& groupAddr = IPv4Address())
257  : IgmpLayer(type, groupAddr, 0, IGMPv1) {}
258 
263 
264 
265  // implement abstract methods
266 
270  void computeCalculateFields();
271 
272 };
273 
274 
279 class IgmpV2Layer : public IgmpLayer
280 {
281 public:
288  IgmpV2Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
289  : IgmpLayer(data, dataLen, prevLayer, packet, IGMPv2) {}
290 
297  IgmpV2Layer(IgmpType type, const IPv4Address& groupAddr = IPv4Address(), uint8_t maxResponseTime = 0)
298  : IgmpLayer(type, groupAddr, maxResponseTime, IGMPv2) {}
299 
304 
305 
306  // implement abstract methods
307 
311  void computeCalculateFields();
312 };
313 
314 
320 {
321 public:
322 
329  IgmpV3QueryLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
330 
339  IgmpV3QueryLayer(const IPv4Address& multicastAddr = IPv4Address(), uint8_t maxResponseTime = 0, uint8_t s_qrv = 0);
340 
347 
351  uint16_t getSourceAddressCount() const;
352 
358  IPv4Address getSourceAddressAtIndex(int index) const;
359 
366  bool addSourceAddress(const IPv4Address& addr);
367 
375  bool addSourceAddressAtIndex(const IPv4Address& addr, int index);
376 
383  bool removeSourceAddressAtIndex(int index);
384 
391 
392  // implement abstract methods
393 
397  void computeCalculateFields();
398 
402  size_t getHeaderLen() const;
403 };
404 
405 
411 {
412 private:
413  igmpv3_group_record* addGroupRecordAt(uint8_t recordType, const IPv4Address& multicastAddress, const std::vector<IPv4Address>& sourceAddresses, int offset);
414 
415 public:
416 
423  IgmpV3ReportLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
424  : IgmpLayer(data, dataLen, prevLayer, packet, IGMPv3) {}
425 
430 
437 
441  uint16_t getGroupRecordCount() const;
442 
448 
458 
469  igmpv3_group_record* addGroupRecord(uint8_t recordType, const IPv4Address& multicastAddress, const std::vector<IPv4Address>& sourceAddresses);
470 
482  igmpv3_group_record* addGroupRecordAtIndex(uint8_t recordType, const IPv4Address& multicastAddress, const std::vector<IPv4Address>& sourceAddresses, int index);
483 
490  bool removeGroupRecordAtIndex(int index);
491 
497  bool removeAllGroupRecords();
498 
499  // implement abstract methods
500 
504  void computeCalculateFields();
505 
509  size_t getHeaderLen() const { return m_DataLen; }
510 };
511 
512 }
513 
514 #endif // PACKETPP_IGMP_LAYER
pcpp::igmpv3_query_header::checksum
uint16_t checksum
Definition: IgmpLayer.h:45
pcpp::IGMPv2
const ProtocolType IGMPv2
Definition: ProtocolType.h:163
pcpp::OsiModelLayer
OsiModelLayer
Definition: ProtocolType.h:233
pcpp::IPv4Address
Definition: IpAddress.h:26
pcpp::igmpv3_report_header::reserved2
uint16_t reserved2
Definition: IgmpLayer.h:70
pcpp::IgmpV3ReportLayer::IgmpV3ReportLayer
IgmpV3ReportLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IgmpLayer.h:423
pcpp::Packet
Definition: Packet.h:26
pcpp::IgmpV3QueryLayer
Definition: IgmpLayer.h:319
pcpp::IgmpV2Layer
Definition: IgmpLayer.h:279
pcpp::IgmpV3ReportLayer::getReportHeader
igmpv3_report_header * getReportHeader() const
Definition: IgmpLayer.h:436
pcpp::igmpv3_group_record::getSourceAddressCount
uint16_t getSourceAddressCount() const
pcpp::IgmpV1Layer::~IgmpV1Layer
~IgmpV1Layer()
Definition: IgmpLayer.h:262
Layer.h
pcpp::IgmpV3ReportLayer::computeCalculateFields
void computeCalculateFields()
pcpp::IgmpLayer
Definition: IgmpLayer.h:161
pcpp::IgmpType_MulticastRouterSolicitation
@ IgmpType_MulticastRouterSolicitation
Definition: IgmpLayer.h:149
pcpp::igmpv3_group_record::numOfSources
uint16_t numOfSources
Definition: IgmpLayer.h:88
pcpp::IgmpLayer::getType
IgmpType getType() const
pcpp::IgmpV3ReportLayer::removeGroupRecordAtIndex
bool removeGroupRecordAtIndex(int index)
pcpp::igmpv3_group_record::auxDataLen
uint8_t auxDataLen
Definition: IgmpLayer.h:86
pcpp::IgmpLayer::getHeaderLen
size_t getHeaderLen() const
Definition: IgmpLayer.h:226
pcpp::IgmpV3ReportLayer
Definition: IgmpLayer.h:410
pcpp::IgmpV3ReportLayer::addGroupRecordAtIndex
igmpv3_group_record * addGroupRecordAtIndex(uint8_t recordType, const IPv4Address &multicastAddress, const std::vector< IPv4Address > &sourceAddresses, int index)
pcpp::igmpv3_report_header::checksum
uint16_t checksum
Definition: IgmpLayer.h:68
pcpp::IgmpType_LeaveGroup
@ IgmpType_LeaveGroup
Definition: IgmpLayer.h:139
pcpp::IgmpV2Layer::IgmpV2Layer
IgmpV2Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IgmpLayer.h:288
pcpp::IgmpV3QueryLayer::removeSourceAddressAtIndex
bool removeSourceAddressAtIndex(int index)
pcpp::igmpv3_group_record::getMulticastAddress
IPv4Address getMulticastAddress() const
Definition: IgmpLayer.h:97
pcpp::igmpv3_report_header::numOfGroupRecords
uint16_t numOfGroupRecords
Definition: IgmpLayer.h:72
pcpp::IgmpV3ReportLayer::getNextGroupRecord
igmpv3_group_record * getNextGroupRecord(igmpv3_group_record *groupRecord) const
pcpp::IgmpV3QueryLayer::addSourceAddress
bool addSourceAddress(const IPv4Address &addr)
pcpp::IgmpType_MulticastRouterTermination
@ IgmpType_MulticastRouterTermination
Definition: IgmpLayer.h:151
pcpp::igmpv3_group_record::getRecordLen
size_t getRecordLen() const
pcpp::IgmpType_MulticastTraceroute
@ IgmpType_MulticastTraceroute
Definition: IgmpLayer.h:143
pcpp::OsiModelNetworkLayer
@ OsiModelNetworkLayer
Definition: ProtocolType.h:240
pcpp::igmp_header
Definition: IgmpLayer.h:21
pcpp::IgmpType_DVMRP
@ IgmpType_DVMRP
Definition: IgmpLayer.h:131
pcpp::IgmpType_Unknown
@ IgmpType_Unknown
Definition: IgmpLayer.h:125
pcpp::IgmpV3QueryLayer::computeCalculateFields
void computeCalculateFields()
pcpp::igmpv3_group_record::sourceAddresses
uint8_t sourceAddresses[]
Definition: IgmpLayer.h:92
pcpp::igmpv3_group_record
Definition: IgmpLayer.h:81
pcpp::igmpv3_group_record::multicastAddress
uint32_t multicastAddress
Definition: IgmpLayer.h:90
pcpp::IgmpV2Layer::IgmpV2Layer
IgmpV2Layer(IgmpType type, const IPv4Address &groupAddr=IPv4Address(), uint8_t maxResponseTime=0)
Definition: IgmpLayer.h:297
pcpp::IgmpV3ReportLayer::IgmpV3ReportLayer
IgmpV3ReportLayer()
Definition: IgmpLayer.h:429
pcpp::ProtocolType
uint64_t ProtocolType
Definition: ProtocolType.h:18
pcpp::IgmpType_MembershipQuery
@ IgmpType_MembershipQuery
Definition: IgmpLayer.h:127
pcpp::IgmpV3ReportLayer::removeAllGroupRecords
bool removeAllGroupRecords()
pcpp::IgmpV3ReportLayer::addGroupRecord
igmpv3_group_record * addGroupRecord(uint8_t recordType, const IPv4Address &multicastAddress, const std::vector< IPv4Address > &sourceAddresses)
pcpp::IgmpType_MembershipReportV2
@ IgmpType_MembershipReportV2
Definition: IgmpLayer.h:137
pcpp::igmpv3_query_header
Definition: IgmpLayer.h:38
pcpp::igmpv3_query_header::maxResponseTime
uint8_t maxResponseTime
Definition: IgmpLayer.h:43
pcpp::igmpv3_query_header::groupAddress
uint32_t groupAddress
Definition: IgmpLayer.h:47
pcpp::IgmpV3QueryLayer::getSourceAddressCount
uint16_t getSourceAddressCount() const
pcpp::IgmpV3QueryLayer::getIgmpV3QueryHeader
igmpv3_query_header * getIgmpV3QueryHeader() const
Definition: IgmpLayer.h:346
pcpp::IgmpType_CiscoTrace
@ IgmpType_CiscoTrace
Definition: IgmpLayer.h:135
pcpp::IgmpType_P1Mv1
@ IgmpType_P1Mv1
Definition: IgmpLayer.h:133
pcpp::IgmpV3QueryLayer::getHeaderLen
size_t getHeaderLen() const
pcpp::igmpv3_query_header::s_qrv
uint8_t s_qrv
Definition: IgmpLayer.h:49
pcpp::IgmpType
IgmpType
Definition: IgmpLayer.h:122
pcpp::IgmpLayer::getOsiModelLayer
OsiModelLayer getOsiModelLayer() const
Definition: IgmpLayer.h:230
pcpp::IgmpType_MembershipReportV3
@ IgmpType_MembershipReportV3
Definition: IgmpLayer.h:145
pcpp::IgmpLayer::getGroupAddress
IPv4Address getGroupAddress() const
Definition: IgmpLayer.h:185
pcpp::igmpv3_query_header::qqic
uint8_t qqic
Definition: IgmpLayer.h:51
pcpp::IgmpV3ReportLayer::getFirstGroupRecord
igmpv3_group_record * getFirstGroupRecord() const
pcpp::igmpv3_report_header::reserved1
uint8_t reserved1
Definition: IgmpLayer.h:66
IpAddress.h
pcpp::igmpv3_group_record::getSourceAddressAtIndex
IPv4Address getSourceAddressAtIndex(int index) const
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::IgmpType_MulticastTracerouteResponse
@ IgmpType_MulticastTracerouteResponse
Definition: IgmpLayer.h:141
pcpp::IgmpLayer::parseNextLayer
void parseNextLayer()
Definition: IgmpLayer.h:221
pcpp::IGMPv1
const ProtocolType IGMPv1
Definition: ProtocolType.h:158
pcpp::IGMPv3
const ProtocolType IGMPv3
Definition: ProtocolType.h:168
pcpp::igmpv3_query_header::numOfSources
uint16_t numOfSources
Definition: IgmpLayer.h:53
pcpp::IgmpV3QueryLayer::IgmpV3QueryLayer
IgmpV3QueryLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
pcpp::Layer
Definition: Layer.h:70
pcpp::IgmpV1Layer::IgmpV1Layer
IgmpV1Layer(IgmpType type, const IPv4Address &groupAddr=IPv4Address())
Definition: IgmpLayer.h:256
pcpp::IgmpV1Layer::computeCalculateFields
void computeCalculateFields()
pcpp::IgmpType_MembershipReportV1
@ IgmpType_MembershipReportV1
Definition: IgmpLayer.h:129
pcpp::igmp_header::groupAddress
uint32_t groupAddress
Definition: IgmpLayer.h:30
pcpp::igmpv3_query_header::type
uint8_t type
Definition: IgmpLayer.h:41
pcpp::IgmpLayer::setType
void setType(IgmpType type)
pcpp::IgmpLayer::getIGMPVerFromData
static ProtocolType getIGMPVerFromData(uint8_t *data, size_t dataLen, bool &isQuery)
pcpp::IgmpV3QueryLayer::getSourceAddressAtIndex
IPv4Address getSourceAddressAtIndex(int index) const
pcpp::igmpv3_group_record::recordType
uint8_t recordType
Definition: IgmpLayer.h:84
pcpp::IgmpLayer::toString
std::string toString() const
pcpp::IgmpV3QueryLayer::addSourceAddressAtIndex
bool addSourceAddressAtIndex(const IPv4Address &addr, int index)
pcpp::IgmpV1Layer
Definition: IgmpLayer.h:238
pcpp::igmp_header::maxResponseTime
uint8_t maxResponseTime
Definition: IgmpLayer.h:26
pcpp::IgmpV3ReportLayer::getGroupRecordCount
uint16_t getGroupRecordCount() const
pcpp::IgmpLayer::setGroupAddress
void setGroupAddress(const IPv4Address &groupAddr)
pcpp::IgmpV1Layer::IgmpV1Layer
IgmpV1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IgmpLayer.h:247
pcpp::IgmpV3ReportLayer::getHeaderLen
size_t getHeaderLen() const
Definition: IgmpLayer.h:509
pcpp::IgmpV2Layer::~IgmpV2Layer
~IgmpV2Layer()
Definition: IgmpLayer.h:303
pcpp::IgmpLayer::getIgmpHeader
igmp_header * getIgmpHeader() const
Definition: IgmpLayer.h:180
pcpp::IgmpV3QueryLayer::removeAllSourceAddresses
bool removeAllSourceAddresses()
pcpp::IgmpType_MulticastRouterAdvertisement
@ IgmpType_MulticastRouterAdvertisement
Definition: IgmpLayer.h:147
pcpp::igmpv3_report_header
Definition: IgmpLayer.h:61
pcpp::igmp_header::checksum
uint16_t checksum
Definition: IgmpLayer.h:28
pcpp::igmpv3_report_header::type
uint8_t type
Definition: IgmpLayer.h:64
pcpp::igmp_header::type
uint8_t type
Definition: IgmpLayer.h:24
pcpp::IgmpV2Layer::computeCalculateFields
void computeCalculateFields()