]> git.ipfire.org Git - thirdparty/snort3.git/blob - src/protocols/eth.h
Pull request #4152: flow: Add tenant ID to FlowKey
[thirdparty/snort3.git] / src / protocols / eth.h
1 //--------------------------------------------------------------------------
2 // Copyright (C) 2014-2023 Cisco and/or its affiliates. All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License Version 2 as published
6 // by the Free Software Foundation. You may not use, modify or distribute
7 // this program under any other version of the GNU General Public License.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 //--------------------------------------------------------------------------
18 // eth.h author Josh Rosenbaum <jrosenba@cisco.com>
19
20 #ifndef PROTOCOLS_ETH_H
21 #define PROTOCOLS_ETH_H
22
23 #include <string>
24
25 #include <arpa/inet.h>
26 #include "protocols/protocol_ids.h"
27
28 #define ETHERNET_HEADER_LEN 14
29 #define ETHERNET_MTU 1500
30
31 namespace snort
32 {
33 namespace eth
34 {
35 constexpr uint16_t MTU_LEN = 1500;
36 constexpr uint16_t MAX_FRAME_LENGTH = 1500;
37 constexpr uint16_t ETH_HEADER_LEN = 14;
38
39 struct EtherHdr
40 {
41 uint8_t ether_dst[6];
42 uint8_t ether_src[6];
43 uint16_t ether_type;
44
45 /* return data in host byte order */
46 inline ProtocolId ethertype() const
47 { return (ProtocolId)ntohs(ether_type); }
48
49 /* return data in network order */
50 inline uint16_t raw_ethertype() const
51 { return ether_type; }
52
53 // <Src MAC> -> <Dst Mac> <Ether Type>
54 std::string to_string() const
55 {
56 char str[50];
57
58 snprintf(str, sizeof(str),
59 "%02X:%02X:%02X:%02X:%02X:%02X -> %02X:%02X:%02X:%02X:%02X:%02X %04X",
60 ether_src[0], ether_src[1], ether_src[2],
61 ether_src[3], ether_src[4], ether_src[5],
62 ether_dst[0], ether_dst[1], ether_dst[2],
63 ether_dst[3], ether_dst[4], ether_dst[5],
64 (uint16_t)ethertype());
65
66 return str;
67 }
68 };
69 } // namespace eth
70 } // namespace snort
71
72 #endif
73