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
886553e2
Commit
886553e2
authored
Aug 28, 2019
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup ip resovle
parent
d44b4acc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
25 deletions
+18
-25
libcaf_net/caf/net/ip.hpp
libcaf_net/caf/net/ip.hpp
+1
-1
libcaf_net/src/ip.cpp
libcaf_net/src/ip.cpp
+7
-21
libcaf_net/test/ip.cpp
libcaf_net/test/ip.cpp
+10
-3
No files found.
libcaf_net/caf/net/ip.hpp
View file @
886553e2
...
...
@@ -5,7 +5,7 @@
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-201
8
Dominik Charousset *
* Copyright 2011-201
9
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 *
...
...
libcaf_net/src/ip.cpp
View file @
886553e2
...
...
@@ -5,7 +5,7 @@
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-201
8
Dominik Charousset *
* Copyright 2011-201
9
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 *
...
...
@@ -34,12 +34,14 @@
# define _WIN32_WINNT 0x0600
# endif
# include <iphlpapi.h>
# include <winsock.h>
#else
# include <sys/types.h>
# include <arpa/inet.h>
# include <net/if.h>
# include <netdb.h>
# include <ifaddrs.h>
# include <sys/ioctl.h>
# include <sys/types.h>
#endif
// clang-format on
...
...
@@ -63,14 +65,12 @@ void* fetch_in_addr(int family, sockaddr* addr) {
return
&
reinterpret_cast
<
sockaddr_in6
*>
(
addr
)
->
sin6_addr
;
}
// TODO: Use getnameinfo instead?
int
fetch_addr_str
(
bool
get_ipv4
,
bool
get_ipv6
,
char
(
&
buf
)[
INET6_ADDRSTRLEN
],
sockaddr
*
addr
)
{
int
fetch_addr_str
(
char
(
&
buf
)[
INET6_ADDRSTRLEN
],
sockaddr
*
addr
)
{
if
(
addr
==
nullptr
)
return
AF_UNSPEC
;
auto
family
=
addr
->
sa_family
;
auto
in_addr
=
fetch_in_addr
(
family
,
addr
);
return
(
(
family
==
AF_INET
&&
get_ipv4
)
||
(
family
==
AF_INET6
&&
get_ipv6
)
)
return
(
family
==
AF_INET
||
family
==
AF_INET6
)
&&
inet_ntop
(
family
,
in_addr
,
buf
,
INET6_ADDRSTRLEN
)
==
buf
?
family
:
AF_UNSPEC
;
...
...
@@ -93,7 +93,7 @@ std::vector<ip_address> resolve(string_view host) {
char
buffer
[
INET6_ADDRSTRLEN
];
std
::
vector
<
ip_address
>
results
;
for
(
auto
i
=
addrs
.
get
();
i
!=
nullptr
;
i
=
i
->
ai_next
)
{
auto
family
=
fetch_addr_str
(
true
,
true
,
buffer
,
i
->
ai_addr
);
auto
family
=
fetch_addr_str
(
buffer
,
i
->
ai_addr
);
if
(
family
!=
AF_UNSPEC
)
{
ip_address
ip
;
if
(
auto
err
=
parse
(
buffer
,
ip
))
...
...
@@ -110,27 +110,13 @@ std::vector<ip_address> resolve(string_view host) {
return
results
;
}
#ifdef CAF_WINDOWS
std
::
string
hostname
()
{
TCHAR
buf
[
MAX_COMPUTERNAME_LENGTH
+
1
];
DWORD
size
=
MAX_COMPUTERNAME_LENGTH
;
GetComputerName
(
buf
,
&
size
);
return
buf
;
}
#else // CAF_WINDOWS
std
::
string
hostname
()
{
char
buf
[
HOST_NAME_MAX
+
1
];
buf
[
HOST_NAME_MAX
]
=
'\0'
;
gethostname
(
buf
,
HOST_NAME_MAX
);
gethostbyname
(
buf
);
return
buf
;
}
#endif // CAF_WINDOWS
}
// namespace ip
}
// namespace net
}
// namespace caf
libcaf_net/test/ip.cpp
View file @
886553e2
...
...
@@ -20,20 +20,27 @@
#include "caf/net/ip.hpp"
#include "caf/ipv4_address.hpp"
#include "caf/ip_address.hpp"
#include "caf/test/dsl.hpp"
#include "host_fixture.hpp"
#include "caf/ip_address.hpp"
#include "caf/ipv4_address.hpp"
using
namespace
caf
;
using
namespace
caf
::
net
;
CAF_TEST_FIXTURE_SCOPE
(
ip_tests
,
host_fixture
)
CAF_TEST
(
resolve
)
{
ip_address
v4_local
{
make_ipv4_address
(
127
,
0
,
0
,
1
)};
ip_address
v6_local
{{
0
},
{
0x1
}};
auto
addrs
=
ip
::
resolve
(
"localhost"
);
CAF_CHECK
(
!
addrs
.
empty
());
auto
contains
=
[
&
](
ip_address
x
)
{
return
std
::
find
(
std
::
begin
(
addrs
),
std
::
end
(
addrs
),
x
)
!=
std
::
end
(
addrs
)
;
return
std
::
count
(
addrs
.
begin
(),
addrs
.
end
(),
x
)
>
0
;
};
CAF_CHECK
(
contains
(
v4_local
)
||
contains
(
v6_local
));
}
CAF_TEST_FIXTURE_SCOPE_END
()
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