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
59e76cee
Commit
59e76cee
authored
Apr 08, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix build on MinGW, relates #262
parent
5b07ea3e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
156 additions
and
52 deletions
+156
-52
libcaf_core/src/get_root_uuid.cpp
libcaf_core/src/get_root_uuid.cpp
+1
-1
libcaf_io/src/default_multiplexer.cpp
libcaf_io/src/default_multiplexer.cpp
+9
-4
libcaf_io/src/interfaces.cpp
libcaf_io/src/interfaces.cpp
+146
-47
No files found.
libcaf_core/src/get_root_uuid.cpp
View file @
59e76cee
...
...
@@ -177,7 +177,7 @@ void mv(std::string& lhs, const std::basic_string<WCHAR>& rhs) {
std
::
string
get_root_uuid
()
{
using
tchar_str
=
std
::
basic_string
<
TCHAR
>
;
string
uuid
;
st
d
::
st
ring
uuid
;
TCHAR
buf
[
max_drive_name
];
// temporary buffer for volume name
tchar_str
drive
=
TEXT
(
"c:
\\
"
);
// string "template" for drive specifier
// walk through legal drive letters, skipping floppies
...
...
libcaf_io/src/default_multiplexer.cpp
View file @
59e76cee
...
...
@@ -232,16 +232,16 @@ namespace network {
ccall
(
cc_zero
,
"listen() failed"
,
listen
,
listener
,
1
);
// create read-only end of the pipe
DWORD
flags
=
0
;
auto
read_fd
=
ccall
(
cc_valid_socket
,
WSASocket
,
AF_INET
,
SOCK_STREAM
,
0
,
NULL
,
0
,
flags
);
auto
read_fd
=
ccall
(
cc_valid_socket
,
"WSASocket() failed"
,
WSASocket
,
AF_INET
,
SOCK_STREAM
,
0
,
nullptr
,
0
,
flags
);
ccall
(
cc_zero
,
"connect() failed"
,
connect
,
read_fd
,
&
a
.
addr
,
int
{
sizeof
(
a
.
inaddr
)});
// get write-only end of the pipe
auto
write_fd
=
ccall
(
cc_valid_socket
,
"accept() failed"
,
accept
,
listener
,
NULL
,
NULL
);
accept
,
listener
,
nullptr
,
nullptr
);
closesocket
(
listener
);
guard
.
disable
();
return
{
read_fd
,
write_fd
}
;
return
std
::
make_pair
(
read_fd
,
write_fd
)
;
}
#endif
...
...
@@ -998,6 +998,11 @@ class socket_guard {
native_socket
m_fd
;
};
#ifdef CAF_WINDOWS
using
sa_family_t
=
short
;
using
in_port_t
=
unsigned
short
;
#endif
in_addr
&
addr_of
(
sockaddr_in
&
what
)
{
return
what
.
sin_addr
;
}
...
...
libcaf_io/src/interfaces.cpp
View file @
59e76cee
...
...
@@ -19,21 +19,35 @@
#include "caf/io/network/interfaces.hpp"
#include <netdb.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <net/if.h>
#include <unistd.h>
#include <ifaddrs.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include "caf/config.hpp"
#include <cerrno>
#include <cstdlib>
#include <cstring>
#ifdef CAF_WINDOWS
# ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
# endif
# include <iostream>
# include <winsock2.h>
# include <ws2tcpip.h>
# include <iphlpapi.h>
# pragma comment(lib, "ws2_32.lib")
# pragma comment(lib, "iphlpapi.lib")
#else
# include <net/if.h>
# include <unistd.h>
# include <netdb.h>
# include <ifaddrs.h>
# include <sys/ioctl.h>
# include <arpa/inet.h>
# include <netinet/in.h>
# include <sys/socket.h>
#endif
#include <memory>
#include "caf/detail/logging.hpp"
#include "caf/detail/get_mac_addresses.hpp"
namespace
caf
{
...
...
@@ -53,19 +67,113 @@ in_addr* fetch_in_addr(sockaddr_in* addr) {
return
&
(
addr
->
sin_addr
);
}
template
<
class
SockaddrType
,
int
Family
>
void
add_addr
(
ifaddrs
*
first
,
std
::
vector
<
std
::
string
>&
res
)
{
auto
addr
=
reinterpret_cast
<
SockaddrType
*>
(
first
->
ifa_addr
);
template
<
int
Family
,
class
SockAddr
>
void
add_addr_as_string
(
std
::
vector
<
std
::
string
>&
res
,
SockAddr
*
addr
)
{
auto
in_addr
=
fetch_in_addr
(
addr
);
char
address_buffer
[
INET6_ADDRSTRLEN
+
1
];
inet_ntop
(
Family
,
in_addr
,
address_buffer
,
INET6_ADDRSTRLEN
);
res
.
push_back
(
address_buffer
);
}
#ifdef CAF_WINDOWS
using
if_device_ptr
=
IP_ADAPTER_ADDRESSES
*
;
const
char
*
if_device_name
(
if_device_ptr
ptr
)
{
return
ptr
->
AdapterName
;
}
template
<
int
Family
>
void
add_addr
(
if_device_ptr
ptr
,
std
::
vector
<
std
::
string
>&
res
)
{
static_assert
(
Family
==
AF_INET
||
Family
==
AF_INET6
,
"invalid address family"
);
using
addr_type
=
typename
std
::
conditional
<
Family
==
AF_INET
,
sockaddr_in
*
,
sockaddr_in6
*
>::
type
;
for
(
auto
i
=
ptr
->
FirstUnicastAddress
;
i
!=
nullptr
;
i
=
i
->
Next
)
{
if
(
i
->
Address
.
lpSockaddr
->
sa_family
==
Family
)
{
auto
addr
=
reinterpret_cast
<
addr_type
>
(
i
->
Address
.
lpSockaddr
);
add_addr_as_string
<
Family
>
(
res
,
addr
);
}
}
}
template
<
class
F
>
void
for_each_device
(
bool
include_localhost
,
F
fun
)
{
ULONG
tmp_size
=
16
*
1024
;
// try 16kb buffer first
IP_ADAPTER_ADDRESSES
*
tmp
=
nullptr
;
constexpr
size_t
max_tries
=
3
;
size_t
try_nr
=
0
;
int
retval
=
0
;
do
{
if
(
tmp
!=
nullptr
)
{
free
(
tmp
);
}
tmp
=
reinterpret_cast
<
IP_ADAPTER_ADDRESSES
*>
(
malloc
(
tmp_size
));
if
(
tmp
==
nullptr
)
{
throw
std
::
bad_alloc
();
}
retval
=
GetAdaptersAddresses
(
AF_UNSPEC
,
GAA_FLAG_INCLUDE_PREFIX
,
nullptr
,
tmp
,
&
tmp_size
);
}
while
(
retval
==
ERROR_BUFFER_OVERFLOW
&&
++
try_nr
<
max_tries
);
std
::
unique_ptr
<
IP_ADAPTER_ADDRESSES
,
decltype
(
free
)
*>
ifs
{
tmp
,
free
};
if
(
retval
!=
NO_ERROR
)
{
std
::
cerr
<<
"Call to GetAdaptersAddresses failed with error: "
<<
retval
<<
std
::
endl
;
if
(
retval
==
ERROR_NO_DATA
)
{
std
::
cerr
<<
"No addresses were found for the requested parameters"
<<
std
::
endl
;
}
else
{
void
*
msgbuf
=
nullptr
;
if
(
FormatMessage
(
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
nullptr
,
retval
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
(
LPTSTR
)
&
msgbuf
,
0
,
nullptr
))
{
printf
(
"Error: %s"
,
msgbuf
);
LocalFree
(
msgbuf
);
}
}
return
;
}
for
(
auto
i
=
ifs
.
get
();
i
!=
nullptr
;
i
=
i
->
Next
)
{
fun
(
i
);
}
}
#else // ifdef CAF_WINDOWS
// interface address pointer
using
if_device_ptr
=
ifaddrs
*
;
const
char
*
if_device_name
(
if_device_ptr
ptr
)
{
return
ptr
->
ifa_name
;
}
template
<
int
Family
>
void
add_addr
(
if_device_ptr
ptr
,
std
::
vector
<
std
::
string
>&
res
)
{
static_assert
(
Family
==
AF_INET
||
Family
==
AF_INET6
,
"invalid address family"
);
using
addr_type
=
typename
std
::
conditional
<
Family
==
AF_INET
,
sockaddr_in
*
,
sockaddr_in6
*
>::
type
;
if
(
ptr
->
ifa_addr
->
sa_family
!=
Family
)
{
return
;
}
add_addr_as_string
<
Family
>
(
res
,
reinterpret_cast
<
addr_type
>
(
ptr
->
ifa_addr
));
}
template
<
class
F
>
void
for_each_device
(
bool
include_localhost
,
F
fun
)
{
char
host
[
NI_MAXHOST
];
if
addrs
*
tmp
=
nullptr
;
if
_device_ptr
tmp
=
nullptr
;
if
(
getifaddrs
(
&
tmp
)
!=
0
)
{
perror
(
"getifaddrs"
);
return
;
...
...
@@ -74,30 +182,29 @@ void for_each_device(bool include_localhost, F fun) {
for
(
auto
i
=
ifs
.
get
();
i
!=
nullptr
;
i
=
i
->
ifa_next
)
{
auto
family
=
i
->
ifa_addr
->
sa_family
;
if
(
include_localhost
)
{
fun
(
i
,
family
);
fun
(
i
);
}
else
if
(
family
==
AF_INET
||
family
==
AF_INET6
)
{
auto
len
=
static_cast
<
socklen_t
>
(
family
==
AF_INET
?
sizeof
(
sockaddr_in
)
:
sizeof
(
sockaddr_in6
));
?
sizeof
(
sockaddr_in
)
:
sizeof
(
sockaddr_in6
));
auto
ok
=
getnameinfo
(
i
->
ifa_addr
,
len
,
host
,
NI_MAXHOST
,
nullptr
,
0
,
0
);
if
(
ok
==
0
&&
strcmp
(
"localhost"
,
host
)
!=
0
)
{
fun
(
i
,
family
);
fun
(
i
);
}
}
}
}
#endif // ifdef CAF_WINDOWS
interfaces_map
interfaces
::
list_all
(
bool
include_localhost
)
{
interfaces_map
result
;
for
(
auto
&
pair
:
detail
::
get_mac_addresses
())
{
result
[
pair
.
first
][
protocol
::
ethernet
].
push_back
(
std
::
move
(
pair
.
second
));
}
for_each_device
(
include_localhost
,
[
&
](
ifaddrs
*
i
,
int
family
)
{
if
(
family
==
AF_INET
)
{
add_addr
<
sockaddr_in
,
AF_INET
>
(
i
,
result
[
i
->
ifa_name
][
protocol
::
ipv4
]);
}
else
if
(
family
==
AF_INET6
)
{
add_addr
<
sockaddr_in6
,
AF_INET6
>
(
i
,
result
[
i
->
ifa_name
][
protocol
::
ipv6
]);
}
for_each_device
(
include_localhost
,
[
&
](
if_device_ptr
i
)
{
add_addr
<
AF_INET
>
(
i
,
result
[
if_device_name
(
i
)][
protocol
::
ipv4
]);
add_addr
<
AF_INET6
>
(
i
,
result
[
if_device_name
(
i
)][
protocol
::
ipv6
]);
});
return
result
;
}
...
...
@@ -108,12 +215,9 @@ interfaces::list_addresses(bool include_localhost) {
for
(
auto
&
pair
:
detail
::
get_mac_addresses
())
{
result
[
protocol
::
ethernet
].
push_back
(
std
::
move
(
pair
.
second
));
}
for_each_device
(
include_localhost
,
[
&
](
ifaddrs
*
i
,
int
family
)
{
if
(
family
==
AF_INET
)
{
add_addr
<
sockaddr_in
,
AF_INET
>
(
i
,
result
[
protocol
::
ipv4
]);
}
else
if
(
family
==
AF_INET6
)
{
add_addr
<
sockaddr_in6
,
AF_INET6
>
(
i
,
result
[
protocol
::
ipv6
]);
}
for_each_device
(
include_localhost
,
[
&
](
if_device_ptr
i
)
{
add_addr
<
AF_INET
>
(
i
,
result
[
protocol
::
ipv4
]);
add_addr
<
AF_INET6
>
(
i
,
result
[
protocol
::
ipv6
]);
});
return
result
;
}
...
...
@@ -128,17 +232,13 @@ std::vector<std::string> interfaces::list_addresses(protocol proc,
}
break
;
case
protocol
:
:
ipv4
:
for_each_device
(
include_localhost
,
[
&
](
ifaddrs
*
i
,
int
family
)
{
if
(
family
==
AF_INET
)
{
add_addr
<
sockaddr_in
,
AF_INET
>
(
i
,
result
);
}
for_each_device
(
include_localhost
,
[
&
](
if_device_ptr
i
)
{
add_addr
<
AF_INET
>
(
i
,
result
);
});
break
;
case
protocol
:
:
ipv6
:
for_each_device
(
include_localhost
,
[
&
](
ifaddrs
*
i
,
int
family
)
{
if
(
family
==
AF_INET6
)
{
add_addr
<
sockaddr_in6
,
AF_INET6
>
(
i
,
result
);
}
for_each_device
(
include_localhost
,
[
&
](
if_device_ptr
i
)
{
add_addr
<
AF_INET6
>
(
i
,
result
);
});
break
;
}
...
...
@@ -148,7 +248,6 @@ std::vector<std::string> interfaces::list_addresses(protocol proc,
optional
<
std
::
pair
<
std
::
string
,
protocol
>>
interfaces
::
native_address
(
const
std
::
string
&
host
,
optional
<
protocol
>
preferred
)
{
CAF_LOGF_TRACE
(
CAF_ARG
(
host
)
<<
", "
<<
CAF_TSARG
(
preferred
));
addrinfo
hint
;
memset
(
&
hint
,
0
,
sizeof
(
hint
));
hint
.
ai_socktype
=
SOCK_STREAM
;
...
...
@@ -165,12 +264,12 @@ interfaces::native_address(const std::string& host,
if
(
family
==
AF_INET
||
family
==
AF_INET6
)
{
char
buffer
[
INET6_ADDRSTRLEN
];
auto
res
=
family
==
AF_INET
?
inet_ntop
(
family
,
&
reinterpret_cast
<
sockaddr_in
*>
(
i
->
ai_addr
)
->
sin_addr
,
buffer
,
sizeof
(
buffer
))
:
inet_ntop
(
family
,
&
reinterpret_cast
<
sockaddr_in6
*>
(
i
->
ai_addr
)
->
sin6_addr
,
buffer
,
sizeof
(
buffer
));
?
inet_ntop
(
family
,
&
reinterpret_cast
<
sockaddr_in
*>
(
i
->
ai_addr
)
->
sin_addr
,
buffer
,
sizeof
(
buffer
))
:
inet_ntop
(
family
,
&
reinterpret_cast
<
sockaddr_in6
*>
(
i
->
ai_addr
)
->
sin6_addr
,
buffer
,
sizeof
(
buffer
));
if
(
res
!=
nullptr
)
{
return
{{
res
,
family
==
AF_INET
?
protocol
::
ipv4
:
protocol
::
ipv6
}};
}
...
...
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