PcapPlusPlus
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();
103 
111 
115  size_t getRecordLen();
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);
172 public:
173 
174  virtual ~IgmpLayer() {}
175 
180  inline igmp_header* getIgmpHeader() { return (igmp_header*)m_Data; }
181 
185  inline IPv4Address getGroupAddress() { return IPv4Address(getIgmpHeader()->groupAddress); }
186 
191  void setGroupAddress(const IPv4Address& groupAddr);
192 
197  IgmpType getType();
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  inline size_t getHeaderLen() { return sizeof(igmp_header); }
227 
228  std::string toString();
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();
348 
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();
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();
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();
505 };
506 
507 }
508 
509 #endif // PACKETPP_IGMP_LAYER
IgmpType
Definition: IgmpLayer.h:122
Definition: IgmpLayer.h:137
uint32_t multicastAddress
Definition: IgmpLayer.h:90
IPv4Address getGroupAddress()
Definition: IgmpLayer.h:185
uint16_t reserved2
Definition: IgmpLayer.h:70
igmpv3_report_header * getReportHeader()
Definition: IgmpLayer.h:431
Definition: IgmpLayer.h:21
Definition: IgmpLayer.h:143
uint32_t groupAddress
Definition: IgmpLayer.h:30
Definition: IgmpLayer.h:277
Definition: IgmpLayer.h:131
Definition: IgmpLayer.h:406
Definition: IgmpLayer.h:61
uint16_t checksum
Definition: IgmpLayer.h:28
Definition: IgmpLayer.h:135
uint16_t getSourceAddressCount()
Definition: ProtocolType.h:210
std::string toString()
void setType(IgmpType type)
bool addSourceAddress(const IPv4Address &addr)
void computeCalculateFields()
IPv4Address getSourceAddressAtIndex(int index)
Definition: IpAddress.h:99
IgmpV2Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
uint8_t auxDataLen
Definition: IgmpLayer.h:86
uint8_t maxResponseTime
Definition: IgmpLayer.h:26
OsiModelLayer
Definition: ProtocolType.h:203
IPv4Address getMulticastAddress()
igmpv3_group_record * getNextGroupRecord(igmpv3_group_record *groupRecord)
uint8_t reserved1
Definition: IgmpLayer.h:66
Definition: IgmpLayer.h:315
Definition: Packet.h:26
Definition: IgmpLayer.h:38
uint8_t sourceAddresses[]
Definition: IgmpLayer.h:92
igmp_header * getIgmpHeader()
Definition: IgmpLayer.h:180
uint8_t type
Definition: IgmpLayer.h:64
uint16_t checksum
Definition: IgmpLayer.h:68
Definition: IgmpLayer.h:133
uint8_t qqic
Definition: IgmpLayer.h:51
ProtocolType
Definition: ProtocolType.h:16
Definition: IgmpLayer.h:238
igmpv3_group_record * addGroupRecord(uint8_t recordType, const IPv4Address &multicastAddress, const std::vector< IPv4Address > &sourceAddresses)
static ProtocolType getIGMPVerFromData(uint8_t *data, size_t dataLen, bool &isQuery)
uint16_t getGroupRecordCount()
uint16_t numOfSources
Definition: IgmpLayer.h:88
Definition: IgmpLayer.h:125
uint8_t recordType
Definition: IgmpLayer.h:84
Definition: IgmpLayer.h:127
static IPv4Address Zero
Definition: IpAddress.h:187
~IgmpV1Layer()
Definition: IgmpLayer.h:260
Definition: IgmpLayer.h:129
Definition: Layer.h:52
void parseNextLayer()
Definition: IgmpLayer.h:221
size_t getHeaderLen()
Definition: IgmpLayer.h:226
bool removeGroupRecordAtIndex(int index)
igmpv3_group_record * addGroupRecordAtIndex(uint8_t recordType, const IPv4Address &multicastAddress, const std::vector< IPv4Address > &sourceAddresses, int index)
uint16_t numOfSources
Definition: IgmpLayer.h:53
IgmpV3QueryLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
bool addSourceAddressAtIndex(const IPv4Address &addr, int index)
Definition: IgmpLayer.h:161
uint16_t numOfGroupRecords
Definition: IgmpLayer.h:72
uint8_t type
Definition: IgmpLayer.h:41
IgmpV1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
void computeCalculateFields()
Definition: IgmpLayer.h:81
~IgmpV2Layer()
Definition: IgmpLayer.h:299
uint8_t s_qrv
Definition: IgmpLayer.h:49
igmpv3_query_header * getIgmpV3QueryHeader()
Definition: IgmpLayer.h:342
void setGroupAddress(const IPv4Address &groupAddr)
uint32_t groupAddress
Definition: IgmpLayer.h:47
OsiModelLayer getOsiModelLayer()
Definition: IgmpLayer.h:230
igmpv3_group_record * getFirstGroupRecord()
The main namespace for the PcapPlusPlus lib.
uint8_t maxResponseTime
Definition: IgmpLayer.h:43
uint8_t type
Definition: IgmpLayer.h:24
Definition: IgmpLayer.h:139
bool removeSourceAddressAtIndex(int index)
IgmpType getType()
Definition: IgmpLayer.h:145
IPv4Address getSoruceAddressAtIndex(int index)
uint16_t checksum
Definition: IgmpLayer.h:45