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
0ad9f7a5
Commit
0ad9f7a5
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
bc640bf0
Changes
3
Hide 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 @
0ad9f7a5
...
@@ -30,9 +30,6 @@ namespace ip {
...
@@ -30,9 +30,6 @@ namespace ip {
/// Returns the ip addresses assigned to `host`.
/// Returns the ip addresses assigned to `host`.
std
::
vector
<
ip_address
>
resolve
(
const
std
::
string
&
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.
/// Returns the hostname of this device.
std
::
string
hostname
();
std
::
string
hostname
();
...
...
libcaf_net/src/ip.cpp
View file @
0ad9f7a5
...
@@ -60,10 +60,6 @@ namespace ip {
...
@@ -60,10 +60,6 @@ namespace ip {
namespace
{
namespace
{
constexpr
auto
v4_any_addr
=
"0.0.0.0"
;
constexpr
auto
v6_any_addr
=
"::"
;
constexpr
auto
localhost
=
"localhost"
;
template
<
class
T
>
template
<
class
T
>
void
*
vptr
(
T
*
ptr
)
{
void
*
vptr
(
T
*
ptr
)
{
return
static_cast
<
void
*>
(
ptr
);
return
static_cast
<
void
*>
(
ptr
);
...
@@ -88,20 +84,6 @@ int fetch_addr_str(bool get_ipv4, bool get_ipv6, char (&buf)[INET6_ADDRSTRLEN],
...
@@ -88,20 +84,6 @@ int fetch_addr_str(bool get_ipv4, bool get_ipv6, char (&buf)[INET6_ADDRSTRLEN],
:
AF_UNSPEC
;
:
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
}
// namespace
std
::
vector
<
ip_address
>
resolve
(
const
std
::
string
&
host
)
{
std
::
vector
<
ip_address
>
resolve
(
const
std
::
string
&
host
)
{
...
@@ -136,47 +118,17 @@ std::vector<ip_address> resolve(const std::string& host) {
...
@@ -136,47 +118,17 @@ std::vector<ip_address> resolve(const std::string& host) {
return
results
;
return
results
;
}
}
std
::
vector
<
ip_address
>
local_addrs
(
const
std
::
string
&
host
)
{
#ifdef CAF_WINDOWS
std
::
vector
<
ip_address
>
results
;
// The string is not returned by getifaddrs, let's just do that ourselves.
std
::
string
hostname
()
{
if
(
host
==
localhost
)
TCHAR
buf
[
MAX_COMPUTERNAME_LENGTH
+
1
];
return
{
ip_address
{{
0
},
{
0x1
}},
DWORD
size
=
MAX_COMPUTERNAME_LENGTH
;
ipv6_address
{
make_ipv4_address
(
127
,
0
,
0
,
1
)}};
GetComputerName
(
buf
,
&
size
);
if
(
host
==
v4_any_addr
||
host
==
v6_any_addr
)
return
std
::
string
{
buf
};
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
;
}
}
#else // CAF_WINDOWS
std
::
string
hostname
()
{
std
::
string
hostname
()
{
char
buf
[
HOST_NAME_MAX
+
1
];
char
buf
[
HOST_NAME_MAX
+
1
];
buf
[
HOST_NAME_MAX
]
=
'\0'
;
buf
[
HOST_NAME_MAX
]
=
'\0'
;
...
@@ -185,6 +137,8 @@ std::string hostname() {
...
@@ -185,6 +137,8 @@ std::string hostname() {
return
std
::
string
{
buf
};
return
std
::
string
{
buf
};
}
}
#endif // CAF_WINDOWS
}
// namespace ip
}
// namespace ip
}
// namespace net
}
// namespace net
}
// namespace caf
}
// namespace caf
libcaf_net/src/tcp_accept_socket.cpp
View file @
0ad9f7a5
...
@@ -116,7 +116,7 @@ expected<tcp_accept_socket> make_accept_socket(const uri::authority_type& auth,
...
@@ -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
))
if
(
auto
ip
=
get_if
<
ip_address
>
(
&
auth
.
host
))
return
make_accept_socket
(
*
ip
,
auth
.
port
,
reuse_addr
);
return
make_accept_socket
(
*
ip
,
auth
.
port
,
reuse_addr
);
auto
host
=
get
<
std
::
string
>
(
auth
.
host
);
auto
host
=
get
<
std
::
string
>
(
auth
.
host
);
auto
addrs
=
ip
::
local_addrs
(
host
);
auto
addrs
=
ip
::
resolve
(
host
);
if
(
addrs
.
empty
())
if
(
addrs
.
empty
())
return
make_error
(
sec
::
cannot_open_port
,
"No local interface available"
,
return
make_error
(
sec
::
cannot_open_port
,
"No local interface available"
,
to_string
(
auth
));
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