PcapPlusPlus  19.12
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 getSourceAdressCount() const;
103 
110  IPv4Address getSoruceAddressAtIndex(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, NULL, 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 
185  IPv4Address getGroupAddress() const { return IPv4Address(getIgmpHeader()->groupAddress); }
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 
255  IgmpV1Layer(IgmpType type, const IPv4Address& groupAddr = IPv4Address::Zero);
256 
261 
262 
263  // implement abstract methods
264 
268  void computeCalculateFields();
269 
270 };
271 
272 
277 class IgmpV2Layer : public IgmpLayer
278 {
279 public:
286  IgmpV2Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
287 
294  IgmpV2Layer(IgmpType type, const IPv4Address& groupAddr = IPv4Address::Zero, uint8_t maxResponseTime = 0);
295 
300 
301 
302  // implement abstract methods
303 
307  void computeCalculateFields();
308 };
309 
310 
316 {
317 public:
318 
325  IgmpV3QueryLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
326 
335  IgmpV3QueryLayer(const IPv4Address& multicastAddr = IPv4Address::Zero, uint8_t maxResponseTime = 0, uint8_t s_qrv = 0);
336 
343 
347  uint16_t getSourceAddressCount() const;
348 
354  IPv4Address getSourceAddressAtIndex(int index) const;
355 
362  bool addSourceAddress(const IPv4Address& addr);
363 
371  bool addSourceAddressAtIndex(const IPv4Address& addr, int index);
372 
379  bool removeSourceAddressAtIndex(int index);
380 
387 
388  // implement abstract methods
389 
393  void computeCalculateFields();
394 
398  size_t getHeaderLen() const;
399 };
400 
401 
407 {
408 private:
409  igmpv3_group_record* addGroupRecordAt(uint8_t recordType, const IPv4Address& multicastAddress, const std::vector<IPv4Address>& sourceAddresses, int offset);
410 
411 public:
412 
419  IgmpV3ReportLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
420 
425 
432 
436  uint16_t getGroupRecordCount() const;
437 
443 
453 
464  igmpv3_group_record* addGroupRecord(uint8_t recordType, const IPv4Address& multicastAddress, const std::vector<IPv4Address>& sourceAddresses);
465 
477  igmpv3_group_record* addGroupRecordAtIndex(uint8_t recordType, const IPv4Address& multicastAddress, const std::vector<IPv4Address>& sourceAddresses, int index);
478 
485  bool removeGroupRecordAtIndex(int index);
486 
492  bool removeAllGroupRecords();
493 
494  // implement abstract methods
495 
499  void computeCalculateFields();
500 
504  size_t getHeaderLen() const { return m_DataLen; }
505 };
506 
507 }
508 
509 #endif // PACKETPP_IGMP_LAYER
pcpp::igmpv3_query_header::checksum
uint16_t checksum
Definition: IgmpLayer.h:45
pcpp::OsiModelLayer
OsiModelLayer
Definition: ProtocolType.h:224
pcpp::IPv4Address
Definition: IpAddress.h:119
pcpp::igmpv3_report_header::reserved2
uint16_t reserved2
Definition: IgmpLayer.h:70
pcpp::Packet
Definition: Packet.h:26
pcpp::IgmpV3QueryLayer
Definition: IgmpLayer.h:315
pcpp::IgmpV2Layer
Definition: IgmpLayer.h:277
pcpp::IgmpV3ReportLayer::getReportHeader
igmpv3_report_header * getReportHeader() const
Definition: IgmpLayer.h:431
pcpp::IgmpV1Layer::~IgmpV1Layer
~IgmpV1Layer()
Definition: IgmpLayer.h:260
Layer.h
pcpp::IgmpV3ReportLayer::computeCalculateFields
void computeCalculateFields()
pcpp::IgmpLayer
Definition: IgmpLayer.h:161
pcpp::IPv4Address::Zero
static IPv4Address Zero
Definition: IpAddress.h:220
pcpp::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::igmpv3_group_record::getSourceAdressCount
uint16_t getSourceAdressCount() 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:406
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
Definition: IgmpLayer.h:139
pcpp::IgmpV2Layer::IgmpV2Layer
IgmpV2Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
pcpp::IgmpV3QueryLayer::removeSourceAddressAtIndex
bool removeSourceAddressAtIndex(int index)
pcpp::igmpv3_group_record::getMulticastAddress
IPv4Address getMulticastAddress() const
pcpp::igmpv3_group_record::getSoruceAddressAtIndex
IPv4Address getSoruceAddressAtIndex(int index) const
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
Definition: IgmpLayer.h:151
pcpp::igmpv3_group_record::getRecordLen
size_t getRecordLen() const
pcpp::IgmpType_MulticastTraceroute
Definition: IgmpLayer.h:143
pcpp::OsiModelNetworkLayer
Definition: ProtocolType.h:231
pcpp::igmp_header
Definition: IgmpLayer.h:21
pcpp::IgmpType_DVMRP
Definition: IgmpLayer.h:131
pcpp::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::IgmpV3ReportLayer::IgmpV3ReportLayer
IgmpV3ReportLayer()
pcpp::ProtocolType
ProtocolType
Definition: ProtocolType.h:16
pcpp::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
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:342
pcpp::IgmpType_CiscoTrace
Definition: IgmpLayer.h:135
pcpp::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
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
The main namespace for the PcapPlusPlus lib.
pcpp::IgmpType_MulticastTracerouteResponse
Definition: IgmpLayer.h:141
pcpp::IgmpLayer::parseNextLayer
void parseNextLayer()
Definition: IgmpLayer.h:221
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::computeCalculateFields
void computeCalculateFields()
pcpp::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)
pcpp::IgmpV3ReportLayer::getHeaderLen
size_t getHeaderLen() const
Definition: IgmpLayer.h:504
pcpp::IgmpV2Layer::~IgmpV2Layer
~IgmpV2Layer()
Definition: IgmpLayer.h:299
pcpp::IgmpLayer::getIgmpHeader
igmp_header * getIgmpHeader() const
Definition: IgmpLayer.h:180
pcpp::IgmpV3QueryLayer::removeAllSourceAddresses
bool removeAllSourceAddresses()
pcpp::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()