PcapPlusPlus
PPPoELayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_PPPOE_LAYER
2 #define PACKETPP_PPPOE_LAYER
3 
4 #include "Layer.h"
5 #include <vector>
6 #include <string.h>
7 
9 
14 namespace pcpp
15 {
16 
21 #pragma pack(push, 1)
22  struct pppoe_header {
23 #if (BYTE_ORDER == LITTLE_ENDIAN)
24 
25  uint8_t version:4,
27  type:4;
29  uint8_t code;
30 #else
31 
32  uint16_t version:4,
34  type:4,
36  code:8;
37 #endif
38 
39  uint16_t sessionId;
41  uint16_t payloadLength;
42  };
43 #pragma pack(pop)
44 
45 
51  class PPPoELayer : public Layer
52  {
53  public:
57  enum PPPoECode
58  {
81  };
82 
83  ~PPPoELayer() {}
84 
89  inline pppoe_header* getPPPoEHeader() { return (pppoe_header*)m_Data; };
90 
91  // abstract methods implementation
92 
96  virtual void computeCalculateFields();
97 
99 
100  protected:
101 
102  // protected c'tor as this class shouldn't be instantiated
103  PPPoELayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { }
104 
105  // protected c'tor as this class shouldn't be instantiated
106  PPPoELayer(uint8_t version, uint8_t type, PPPoELayer::PPPoECode code, uint16_t sessionId, size_t additionalBytesToAllocate = 0);
107 
108  };
109 
110 
116  {
117  public:
118 
126  PPPoESessionLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : PPPoELayer(data, dataLen, prevLayer, packet) { m_Protocol = PPPoESession; }
127 
135  PPPoESessionLayer(uint8_t version, uint8_t type, uint16_t sessionId, uint16_t pppNextProtocol) : PPPoELayer(version, type, PPPoELayer::PPPOE_CODE_SESSION, sessionId, sizeof(uint16_t)) { setPPPNextProtocol(pppNextProtocol); }
136 
137  virtual ~PPPoESessionLayer() {}
138 
143  uint16_t getPPPNextProtocol();
144 
149  void setPPPNextProtocol(uint16_t nextProtocol);
150 
151  // abstract methods implementation
152 
156  virtual void parseNextLayer();
157 
161  virtual size_t getHeaderLen() { return sizeof(pppoe_header) + sizeof(uint16_t); }
162 
163  virtual std::string toString();
164  };
165 
166 
167 
173  {
174  public:
179  {
181  PPPOE_TAG_EOL = 0x0000,
203  PPPOE_TAG_HURL = 0x0111,
205  PPPOE_TAG_MOTM = 0x0112,
216  };
217 
222  struct PPPoETag
223  {
224  public:
225 
227  uint16_t tagType;
229  uint16_t tagDataLength;
231  uint8_t tagData[];
232 
242  template<typename T>
243  T getTagDataAs(int tagDataOffset = 0)
244  {
245  T result;
246  memcpy(&result, tagData+tagDataOffset, sizeof(T));
247  return result;
248  }
249 
258  template<typename T>
259  void setTagData(T value, int tagDataOffset = 0)
260  {
261  memcpy(tagData+tagDataOffset, &value, sizeof(T));
262  }
263 
267  size_t getTagTotalSize() const;
268 
273  private:
274  // private c'tor which isn't implemented to make this struct impossible to construct
275  PPPoETag();
276  };
277 
285  PPPoEDiscoveryLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : PPPoELayer(data, dataLen, prevLayer, packet) { m_Protocol = PPPoEDiscovery; m_TagCount = -1; m_DataLen = getHeaderLen(); }
286 
294  PPPoEDiscoveryLayer(uint8_t version, uint8_t type, PPPoELayer::PPPoECode code, uint16_t sessionId) : PPPoELayer(version, type, code, sessionId) { m_Protocol = PPPoEDiscovery; m_TagCount = -1; }
295 
299  PPPoEDiscoveryLayer(const PPPoEDiscoveryLayer& other) : PPPoELayer(other) { m_TagCount = other.m_TagCount; }
300 
308  PPPoETag* getTag(PPPoEDiscoveryLayer::PPPoETagTypes tagType);
309 
314  PPPoETag* getFirstTag();
315 
323  PPPoETag* getNextTag(PPPoETag* tag);
324 
328  int getTagCount();
329 
338  PPPoETag* addTag(PPPoETagTypes tagType, uint16_t tagLength, const uint8_t* tagData);
339 
349  PPPoETag* addTagAfter(PPPoETagTypes tagType, uint16_t tagLength, const uint8_t* tagData, PPPoETag* prevTag);
350 
358 
363  bool removeAllTags();
364 
365  // abstract methods implementation
366 
370  virtual void parseNextLayer() {};
371 
375  virtual size_t getHeaderLen();
376 
377  virtual std::string toString() { return "PPP-over-Ethernet Discovery (" + codeToString((PPPoELayer::PPPoECode)getPPPoEHeader()->code) + ")"; }
378 
379  private:
380  int m_TagCount;
381 
382  PPPoETag* addTagAt(PPPoETagTypes tagType, uint16_t tagLength, const uint8_t* tagData, int offset);
383 
384  PPPoETag* castPtrToPPPoETag(uint8_t* ptr);
385 
386  std::string codeToString(PPPoECode code);
387  };
388 
389 
390  // Copied from Wireshark: ppptypes.h
391 
393 #define PCPP_PPP_PADDING 0x1
394 
395 #define PCPP_PPP_ROHC_SCID 0x3
396 
397 #define PCPP_PPP_ROHC_LCID 0x5
398 
399 #define PCPP_PPP_IP 0x21
400 
401 #define PCPP_PPP_OSI 0x23
402 
403 #define PCPP_PPP_XNSIDP 0x25
404 
405 #define PCPP_PPP_DEC4 0x27
406 
407 #define PCPP_PPP_AT 0x29
408 
409 #define PCPP_PPP_IPX 0x2b
410 
411 #define PCPP_PPP_VJC_COMP 0x2d
412 
413 #define PCPP_PPP_VJC_UNCOMP 0x2f
414 
415 #define PCPP_PPP_BCP 0x31
416 
417 #define PCPP_PPP_ST 0x33
418 
419 #define PCPP_PPP_VINES 0x35
420 
421 #define PCPP_PPP_AT_EDDP 0x39
422 
423 #define PCPP_PPP_AT_SB 0x3b
424 
425 #define PCPP_PPP_MP 0x3d
426 
427 #define PCPP_PPP_NB 0x3f
428 
429 #define PCPP_PPP_CISCO 0x41
430 
431 #define PCPP_PPP_ASCOM 0x43
432 
433 #define PCPP_PPP_LBLB 0x45
434 
435 #define PCPP_PPP_RL 0x47
436 
437 #define PCPP_PPP_SDTP 0x49
438 
439 #define PCPP_PPP_LLC 0x4b
440 
441 #define PCPP_PPP_SNA 0x4d
442 
443 #define PCPP_PPP_IPV6HC 0x4f
444 
445 #define PCPP_PPP_KNX 0x51
446 
447 #define PCPP_PPP_ENCRYPT 0x53
448 
449 #define PCPP_PPP_ILE 0x55
450 
451 #define PCPP_PPP_IPV6 0x57
452 
453 #define PCPP_PPP_MUX 0x59
454 
455 #define PCPP_PPP_VSNP 0x5b
456 
457 #define PCPP_PPP_TNP 0x5d
458 
459 #define PCPP_PPP_RTP_FH 0x61
460 
461 #define PCPP_PPP_RTP_CTCP 0x63
462 
463 #define PCPP_PPP_RTP_CNTCP 0x65
464 
465 #define PCPP_PPP_RTP_CUDP8 0x67
466 
467 #define PCPP_PPP_RTP_CRTP8 0x69
468 
469 #define PCPP_PPP_STAMPEDE 0x6f
470 
471 #define PCPP_PPP_MPPLUS 0x73
472 
473 #define PCPP_PPP_NTCITS_IPI 0xc1
474 
475 #define PCPP_PPP_ML_SLCOMP 0xfb
476 
477 #define PCPP_PPP_COMP 0xfd
478 
479 #define PCPP_PPP_STP_HELLO 0x0201
480 
481 #define PCPP_PPP_IBM_SR 0x0203
482 
483 #define PCPP_PPP_DEC_LB 0x0205
484 
485 #define PCPP_PPP_CDP 0x0207
486 
487 #define PCPP_PPP_NETCS 0x0209
488 
489 #define PCPP_PPP_STP 0x020b
490 
491 #define PCPP_PPP_EDP 0x020d
492 
493 #define PCPP_PPP_OSCP 0x0211
494 
495 #define PCPP_PPP_OSCP2 0x0213
496 
497 #define PCPP_PPP_LUXCOM 0x0231
498 
499 #define PCPP_PPP_SIGMA 0x0233
500 
501 #define PCPP_PPP_ACSP 0x0235
502 
503 #define PCPP_PPP_MPLS_UNI 0x0281
504 
505 #define PCPP_PPP_MPLS_MULTI 0x0283
506 
507 #define PCPP_PPP_P12844 0x0285
508 
509 #define PCPP_PPP_TETRA 0x0287
510 
511 #define PCPP_PPP_MFTP 0x0289
512 
513 #define PCPP_PPP_RTP_CTCPND 0x2063
514 
515 #define PCPP_PPP_RTP_CS 0x2065
516 
517 #define PCPP_PPP_RTP_CUDP16 0x2067
518 
519 #define PCPP_PPP_RTP_CRDP16 0x2069
520 
521 #define PCPP_PPP_CCCP 0x4001
522 
523 #define PCPP_PPP_CDPD_MNRP 0x4003
524 
525 #define PCPP_PPP_EXPANDAP 0x4005
526 
527 #define PCPP_PPP_ODSICP 0x4007
528 
529 #define PCPP_PPP_DOCSIS 0x4009
530 
531 #define PCPP_PPP_CETACEANNDP 0x400b
532 
533 #define PCPP_PPP_LZS 0x4021
534 
535 #define PCPP_PPP_REFTEK 0x4023
536 
537 #define PCPP_PPP_FC 0x4025
538 
539 #define PCPP_PPP_EMIT 0x4027
540 
541 #define PCPP_PPP_VSP 0x405b
542 
543 #define PCPP_PPP_TLSP 0x405d
544 
545 #define PCPP_PPP_IPCP 0x8021
546 
547 #define PCPP_PPP_OSINLCP 0x8023
548 
549 #define PCPP_PPP_XNSIDPCP 0x8025
550 
551 #define PCPP_PPP_DECNETCP 0x8027
552 
553 #define PCPP_PPP_ATCP 0x8029
554 
555 #define PCPP_PPP_IPXCP 0x802b
556 
557 #define PCPP_PPP_BRIDGENCP 0x8031
558 
559 #define PCPP_PPP_SPCP 0x8033
560 
561 #define PCPP_PPP_BVCP 0x8035
562 
563 #define PCPP_PPP_MLCP 0x803d
564 
565 #define PCPP_PPP_NBCP 0x803f
566 
567 #define PCPP_PPP_CISCOCP 0x8041
568 
569 #define PCPP_PPP_ASCOMCP 0x8043
570 
571 #define PCPP_PPP_LBLBCP 0x8045
572 
573 #define PCPP_PPP_RLNCP 0x8047
574 
575 #define PCPP_PPP_SDCP 0x8049
576 
577 #define PCPP_PPP_LLCCP 0x804b
578 
579 #define PCPP_PPP_SNACP 0x804d
580 
581 #define PCPP_PPP_IP6HCCP 0x804f
582 
583 #define PCPP_PPP_KNXCP 0x8051
584 
585 #define PCPP_PPP_ECP 0x8053
586 
587 #define PCPP_PPP_ILECP 0x8055
588 
589 #define PCPP_PPP_IPV6CP 0x8057
590 
591 #define PCPP_PPP_MUXCP 0x8059
592 
593 #define PCPP_PPP_VSNCP 0x805b
594 
595 #define PCPP_PPP_TNCP 0x805d
596 
597 #define PCPP_PPP_STAMPEDECP 0x806f
598 
599 #define PCPP_PPP_MPPCP 0x8073
600 
601 #define PCPP_PPP_IPICP 0x80c1
602 
603 #define PCPP_PPP_SLCC 0x80fb
604 
605 #define PCPP_PPP_CCP 0x80fd
606 
607 #define PCPP_PPP_CDPCP 0x8207
608 
609 #define PCPP_PPP_NETCSCP 0x8209
610 
611 #define PCPP_PPP_STPCP 0x820b
612 
613 #define PCPP_PPP_EDPCP 0x820d
614 
615 #define PCPP_PPP_ACSPC 0x8235
616 
617 #define PCPP_PPP_MPLSCP 0x8281
618 
619 #define PCPP_PPP_P12844CP 0x8285
620 
621 #define PCPP_PPP_TETRACP 0x8287
622 
623 #define PCPP_PPP_MFTPCP 0x8289
624 
625 #define PCPP_PPP_LCP 0xc021
626 
627 #define PCPP_PPP_PAP 0xc023
628 
629 #define PCPP_PPP_LQR 0xc025
630 
631 #define PCPP_PPP_SPAP 0xc027
632 
633 #define PCPP_PPP_CBCP 0xc029
634 
635 #define PCPP_PPP_BACP 0xc02b
636 
637 #define PCPP_PPP_BAP 0xc02d
638 
639 #define PCPP_PPP_VSAP 0xc05b
640 
641 #define PCPP_PPP_CONTCP 0xc081
642 
643 #define PCPP_PPP_CHAP 0xc223
644 
645 #define PCPP_PPP_RSAAP 0xc225
646 
647 #define PCPP_PPP_EAP 0xc227
648 
649 #define PCPP_PPP_SIEP 0xc229
650 
651 #define PCPP_PPP_SBAP 0xc26f
652 
653 #define PCPP_PPP_PRPAP 0xc281
654 
655 #define PCPP_PPP_PRPAP2 0xc283
656 
657 #define PCPP_PPP_PRPNIAP 0xc481
658 
659 } // namespace pcpp
660 
661 #endif /* PACKETPP_PPPOE_LAYER */
void setTagData(T value, int tagDataOffset=0)
Definition: PPPoELayer.h:259
virtual void parseNextLayer()
uint8_t type
Definition: PPPoELayer.h:25
pppoe_header * getPPPoEHeader()
Definition: PPPoELayer.h:89
Definition: PPPoELayer.h:22
virtual size_t getHeaderLen()
Definition: PPPoELayer.h:161
Definition: PPPoELayer.h:74
Definition: ProtocolType.h:86
Definition: PPPoELayer.h:78
uint16_t getPPPNextProtocol()
uint8_t version
Definition: PPPoELayer.h:25
Definition: Packet.h:26
uint8_t tagData[]
Definition: PPPoELayer.h:231
The main namespace for the PcapPlusPlus lib.
uint16_t payloadLength
Definition: PPPoELayer.h:41
uint16_t tagType
Definition: PPPoELayer.h:227
Definition: PPPoELayer.h:68
PPPoEDiscoveryLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: PPPoELayer.h:285
Definition: ProtocolType.h:213
OsiModelLayer
Definition: ProtocolType.h:208
void setPPPNextProtocol(uint16_t nextProtocol)
PPPoETagTypes
Definition: PPPoELayer.h:178
Definition: PPPoELayer.h:115
Definition: PPPoELayer.h:76
Definition: PPPoELayer.h:64
Definition: ProtocolType.h:91
uint16_t tagDataLength
Definition: PPPoELayer.h:229
Definition: PPPoELayer.h:203
Definition: PPPoELayer.h:181
Definition: PPPoELayer.h:60
Definition: PPPoELayer.h:222
PPPoEDiscoveryLayer(const PPPoEDiscoveryLayer &other)
Definition: PPPoELayer.h:299
PPPoETag * addTagAfter(PPPoETagTypes tagType, uint16_t tagLength, const uint8_t *tagData, PPPoETag *prevTag)
Definition: PPPoELayer.h:51
bool removeTag(PPPoEDiscoveryLayer::PPPoETagTypes tagType)
PPPoESessionLayer(uint8_t version, uint8_t type, uint16_t sessionId, uint16_t pppNextProtocol)
Definition: PPPoELayer.h:135
virtual size_t getHeaderLen()
uint16_t sessionId
Definition: PPPoELayer.h:39
Definition: PPPoELayer.h:72
virtual void computeCalculateFields()
Definition: PPPoELayer.h:70
PPPoECode
Definition: PPPoELayer.h:57
uint8_t code
Definition: PPPoELayer.h:29
virtual void parseNextLayer()
Definition: PPPoELayer.h:370
PPPoEDiscoveryLayer::PPPoETagTypes getType()
Definition: Layer.h:70
PPPoETag * getNextTag(PPPoETag *tag)
Definition: PPPoELayer.h:172
T getTagDataAs(int tagDataOffset=0)
Definition: PPPoELayer.h:243
virtual std::string toString()
OsiModelLayer getOsiModelLayer()
Definition: PPPoELayer.h:98
Definition: PPPoELayer.h:66
Definition: PPPoELayer.h:62
PPPoETag * getTag(PPPoEDiscoveryLayer::PPPoETagTypes tagType)
Definition: PPPoELayer.h:80
PPPoETag * addTag(PPPoETagTypes tagType, uint16_t tagLength, const uint8_t *tagData)
PPPoESessionLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: PPPoELayer.h:126
PPPoEDiscoveryLayer(uint8_t version, uint8_t type, PPPoELayer::PPPoECode code, uint16_t sessionId)
Definition: PPPoELayer.h:294
Definition: PPPoELayer.h:205
virtual std::string toString()
Definition: PPPoELayer.h:377