PcapPlusPlus  24.09
IgmpLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 #include "IpAddress.h"
5 #include <vector>
6 
8 
13 namespace pcpp
14 {
15 
20  struct igmp_header
21  {
23  uint8_t type;
25  uint8_t maxResponseTime;
27  uint16_t checksum;
30  uint32_t groupAddress;
31  };
32 
38  {
40  uint8_t type;
42  uint8_t maxResponseTime;
44  uint16_t checksum;
47  uint32_t groupAddress;
49  uint8_t s_qrv;
51  uint8_t qqic;
53  uint16_t numOfSources;
54  };
55 
61  {
63  uint8_t type;
65  uint8_t reserved1;
67  uint16_t checksum;
69  uint16_t reserved2;
72  };
73 
80  {
82  uint8_t recordType;
85  uint8_t auxDataLen;
87  uint16_t numOfSources;
89  uint32_t multicastAddress;
91  uint8_t sourceAddresses[];
92 
97  {
98  return multicastAddress;
99  }
100 
104  uint16_t getSourceAddressCount() const;
105 
113 
117  size_t getRecordLen() const;
118  };
119 
123  enum IgmpType
124  {
153  };
154 
161  class IgmpLayer : public Layer
162  {
163  protected:
164  IgmpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ProtocolType igmpVer)
165  : Layer(data, dataLen, prevLayer, packet, igmpVer)
166  {}
167 
168  IgmpLayer(IgmpType type, const IPv4Address& groupAddr, uint8_t maxResponseTime, ProtocolType igmpVer);
169 
170  uint16_t calculateChecksum();
171 
172  size_t getHeaderSizeByVerAndType(ProtocolType igmpVer, IgmpType igmpType) const;
173 
174  public:
175  virtual ~IgmpLayer()
176  {}
177 
184  {
185  return (igmp_header*)m_Data;
186  }
187 
192  {
193  return getIgmpHeader()->groupAddress;
194  }
195 
200  void setGroupAddress(const IPv4Address& groupAddr);
201 
206  IgmpType getType() const;
207 
212  void setType(IgmpType type);
213 
222  static ProtocolType getIGMPVerFromData(uint8_t* data, size_t dataLen, bool& isQuery);
223 
224  // implement abstract methods
225 
230  {}
231 
235  size_t getHeaderLen() const
236  {
237  return sizeof(igmp_header);
238  }
239 
240  std::string toString() const;
241 
243  {
244  return OsiModelNetworkLayer;
245  }
246  };
247 
253  class IgmpV1Layer : public IgmpLayer
254  {
255  public:
262  IgmpV1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
263  : IgmpLayer(data, dataLen, prevLayer, packet, IGMPv1)
264  {}
265 
272  explicit IgmpV1Layer(IgmpType type, const IPv4Address& groupAddr = IPv4Address())
273  : IgmpLayer(type, groupAddr, 0, IGMPv1)
274  {}
275 
280  {}
281 
282  // implement abstract methods
283 
288  };
289 
295  class IgmpV2Layer : public IgmpLayer
296  {
297  public:
304  IgmpV2Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
305  : IgmpLayer(data, dataLen, prevLayer, packet, IGMPv2)
306  {}
307 
316  explicit IgmpV2Layer(IgmpType type, const IPv4Address& groupAddr = IPv4Address(), uint8_t maxResponseTime = 0)
317  : IgmpLayer(type, groupAddr, maxResponseTime, IGMPv2)
318  {}
319 
324  {}
325 
326  // implement abstract methods
327 
332  };
333 
339  {
340  public:
347  IgmpV3QueryLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
348 
359  explicit IgmpV3QueryLayer(const IPv4Address& multicastAddr = IPv4Address(), uint8_t maxResponseTime = 0,
360  uint8_t s_qrv = 0);
361 
368  {
369  return (igmpv3_query_header*)m_Data;
370  }
371 
376  uint16_t getSourceAddressCount() const;
377 
385 
393  bool addSourceAddress(const IPv4Address& addr);
394 
403  bool addSourceAddressAtIndex(const IPv4Address& addr, int index);
404 
412  bool removeSourceAddressAtIndex(int index);
413 
420 
421  // implement abstract methods
422 
427 
432  size_t getHeaderLen() const;
433  };
434 
440  {
441  private:
442  igmpv3_group_record* addGroupRecordAt(uint8_t recordType, const IPv4Address& multicastAddress,
443  const std::vector<IPv4Address>& sourceAddresses, int offset);
444 
445  public:
452  IgmpV3ReportLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
453  : IgmpLayer(data, dataLen, prevLayer, packet, IGMPv3)
454  {}
455 
460  {}
461 
468  {
469  return (igmpv3_report_header*)m_Data;
470  }
471 
476  uint16_t getGroupRecordCount() const;
477 
483 
493 
504  igmpv3_group_record* addGroupRecord(uint8_t recordType, const IPv4Address& multicastAddress,
505  const std::vector<IPv4Address>& sourceAddresses);
506 
518  igmpv3_group_record* addGroupRecordAtIndex(uint8_t recordType, const IPv4Address& multicastAddress,
519  const std::vector<IPv4Address>& sourceAddresses, int index);
520 
528  bool removeGroupRecordAtIndex(int index);
529 
536 
537  // implement abstract methods
538 
543 
548  size_t getHeaderLen() const
549  {
550  return m_DataLen;
551  }
552  };
553 
554 } // namespace pcpp
Definition: IpAddress.h:32
Definition: IgmpLayer.h:162
IPv4Address getGroupAddress() const
Definition: IgmpLayer.h:191
void parseNextLayer()
Definition: IgmpLayer.h:229
void setGroupAddress(const IPv4Address &groupAddr)
igmp_header * getIgmpHeader() const
Definition: IgmpLayer.h:183
static ProtocolType getIGMPVerFromData(uint8_t *data, size_t dataLen, bool &isQuery)
IgmpType getType() const
void setType(IgmpType type)
size_t getHeaderLen() const
Definition: IgmpLayer.h:235
OsiModelLayer getOsiModelLayer() const
Definition: IgmpLayer.h:242
std::string toString() const
Definition: IgmpLayer.h:254
~IgmpV1Layer()
Definition: IgmpLayer.h:279
IgmpV1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IgmpLayer.h:262
void computeCalculateFields()
IgmpV1Layer(IgmpType type, const IPv4Address &groupAddr=IPv4Address())
Definition: IgmpLayer.h:272
Definition: IgmpLayer.h:296
~IgmpV2Layer()
Definition: IgmpLayer.h:323
void computeCalculateFields()
IgmpV2Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IgmpLayer.h:304
IgmpV2Layer(IgmpType type, const IPv4Address &groupAddr=IPv4Address(), uint8_t maxResponseTime=0)
Definition: IgmpLayer.h:316
Definition: IgmpLayer.h:339
uint16_t getSourceAddressCount() const
bool addSourceAddressAtIndex(const IPv4Address &addr, int index)
bool addSourceAddress(const IPv4Address &addr)
IgmpV3QueryLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
bool removeSourceAddressAtIndex(int index)
IPv4Address getSourceAddressAtIndex(int index) const
IgmpV3QueryLayer(const IPv4Address &multicastAddr=IPv4Address(), uint8_t maxResponseTime=0, uint8_t s_qrv=0)
size_t getHeaderLen() const
igmpv3_query_header * getIgmpV3QueryHeader() const
Definition: IgmpLayer.h:367
Definition: IgmpLayer.h:440
igmpv3_group_record * addGroupRecord(uint8_t recordType, const IPv4Address &multicastAddress, const std::vector< IPv4Address > &sourceAddresses)
igmpv3_group_record * addGroupRecordAtIndex(uint8_t recordType, const IPv4Address &multicastAddress, const std::vector< IPv4Address > &sourceAddresses, int index)
IgmpV3ReportLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IgmpLayer.h:452
bool removeGroupRecordAtIndex(int index)
igmpv3_report_header * getReportHeader() const
Definition: IgmpLayer.h:467
uint16_t getGroupRecordCount() const
IgmpV3ReportLayer()
Definition: IgmpLayer.h:459
igmpv3_group_record * getFirstGroupRecord() const
igmpv3_group_record * getNextGroupRecord(igmpv3_group_record *groupRecord) const
size_t getHeaderLen() const
Definition: IgmpLayer.h:548
Definition: Layer.h:70
Definition: Packet.h:27
The main namespace for the PcapPlusPlus lib.
uint8_t ProtocolType
Definition: ProtocolType.h:17
const ProtocolType IGMPv2
Definition: ProtocolType.h:163
const ProtocolType IGMPv3
Definition: ProtocolType.h:168
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelNetworkLayer
Definition: ProtocolType.h:360
const ProtocolType IGMPv1
Definition: ProtocolType.h:158
IgmpType
Definition: IgmpLayer.h:124
@ IgmpType_MulticastRouterTermination
Definition: IgmpLayer.h:152
@ IgmpType_Unknown
Definition: IgmpLayer.h:126
@ IgmpType_MembershipReportV2
Definition: IgmpLayer.h:138
@ IgmpType_DVMRP
Definition: IgmpLayer.h:132
@ IgmpType_MembershipReportV3
Definition: IgmpLayer.h:146
@ IgmpType_MulticastTraceroute
Definition: IgmpLayer.h:144
@ IgmpType_P1Mv1
Definition: IgmpLayer.h:134
@ IgmpType_LeaveGroup
Definition: IgmpLayer.h:140
@ IgmpType_MembershipReportV1
Definition: IgmpLayer.h:130
@ IgmpType_MulticastRouterAdvertisement
Definition: IgmpLayer.h:148
@ IgmpType_MulticastRouterSolicitation
Definition: IgmpLayer.h:150
@ IgmpType_CiscoTrace
Definition: IgmpLayer.h:136
@ IgmpType_MembershipQuery
Definition: IgmpLayer.h:128
@ IgmpType_MulticastTracerouteResponse
Definition: IgmpLayer.h:142
Definition: IgmpLayer.h:21
uint8_t type
Definition: IgmpLayer.h:23
uint16_t checksum
Definition: IgmpLayer.h:27
uint32_t groupAddress
Definition: IgmpLayer.h:30
uint8_t maxResponseTime
Definition: IgmpLayer.h:25
Definition: IgmpLayer.h:80
uint8_t sourceAddresses[]
Definition: IgmpLayer.h:91
size_t getRecordLen() const
uint32_t multicastAddress
Definition: IgmpLayer.h:89
uint8_t auxDataLen
Definition: IgmpLayer.h:85
uint8_t recordType
Definition: IgmpLayer.h:82
IPv4Address getMulticastAddress() const
Definition: IgmpLayer.h:96
uint16_t numOfSources
Definition: IgmpLayer.h:87
IPv4Address getSourceAddressAtIndex(int index) const
uint16_t getSourceAddressCount() const
Definition: IgmpLayer.h:38
uint8_t type
Definition: IgmpLayer.h:40
uint32_t groupAddress
Definition: IgmpLayer.h:47
uint8_t qqic
Definition: IgmpLayer.h:51
uint16_t numOfSources
Definition: IgmpLayer.h:53
uint8_t s_qrv
Definition: IgmpLayer.h:49
uint16_t checksum
Definition: IgmpLayer.h:44
uint8_t maxResponseTime
Definition: IgmpLayer.h:42
Definition: IgmpLayer.h:61
uint16_t numOfGroupRecords
Definition: IgmpLayer.h:71
uint8_t type
Definition: IgmpLayer.h:63
uint8_t reserved1
Definition: IgmpLayer.h:65
uint16_t reserved2
Definition: IgmpLayer.h:69
uint16_t checksum
Definition: IgmpLayer.h:67