libtins  3.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
ppi.h
1 /*
2  * Copyright (c) 2016, 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 "pdu.h"
34 #include "macros.h"
35 #include "endianness.h"
36 #include "small_uint.h"
37 
38 namespace Tins {
39 
48 class TINS_API PPI : public PDU {
49 public:
53  static const PDU::PDUType pdu_flag = PDU::PPI;
54 
66  PPI(const uint8_t* buffer, uint32_t total_sz);
67 
68  // Getters
69 
74  uint8_t version() const {
75  return header_.version;
76  }
77 
82  uint8_t flags() const {
83  return header_.flags;
84  }
85 
90  uint16_t length() const {
91  return Endian::le_to_host(header_.length);
92  }
93 
98  uint32_t dlt() const {
99  return Endian::le_to_host(header_.dlt);
100  }
101 
107  uint32_t header_size() const;
108 
113  PDUType pdu_type() const {
114  return pdu_flag;
115  }
116 
122  PPI* clone() const {
123  return new PPI(*this);
124  }
125 private:
126  void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
127  void parse_80211(const uint8_t* buffer, uint32_t total_sz);
128 
129  struct ppi_header {
130  uint8_t version, flags;
131  uint16_t length;
132  uint32_t dlt;
133  };
134 
135  ppi_header header_;
136  byte_array data_;
137 };
138 }
139 
140 #endif // TINS_PPI_H
PDUType pdu_type() const
Getter for the PDU's type.
Definition: ppi.h:113
uint8_t flags() const
Getter for the flags field.
Definition: ppi.h:82
std::vector< uint8_t > byte_array
Definition: pdu.h:46
PPI * clone() const
Clones this PDU.
Definition: ppi.h:122
PDUType
Enum which identifies each type of PDU.
Definition: pdu.h:128
Represents a Per-Packet Information PDU.
Definition: ppi.h:48
uint32_t dlt() const
Getter for the Data Link Type field.
Definition: ppi.h:98
uint16_t length() const
Getter for the length field.
Definition: ppi.h:90
uint8_t version() const
Getter for the version field.
Definition: ppi.h:74
Base class for protocol data units.
Definition: pdu.h:108