Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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 Framework
Commits
969ef9ba
Commit
969ef9ba
authored
Aug 30, 2019
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add conversions for ipv4
parent
d449cbc4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
8 deletions
+52
-8
libcaf_net/caf/detail/convert_ip_endpoint.hpp
libcaf_net/caf/detail/convert_ip_endpoint.hpp
+7
-3
libcaf_net/src/convert_ip_endpoint.cpp
libcaf_net/src/convert_ip_endpoint.cpp
+21
-2
libcaf_net/test/convert_ip_endpoint.cpp
libcaf_net/test/convert_ip_endpoint.cpp
+24
-3
No files found.
libcaf_net/caf/detail/convert_ip_endpoint.hpp
View file @
969ef9ba
...
...
@@ -19,14 +19,18 @@
#pragma once
#include "caf/detail/socket_sys_includes.hpp"
#include "caf/
ip_endpoint
.hpp"
#include "caf/
fwd
.hpp"
namespace
caf
{
namespace
detail
{
sockaddr_in6
to_sockaddr
(
const
ip_endpoint
&
ep
);
sockaddr_in6
to_sockaddr
(
const
ip
v6
_endpoint
&
ep
);
ip_endpoint
to_ip_endpoint
(
const
sockaddr_in6
&
addr
);
ipv6_endpoint
to_ip_endpoint
(
const
sockaddr_in6
&
addr
);
sockaddr_in
to_sockaddr
(
const
ipv4_endpoint
&
ep
);
ipv4_endpoint
to_ip_endpoint
(
const
sockaddr_in
&
addr
);
}
// namespace detail
}
// namespace caf
libcaf_net/src/convert_ip_endpoint.cpp
View file @
969ef9ba
...
...
@@ -17,11 +17,13 @@
******************************************************************************/
#include "caf/detail/convert_ip_endpoint.hpp"
#include "caf/ipv4_endpoint.hpp"
#include "caf/ipv6_endpoint.hpp"
namespace
caf
{
namespace
detail
{
sockaddr_in6
to_sockaddr
(
const
ip_endpoint
&
ep
)
{
sockaddr_in6
to_sockaddr
(
const
ip
v6
_endpoint
&
ep
)
{
sockaddr_in6
addr
=
{};
addr
.
sin6_family
=
AF_INET6
;
addr
.
sin6_port
=
ntohs
(
ep
.
port
());
...
...
@@ -29,7 +31,7 @@ sockaddr_in6 to_sockaddr(const ip_endpoint& ep) {
return
addr
;
}
ip_endpoint
to_ip_endpoint
(
const
sockaddr_in6
&
addr
)
{
ip
v6
_endpoint
to_ip_endpoint
(
const
sockaddr_in6
&
addr
)
{
ip_endpoint
ep
;
ep
.
port
(
htons
(
addr
.
sin6_port
));
ipv6_address
ip_addr
;
...
...
@@ -38,5 +40,22 @@ ip_endpoint to_ip_endpoint(const sockaddr_in6& addr) {
return
ep
;
}
sockaddr_in
to_sockaddr
(
const
ipv4_endpoint
&
ep
)
{
sockaddr_in
addr
=
{};
addr
.
sin_family
=
AF_INET
;
addr
.
sin_port
=
ntohs
(
ep
.
port
());
memcpy
(
&
addr
.
sin_addr
,
ep
.
address
().
bytes
().
data
(),
ep
.
address
().
size
());
return
addr
;
}
ipv4_endpoint
to_ip_endpoint
(
const
sockaddr_in
&
addr
)
{
ipv4_endpoint
ep
;
ep
.
port
(
htons
(
addr
.
sin_port
));
ipv4_address
ip_addr
;
memcpy
(
ip_addr
.
bytes
().
data
(),
&
addr
.
sin_addr
,
ip_addr
.
size
());
ep
.
address
(
ip_addr
);
return
ep
;
}
}
// namespace detail
}
// namespace caf
libcaf_net/test/convert_ip_endpoint.cpp
View file @
969ef9ba
...
...
@@ -25,11 +25,13 @@
#include <cstring>
#include "caf/detail/socket_sys_includes.hpp"
#include "caf/ipv4_endpoint.hpp"
#include "caf/ipv6_endpoint.hpp"
using
namespace
caf
;
using
namespace
caf
::
detail
;
CAF_TEST
(
sockaddr
roundtrip
)
{
CAF_TEST
(
sockaddr
_in6
roundtrip
)
{
sockaddr_in6
source_addr
=
{};
source_addr
.
sin6_family
=
AF_INET6
;
source_addr
.
sin6_port
=
htons
(
23
);
...
...
@@ -39,11 +41,30 @@ CAF_TEST(sockaddr roundtrip) {
CAF_CHECK_EQUAL
(
memcmp
(
&
source_addr
,
&
dest_addr
,
sizeof
(
sockaddr_in6
)),
0
);
}
CAF_TEST
(
ip_endpoint
roundtrip
)
{
ip_endpoint
source_ep
;
CAF_TEST
(
ip
v6
_endpoint
roundtrip
)
{
ip
v6
_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
);
}
CAF_TEST
(
sockaddr_in4
roundtrip
)
{
sockaddr_in
source_addr
=
{};
source_addr
.
sin_family
=
AF_INET
;
source_addr
.
sin_port
=
htons
(
23
);
source_addr
.
sin_addr
.
s_addr
=
INADDR_LOOPBACK
;
auto
ep
=
to_ip_endpoint
(
source_addr
);
auto
dest_addr
=
to_sockaddr
(
ep
);
CAF_CHECK_EQUAL
(
memcmp
(
&
source_addr
,
&
dest_addr
,
sizeof
(
sockaddr_in
)),
0
);
}
CAF_TEST
(
ipv4_endpoint
roundtrip
)
{
ipv4_endpoint
source_ep
;
if
(
auto
err
=
detail
::
parse
(
"127.0.0.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