Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
93ccb5a1
Commit
93ccb5a1
authored
Nov 15, 2016
by
Constantin Rack
Committed by
GitHub
Nov 15, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2215 from Bklyn/udp-bugfix
Problem: inconsistent indentation and tabs in code
parents
5879f729
10181d76
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
130 additions
and
130 deletions
+130
-130
tcp_address.cpp
src/tcp_address.cpp
+130
-130
No files found.
src/tcp_address.cpp
View file @
93ccb5a1
...
...
@@ -240,135 +240,135 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
#include <netioapi.h>
int
zmq
::
tcp_address_t
::
get_interface_name
(
unsigned
long
index
,
char
**
dest
)
const
{
char
*
buffer
=
(
char
*
)
malloc
(
IF_MAX_STRING_SIZE
);
alloc_assert
(
buffer
);
char
*
if_name_result
=
NULL
;
char
*
buffer
=
(
char
*
)
malloc
(
IF_MAX_STRING_SIZE
);
alloc_assert
(
buffer
);
char
*
if_name_result
=
NULL
;
#ifndef ZMQ_HAVE_WINDOWS_TARGET_XP
if_name_result
=
if_indextoname
(
index
,
buffer
);
if_name_result
=
if_indextoname
(
index
,
buffer
);
#endif
if
(
if_name_result
==
NULL
)
{
free
(
buffer
);
return
-
1
;
}
*
dest
=
buffer
;
return
0
;
if
(
if_name_result
==
NULL
)
{
free
(
buffer
);
return
-
1
;
}
*
dest
=
buffer
;
return
0
;
}
int
zmq
::
tcp_address_t
::
wchar_to_utf8
(
const
WCHAR
*
src
,
char
**
dest
)
const
{
int
rc
;
int
buffer_len
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
src
,
-
1
,
NULL
,
0
,
NULL
,
0
);
char
*
buffer
=
(
char
*
)
malloc
(
buffer_len
);
alloc_assert
(
buffer
);
rc
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
src
,
-
1
,
buffer
,
buffer_len
,
NULL
,
0
);
if
(
rc
==
0
)
{
free
(
buffer
);
return
-
1
;
}
*
dest
=
buffer
;
return
0
;
int
rc
;
int
buffer_len
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
src
,
-
1
,
NULL
,
0
,
NULL
,
0
);
char
*
buffer
=
(
char
*
)
malloc
(
buffer_len
);
alloc_assert
(
buffer
);
rc
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
src
,
-
1
,
buffer
,
buffer_len
,
NULL
,
0
);
if
(
rc
==
0
)
{
free
(
buffer
);
return
-
1
;
}
*
dest
=
buffer
;
return
0
;
}
int
zmq
::
tcp_address_t
::
resolve_nic_name
(
const
char
*
nic_
,
bool
ipv6_
,
bool
is_src_
)
{
int
rc
;
bool
found
=
false
;
const
int
max_attempts
=
10
;
int
iterations
=
0
;
IP_ADAPTER_ADDRESSES
*
addresses
=
NULL
;
IP_ADAPTER_ADDRESSES
*
current_addresses
=
NULL
;
unsigned
long
out_buf_len
=
sizeof
(
IP_ADAPTER_ADDRESSES
);
do
{
addresses
=
(
IP_ADAPTER_ADDRESSES
*
)
malloc
(
out_buf_len
);
alloc_assert
(
addresses
);
rc
=
GetAdaptersAddresses
(
AF_UNSPEC
,
GAA_FLAG_SKIP_ANYCAST
|
GAA_FLAG_SKIP_MULTICAST
|
GAA_FLAG_SKIP_DNS_SERVER
,
NULL
,
addresses
,
&
out_buf_len
);
if
(
rc
==
ERROR_BUFFER_OVERFLOW
)
{
free
(
addresses
);
addresses
=
NULL
;
}
else
{
break
;
}
iterations
++
;
}
while
((
rc
==
ERROR_BUFFER_OVERFLOW
)
&&
(
iterations
<
max_attempts
));
if
(
rc
==
0
)
{
current_addresses
=
addresses
;
while
(
current_addresses
)
{
char
*
if_name
=
NULL
;
char
*
if_friendly_name
=
NULL
;
int
str_rc1
,
str_rc2
;
str_rc1
=
get_interface_name
(
current_addresses
->
IfIndex
,
&
if_name
);
str_rc2
=
wchar_to_utf8
(
current_addresses
->
FriendlyName
,
&
if_friendly_name
);
// Find a network adapter by its "name" or "friendly name"
if
(
((
str_rc1
==
0
)
&&
(
!
strcmp
(
nic_
,
if_name
)))
||
((
str_rc2
==
0
)
&&
(
!
strcmp
(
nic_
,
if_friendly_name
)))
)
{
// Iterate over all unicast addresses bound to the current network interface
IP_ADAPTER_UNICAST_ADDRESS
*
unicast_address
=
current_addresses
->
FirstUnicastAddress
;
IP_ADAPTER_UNICAST_ADDRESS
*
current_unicast_address
=
unicast_address
;
while
(
current_unicast_address
)
{
ADDRESS_FAMILY
family
=
current_unicast_address
->
Address
.
lpSockaddr
->
sa_family
;
if
(
family
==
AF_INET
||
(
ipv6_
&&
family
==
AF_INET6
)
)
{
if
(
is_src_
)
memcpy
(
&
source_address
,
current_unicast_address
->
Address
.
lpSockaddr
,
(
family
==
AF_INET
)
?
sizeof
(
struct
sockaddr_in
)
:
sizeof
(
struct
sockaddr_in6
));
else
memcpy
(
&
address
,
current_unicast_address
->
Address
.
lpSockaddr
,
(
family
==
AF_INET
)
?
sizeof
(
struct
sockaddr_in
)
:
sizeof
(
struct
sockaddr_in6
));
found
=
true
;
break
;
}
current_unicast_address
=
current_unicast_address
->
Next
;
}
if
(
found
)
break
;
}
if
(
str_rc1
==
0
)
free
(
if_name
);
if
(
str_rc2
==
0
)
free
(
if_friendly_name
);
current_addresses
=
current_addresses
->
Next
;
}
free
(
addresses
);
}
if
(
!
found
)
{
errno
=
ENODEV
;
return
-
1
;
}
return
0
;
int
rc
;
bool
found
=
false
;
const
int
max_attempts
=
10
;
int
iterations
=
0
;
IP_ADAPTER_ADDRESSES
*
addresses
=
NULL
;
IP_ADAPTER_ADDRESSES
*
current_addresses
=
NULL
;
unsigned
long
out_buf_len
=
sizeof
(
IP_ADAPTER_ADDRESSES
);
do
{
addresses
=
(
IP_ADAPTER_ADDRESSES
*
)
malloc
(
out_buf_len
);
alloc_assert
(
addresses
);
rc
=
GetAdaptersAddresses
(
AF_UNSPEC
,
GAA_FLAG_SKIP_ANYCAST
|
GAA_FLAG_SKIP_MULTICAST
|
GAA_FLAG_SKIP_DNS_SERVER
,
NULL
,
addresses
,
&
out_buf_len
);
if
(
rc
==
ERROR_BUFFER_OVERFLOW
)
{
free
(
addresses
);
addresses
=
NULL
;
}
else
{
break
;
}
iterations
++
;
}
while
((
rc
==
ERROR_BUFFER_OVERFLOW
)
&&
(
iterations
<
max_attempts
));
if
(
rc
==
0
)
{
current_addresses
=
addresses
;
while
(
current_addresses
)
{
char
*
if_name
=
NULL
;
char
*
if_friendly_name
=
NULL
;
int
str_rc1
,
str_rc2
;
str_rc1
=
get_interface_name
(
current_addresses
->
IfIndex
,
&
if_name
);
str_rc2
=
wchar_to_utf8
(
current_addresses
->
FriendlyName
,
&
if_friendly_name
);
// Find a network adapter by its "name" or "friendly name"
if
(
((
str_rc1
==
0
)
&&
(
!
strcmp
(
nic_
,
if_name
)))
||
((
str_rc2
==
0
)
&&
(
!
strcmp
(
nic_
,
if_friendly_name
)))
)
{
// Iterate over all unicast addresses bound to the current network interface
IP_ADAPTER_UNICAST_ADDRESS
*
unicast_address
=
current_addresses
->
FirstUnicastAddress
;
IP_ADAPTER_UNICAST_ADDRESS
*
current_unicast_address
=
unicast_address
;
while
(
current_unicast_address
)
{
ADDRESS_FAMILY
family
=
current_unicast_address
->
Address
.
lpSockaddr
->
sa_family
;
if
(
family
==
AF_INET
||
(
ipv6_
&&
family
==
AF_INET6
)
)
{
if
(
is_src_
)
memcpy
(
&
source_address
,
current_unicast_address
->
Address
.
lpSockaddr
,
(
family
==
AF_INET
)
?
sizeof
(
struct
sockaddr_in
)
:
sizeof
(
struct
sockaddr_in6
));
else
memcpy
(
&
address
,
current_unicast_address
->
Address
.
lpSockaddr
,
(
family
==
AF_INET
)
?
sizeof
(
struct
sockaddr_in
)
:
sizeof
(
struct
sockaddr_in6
));
found
=
true
;
break
;
}
current_unicast_address
=
current_unicast_address
->
Next
;
}
if
(
found
)
break
;
}
if
(
str_rc1
==
0
)
free
(
if_name
);
if
(
str_rc2
==
0
)
free
(
if_friendly_name
);
current_addresses
=
current_addresses
->
Next
;
}
free
(
addresses
);
}
if
(
!
found
)
{
errno
=
ENODEV
;
return
-
1
;
}
return
0
;
}
#else
...
...
@@ -459,21 +459,21 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b
// Resolve the literal address. Some of the error info is lost in case
// of error, however, there's no way to report EAI errors via errno.
rc
=
getaddrinfo
(
interface_
,
NULL
,
&
req
,
&
res
);
rc
=
getaddrinfo
(
interface_
,
NULL
,
&
req
,
&
res
);
#if defined ZMQ_HAVE_WINDOWS
// Resolve specific case on Windows platform when using IPv4 address
// with ZMQ_IPv6 socket option.
if
((
req
.
ai_family
=
AF_INET6
)
&&
(
rc
==
WSAHOST_NOT_FOUND
))
{
req
.
ai_family
=
AF_INET
;
rc
=
getaddrinfo
(
interface_
,
NULL
,
&
req
,
&
res
);
}
// Resolve specific case on Windows platform when using IPv4 address
// with ZMQ_IPv6 socket option.
if
((
req
.
ai_family
=
AF_INET6
)
&&
(
rc
==
WSAHOST_NOT_FOUND
))
{
req
.
ai_family
=
AF_INET
;
rc
=
getaddrinfo
(
interface_
,
NULL
,
&
req
,
&
res
);
}
#endif
if
(
rc
)
{
errno
=
ENODEV
;
return
-
1
;
}
if
(
rc
)
{
errno
=
ENODEV
;
return
-
1
;
}
// Use the first result.
zmq_assert
(
res
!=
NULL
);
...
...
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