OpenVPN 3 Core Library
Loading...
Searching...
No Matches
endian.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#pragma once
13
15
16namespace openvpn::Endian {
17#if defined(OPENVPN_LITTLE_ENDIAN)
18inline size_t e16(const size_t v)
19{
20 return v;
21}
22inline size_t e16rev(const size_t v)
23{
24 return 15 - v;
25}
26inline size_t e4(const size_t v)
27{
28 return v;
29}
30inline size_t e4rev(const size_t v)
31{
32 return 3 - v;
33}
34inline size_t e2(const size_t v)
35{
36 return v;
37}
38inline size_t e2rev(const size_t v)
39{
40 return 1 - v;
41}
42#elif defined(OPENVPN_BIG_ENDIAN)
43inline size_t e16rev(const size_t v)
44{
45 return v;
46}
47inline size_t e16(const size_t v)
48{
49 return 15 - v;
50}
51inline size_t e4rev(const size_t v)
52{
53 return v;
54}
55inline size_t e4(const size_t v)
56{
57 return 3 - v;
58}
59inline size_t e2rev(const size_t v)
60{
61 return v;
62}
63inline size_t e2(const size_t v)
64{
65 return 1 - v;
66}
67#else
68#error One of OPENVPN_LITTLE_ENDIAN or OPENVPN_BIG_ENDIAN must be defined
69#endif
70} // namespace openvpn::Endian