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
61411cde
Commit
61411cde
authored
Aug 27, 2019
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use resolve for local addr lookup for interop
parent
aa96b5d1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
61 deletions
+12
-61
libcaf_net/caf/net/ip.hpp
libcaf_net/caf/net/ip.hpp
+0
-3
libcaf_net/src/ip.cpp
libcaf_net/src/ip.cpp
+11
-57
libcaf_net/src/tcp_accept_socket.cpp
libcaf_net/src/tcp_accept_socket.cpp
+1
-1
No files found.
libcaf_net/caf/net/ip.hpp
View file @
61411cde
...
...
@@ -30,9 +30,6 @@ namespace ip {
/// Returns the ip addresses assigned to `host`.
std
::
vector
<
ip_address
>
resolve
(
const
std
::
string
&
host
);
/// Returns the ip addresses for the local hostname.
std
::
vector
<
ip_address
>
local_addrs
(
const
std
::
string
&
host
);
/// Returns the hostname of this device.
std
::
string
hostname
();
...
...
libcaf_net/src/ip.cpp
View file @
61411cde
...
...
@@ -60,10 +60,6 @@ namespace ip {
namespace
{
constexpr
auto
v4_any_addr
=
"0.0.0.0"
;
constexpr
auto
v6_any_addr
=
"::"
;
constexpr
auto
localhost
=
"localhost"
;
template
<
class
T
>
void
*
vptr
(
T
*
ptr
)
{
return
static_cast
<
void
*>
(
ptr
);
...
...
@@ -88,20 +84,6 @@ int fetch_addr_str(bool get_ipv4, bool get_ipv6, char (&buf)[INET6_ADDRSTRLEN],
:
AF_UNSPEC
;
}
void
find_by_name
(
const
vector
<
pair
<
string
,
ip_address
>>&
interfaces
,
const
string
&
name
,
vector
<
ip_address
>&
results
)
{
for
(
auto
&
p
:
interfaces
)
if
(
p
.
first
==
name
)
results
.
push_back
(
p
.
second
);
}
void
find_by_addr
(
const
vector
<
pair
<
string
,
ip_address
>>&
interfaces
,
ip_address
addr
,
vector
<
ip_address
>&
results
)
{
for
(
auto
&
p
:
interfaces
)
if
(
p
.
second
==
addr
)
results
.
push_back
(
p
.
second
);
}
}
// namespace
std
::
vector
<
ip_address
>
resolve
(
const
std
::
string
&
host
)
{
...
...
@@ -136,47 +118,17 @@ std::vector<ip_address> resolve(const std::string& host) {
return
results
;
}
std
::
vector
<
ip_address
>
local_addrs
(
const
std
::
string
&
host
)
{
std
::
vector
<
ip_address
>
results
;
// The string is not returned by getifaddrs, let's just do that ourselves.
if
(
host
==
localhost
)
return
{
ip_address
{{
0
},
{
0x1
}},
ipv6_address
{
make_ipv4_address
(
127
,
0
,
0
,
1
)}};
if
(
host
==
v4_any_addr
||
host
==
v6_any_addr
)
return
{
ip_address
{}};
ifaddrs
*
tmp
=
nullptr
;
if
(
getifaddrs
(
&
tmp
)
!=
0
)
return
{};
std
::
unique_ptr
<
ifaddrs
,
decltype
(
freeifaddrs
)
*>
addrs
{
tmp
,
freeifaddrs
};
char
buffer
[
INET6_ADDRSTRLEN
];
// Unless explicitly specified we are going to skip link-local addresses.
auto
is_link_local
=
starts_with
(
host
,
"fe80:"
);
std
::
vector
<
std
::
pair
<
std
::
string
,
ip_address
>>
interfaces
;
for
(
auto
i
=
addrs
.
get
();
i
!=
nullptr
;
i
=
i
->
ifa_next
)
{
auto
family
=
fetch_addr_str
(
true
,
true
,
buffer
,
i
->
ifa_addr
);
if
(
family
!=
AF_UNSPEC
)
{
ip_address
ip
;
if
(
!
is_link_local
&&
starts_with
(
buffer
,
"fe80:"
))
{
CAF_LOG_DEBUG
(
"skipping link-local address: "
<<
buffer
);
continue
;
}
else
if
(
auto
err
=
parse
(
buffer
,
ip
))
{
CAF_LOG_ERROR
(
"could not parse into ip address "
<<
buffer
);
continue
;
}
interfaces
.
emplace_back
(
std
::
string
{
i
->
ifa_name
},
ip
);
}
}
ip_address
host_addr
;
if
(
host
.
empty
()
||
host
==
v4_any_addr
||
host
==
v6_any_addr
)
for
(
auto
&
p
:
interfaces
)
results
.
push_back
(
std
::
move
(
p
.
second
));
else
if
(
auto
err
=
parse
(
host
,
host_addr
))
find_by_name
(
interfaces
,
host
,
results
);
else
find_by_addr
(
interfaces
,
host_addr
,
results
);
return
results
;
#ifdef CAF_WINDOWS
std
::
string
hostname
()
{
TCHAR
buf
[
MAX_COMPUTERNAME_LENGTH
+
1
];
DWORD
size
=
MAX_COMPUTERNAME_LENGTH
;
GetComputerName
(
buf
,
&
size
);
return
std
::
string
{
buf
};
}
#else // CAF_WINDOWS
std
::
string
hostname
()
{
char
buf
[
HOST_NAME_MAX
+
1
];
buf
[
HOST_NAME_MAX
]
=
'\0'
;
...
...
@@ -185,6 +137,8 @@ std::string hostname() {
return
std
::
string
{
buf
};
}
#endif // CAF_WINDOWS
}
// namespace ip
}
// namespace net
}
// namespace caf
libcaf_net/src/tcp_accept_socket.cpp
View file @
61411cde
...
...
@@ -116,7 +116,7 @@ expected<tcp_accept_socket> make_accept_socket(const uri::authority_type& auth,
if
(
auto
ip
=
get_if
<
ip_address
>
(
&
auth
.
host
))
return
make_accept_socket
(
*
ip
,
auth
.
port
,
reuse_addr
);
auto
host
=
get
<
std
::
string
>
(
auth
.
host
);
auto
addrs
=
ip
::
local_addrs
(
host
);
auto
addrs
=
ip
::
resolve
(
host
);
if
(
addrs
.
empty
())
return
make_error
(
sec
::
cannot_open_port
,
"No local interface available"
,
to_string
(
auth
));
...
...
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