libtins 4.5
Loading...
Searching...
No Matches
snap.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_SNAP_H
31#define TINS_SNAP_H
32
33#include <stdint.h>
34#include <tins/pdu.h>
35#include <tins/macros.h>
36#include <tins/endianness.h>
37#include <tins/small_uint.h>
38
39namespace Tins {
40
48class TINS_API SNAP : public PDU {
49public:
53 static const PDU::PDUType pdu_flag = PDU::SNAP;
54
60 SNAP();
61
74 SNAP(const uint8_t* buffer, uint32_t total_sz);
75
76 /* Setters */
77
82 void control(uint8_t new_control);
83
88 void org_code(small_uint<24> new_org);
89
94 void eth_type(uint16_t new_eth);
95
96 /* Getters */
97
102 uint8_t dsap() const {
103 return snap_.dsap;
104 }
105
110 uint8_t ssap() const {
111 return snap_.ssap;
112 }
113
118 uint8_t control() const {
119 #if TINS_IS_LITTLE_ENDIAN
120 return (snap_.control_org) & 0xff;
121 #else
122 return (snap_.control_org >> 24) & 0xff;
123 #endif
124 }
125
131 #if TINS_IS_LITTLE_ENDIAN
132 return Endian::be_to_host<uint32_t>(snap_.control_org & 0xffffff00);
133 #else
134 return snap_.control_org & 0xffffff;
135 #endif
136 }
137
142 uint16_t eth_type() const {
143 return Endian::be_to_host(snap_.eth_type);
144 }
145
152 uint32_t header_size() const;
153
159 return pdu_flag;
160 }
161
167 SNAP* clone() const {
168 return new SNAP(*this);
169 }
170private:
171 TINS_BEGIN_PACK
172 struct snap_header {
173 uint8_t dsap;
174 uint8_t ssap;
175 uint32_t control_org;
176 uint16_t eth_type;
177 } TINS_END_PACK;
178
179 void write_serialization(uint8_t* buffer, uint32_t total_sz);
180
181 snap_header snap_;
182};
183
184} // Tins
185
186#endif // TINS_SNAP_H
Base class for protocol data units.
Definition pdu.h:107
PDUType
Enum which identifies each type of PDU.
Definition pdu.h:127
Represents a SNAP frame.
Definition snap.h:48
uint16_t eth_type() const
Getter for the Ethernet Type field.
Definition snap.h:142
small_uint< 24 > org_code() const
Getter for the Organization Code field.
Definition snap.h:130
uint8_t ssap() const
Getter for the SSAP field.
Definition snap.h:110
uint8_t control() const
Getter for the Control field.
Definition snap.h:118
PDUType pdu_type() const
Getter for the PDU's type.
Definition snap.h:158
SNAP * clone() const
Clones this PDU.
Definition snap.h:167
uint8_t dsap() const
Getter for the DSAP field.
Definition snap.h:102
Represents a field of n bits.
Definition small_uint.h:52
The Tins namespace.
Definition address_range.h:38