Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
actor-incubator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
actor-incubator
Commits
d8343bd3
Commit
d8343bd3
authored
Aug 27, 2019
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add conversion functions for ip_endpoint
parent
7f2798df
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
0 deletions
+124
-0
libcaf_net/CMakeLists.txt
libcaf_net/CMakeLists.txt
+1
-0
libcaf_net/caf/detail/convert_ip_endpoint.hpp
libcaf_net/caf/detail/convert_ip_endpoint.hpp
+32
-0
libcaf_net/src/convert_ip_endpoint.cpp
libcaf_net/src/convert_ip_endpoint.cpp
+42
-0
libcaf_net/test/convert_ip_endpoint.cpp
libcaf_net/test/convert_ip_endpoint.cpp
+49
-0
No files found.
libcaf_net/CMakeLists.txt
View file @
d8343bd3
...
...
@@ -19,6 +19,7 @@ set(LIBCAF_NET_SRCS
src/socket_manager.cpp
src/stream_socket.cpp
src/scribe.cpp
src/convert_ip_endpoint.cpp
)
add_custom_target
(
libcaf_net
)
...
...
libcaf_net/caf/detail/convert_ip_endpoint.hpp
0 → 100644
View file @
d8343bd3
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2019 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include "caf/detail/socket_sys_includes.hpp"
#include "caf/ip_endpoint.hpp"
namespace
caf
{
namespace
detail
{
sockaddr_in6
to_sockaddr
(
const
ip_endpoint
&
ep
);
ip_endpoint
to_ip_endpoint
(
const
sockaddr_in6
&
addr
);
}
// namespace detail
}
// namespace caf
libcaf_net/src/convert_ip_endpoint.cpp
0 → 100644
View file @
d8343bd3
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2019 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/detail/convert_ip_endpoint.hpp"
namespace
caf
{
namespace
detail
{
sockaddr_in6
to_sockaddr
(
const
ip_endpoint
&
ep
)
{
sockaddr_in6
addr
=
{};
addr
.
sin6_family
=
AF_INET6
;
addr
.
sin6_port
=
ntohs
(
ep
.
port
());
memcpy
(
&
addr
.
sin6_addr
,
ep
.
address
().
bytes
().
data
(),
ep
.
address
().
size
());
return
addr
;
}
ip_endpoint
to_ip_endpoint
(
const
sockaddr_in6
&
addr
)
{
ip_endpoint
ep
;
ep
.
port
(
htons
(
addr
.
sin6_port
));
ipv6_address
ip_addr
;
memcpy
(
ip_addr
.
bytes
().
data
(),
&
addr
.
sin6_addr
,
ip_addr
.
size
());
ep
.
address
(
ip_addr
);
return
ep
;
}
}
// namespace detail
}
// namespace caf
libcaf_net/test/convert_ip_endpoint.cpp
0 → 100644
View file @
d8343bd3
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2019 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#define CAF_SUITE convert_ip_endpoint
#include "caf/detail/convert_ip_endpoint.hpp"
#include "caf/test/dsl.hpp"
#include <cstring>
#include "caf/detail/socket_sys_includes.hpp"
using
namespace
caf
;
using
namespace
caf
::
detail
;
CAF_TEST
(
sockaddr
roundtrip
)
{
sockaddr_in6
source_addr
=
{};
source_addr
.
sin6_family
=
AF_INET6
;
source_addr
.
sin6_port
=
htons
(
23
);
source_addr
.
sin6_addr
=
in6addr_loopback
;
auto
ep
=
to_ip_endpoint
(
source_addr
);
auto
dest_addr
=
to_sockaddr
(
ep
);
CAF_CHECK_EQUAL
(
memcmp
(
&
source_addr
,
&
dest_addr
,
sizeof
(
sockaddr_in6
)),
0
);
}
CAF_TEST
(
ip_endpoint
roundtrip
)
{
ip_endpoint
source_ep
;
if
(
auto
err
=
detail
::
parse
(
"[::1]:55555"
,
source_ep
))
CAF_FAIL
(
"unable to parse input: "
<<
err
);
auto
addr
=
to_sockaddr
(
source_ep
);
auto
dest_ep
=
to_ip_endpoint
(
addr
);
CAF_CHECK_EQUAL
(
source_ep
,
dest_ep
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment