libtins 4.5
Loading...
Searching...
No Matches
sll.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_SLL_H
31#define TINS_SLL_H
32
33#include <vector>
34#include <tins/pdu.h>
35#include <tins/macros.h>
36#include <tins/endianness.h>
37#include <tins/hw_address.h>
38
39namespace Tins {
40
45class TINS_API SLL : public PDU {
46public:
50 static const PDU::PDUType pdu_flag = PDU::SLL;
51
56
60 SLL();
61
74 SLL(const uint8_t* buffer, uint32_t total_sz);
75
76 // Getters
77
82 uint16_t packet_type() const {
83 return Endian::be_to_host(header_.packet_type);
84 }
85
90 uint16_t lladdr_type() const {
91 return Endian::be_to_host(header_.lladdr_type);
92 }
93
98 uint16_t lladdr_len() const {
99 return Endian::be_to_host(header_.lladdr_len);
100 }
101
107 return header_.address;
108 }
109
114 uint16_t protocol() const {
115 return Endian::be_to_host(header_.protocol);
116 }
117
122 PDUType pdu_type() const { return pdu_flag; }
123
124 // Setters
125
130 void packet_type(uint16_t new_packet_type);
131
136 void lladdr_type(uint16_t new_lladdr_type);
137
142 void lladdr_len(uint16_t new_lladdr_len);
143
148 void address(const address_type& new_address);
149
154 void protocol(uint16_t new_protocol);
155
161 uint32_t header_size() const;
162
166 SLL* clone() const {
167 return new SLL(*this);
168 }
169private:
170 TINS_BEGIN_PACK
171 struct sll_header {
172 uint16_t packet_type, lladdr_type, lladdr_len;
173 uint8_t address[8];
174 uint16_t protocol;
175 } TINS_END_PACK;
176
177 void write_serialization(uint8_t* buffer, uint32_t total_sz);
178
179 sll_header header_;
180};
181}
182
183#endif // TINS_SLL_H
Represents a hardware address.
Definition resolve_utils.h:43
Base class for protocol data units.
Definition pdu.h:107
PDUType
Enum which identifies each type of PDU.
Definition pdu.h:127
Represents a Linux cooked-mode capture (SLL) PDU.
Definition sll.h:45
uint16_t lladdr_len() const
Getter for the LLADDR Length field.
Definition sll.h:98
SLL * clone() const
Definition sll.h:166
uint16_t lladdr_type() const
Getter for the LLADDR Type field.
Definition sll.h:90
uint16_t packet_type() const
Getter for the Packet Type field.
Definition sll.h:82
HWAddress< 8 > address_type
Definition sll.h:55
uint16_t protocol() const
Getter for the Protocol field.
Definition sll.h:114
address_type address() const
Getter for the Address field.
Definition sll.h:106
PDUType pdu_type() const
Getter for the PDU's type.
Definition sll.h:122
The Tins namespace.
Definition address_range.h:38