]>
git.ipfire.org Git - thirdparty/snort3.git/blob - src/protocols/eth.h
1 //--------------------------------------------------------------------------
2 // Copyright (C) 2014-2023 Cisco and/or its affiliates. All rights reserved.
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.
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.
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>
20 #ifndef PROTOCOLS_ETH_H
21 #define PROTOCOLS_ETH_H
25 #include <arpa/inet.h>
26 #include "protocols/protocol_ids.h"
28 #define ETHERNET_HEADER_LEN 14
29 #define ETHERNET_MTU 1500
35 constexpr uint16_t MTU_LEN
= 1500;
36 constexpr uint16_t MAX_FRAME_LENGTH
= 1500;
37 constexpr uint16_t ETH_HEADER_LEN
= 14;
45 /* return data in host byte order */
46 inline ProtocolId
ethertype() const
47 { return (ProtocolId
)ntohs(ether_type
); }
49 /* return data in network order */
50 inline uint16_t raw_ethertype() const
51 { return ether_type
; }
53 // <Src MAC> -> <Dst Mac> <Ether Type>
54 std::string
to_string() const
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());