libtins  4.0
ppi.h
1 /*
2  * Copyright (c) 2017, Matias Fontanini
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef TINS_PPI_H
31 #define TINS_PPI_H
32 
33 #include <tins/pdu.h>
34 #include <tins/macros.h>
35 #include <tins/endianness.h>
36 #include <tins/small_uint.h>
37 
38 #ifdef TINS_HAVE_PCAP
39 
40 namespace Tins {
41 
50 class TINS_API PPI : public PDU {
51 public:
55  static const PDU::PDUType pdu_flag = PDU::PPI;
56 
68  PPI(const uint8_t* buffer, uint32_t total_sz);
69 
70  // Getters
71 
76  uint8_t version() const {
77  return header_.version;
78  }
79 
84  uint8_t flags() const {
85  return header_.flags;
86  }
87 
92  uint16_t length() const {
93  return Endian::le_to_host(header_.length);
94  }
95 
100  uint32_t dlt() const {
101  return Endian::le_to_host(header_.dlt);
102  }
103 
109  uint32_t header_size() const;
110 
115  PDUType pdu_type() const {
116  return pdu_flag;
117  }
118 
124  PPI* clone() const {
125  return new PPI(*this);
126  }
127 private:
128  void write_serialization(uint8_t* buffer, uint32_t total_sz);
129  void parse_80211(const uint8_t* buffer, uint32_t total_sz);
130 
131  struct ppi_header {
132  uint8_t version, flags;
133  uint16_t length;
134  uint32_t dlt;
135  };
136 
137  ppi_header header_;
138  byte_array data_;
139 };
140 
141 } // Tins
142 
143 #endif // TINS_HAVE_PCAP
144 
145 #endif // TINS_PPI_H
std::vector< uint8_t > byte_array
Definition: pdu.h:45
PDUType
Enum which identifies each type of PDU.
Definition: pdu.h:127
The Tins namespace.
Definition: address_range.h:38