OpenVPN 3 Core Library
Loading...
Searching...
No Matches
alignment.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
#ifndef ALIGNMENT_HEADER_PARSED
13
#define ALIGNMENT_HEADER_PARSED
14
15
#include <cstring>
16
#include <type_traits>
17
18
namespace
openvpn
{
19
29
template <typename T, typename = std::enable_if_t<std::is_trivially_copyable<T>::value>>
30
T
alignment_safe_extract
(
const
void
*toAlign)
noexcept
31
{
32
T
ret
;
33
std::memcpy(&
ret
, toAlign,
sizeof
(T));
34
return
ret
;
35
}
36
37
}
// namespace openvpn
38
39
#endif
openvpn
Definition
ovpncli.cpp:97
openvpn::alignment_safe_extract
T alignment_safe_extract(const void *toAlign) noexcept
Converts a byte buffer to the desired type, avoiding undefined behavior due to alignment.
Definition
alignment.hpp:30
ret
std::string ret
Definition
test_capture.cpp:268
openvpn
common
alignment.hpp
Generated by
1.9.8