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
7cfa9335
Commit
7cfa9335
authored
Dec 09, 2015
by
Sathish Yenna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing support for IPv6 link local addresses (which include % followed by the interface name)
parent
6eeef5eb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
4 deletions
+28
-4
socket_base.cpp
src/socket_base.cpp
+4
-2
tcp_address.cpp
src/tcp_address.cpp
+24
-2
No files found.
src/socket_base.cpp
View file @
7cfa9335
...
...
@@ -796,6 +796,8 @@ int zmq::socket_base_t::connect (const char *addr_)
// Do some basic sanity checks on tcp:// address syntax
// - hostname starts with digit or letter, with embedded '-' or '.'
// - IPv6 address may contain hex chars and colons.
// - IPv6 link local address may contain % followed by interface name / zone_id
// (Reference: https://tools.ietf.org/html/rfc4007)
// - IPv4 address may contain decimal digits and dots.
// - Address must end in ":port" where port is *, or numeric
// - Address may contain two parts separated by ':'
...
...
@@ -806,8 +808,8 @@ int zmq::socket_base_t::connect (const char *addr_)
check
++
;
while
(
isalnum
(
*
check
)
||
isxdigit
(
*
check
)
||
*
check
==
'.'
||
*
check
==
'-'
||
*
check
==
':'
||
*
check
==
';
'
||
*
check
==
']'
)
||
*
check
==
'.'
||
*
check
==
'-'
||
*
check
==
':'
||
*
check
==
'%
'
||
*
check
==
'
;'
||
*
check
==
'
]'
)
check
++
;
}
// Assume the worst, now look for success
...
...
src/tcp_address.cpp
View file @
7cfa9335
...
...
@@ -162,6 +162,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
&& defined ZMQ_HAVE_IFADDRS)
#include <ifaddrs.h>
#include <net/if.h>
// On these platforms, network interface name can be queried
// using getifaddrs function.
...
...
@@ -429,6 +430,23 @@ int zmq::tcp_address_t::resolve (const char *name_, bool local_, bool ipv6_, boo
addr_str
[
addr_str
.
size
()
-
1
]
==
']'
)
addr_str
=
addr_str
.
substr
(
1
,
addr_str
.
size
()
-
2
);
// Test the '%' to know if we have an interface name / zone_id in the address
// Reference: https://tools.ietf.org/html/rfc4007
std
::
size_t
pos
=
addr_str
.
rfind
(
"%"
);
uint32_t
zone_id
=
0
;
if
(
pos
!=
std
::
string
::
npos
)
{
std
::
string
if_str
=
addr_str
.
substr
(
pos
+
1
);
addr_str
=
addr_str
.
substr
(
0
,
pos
);
if
(
isalpha
(
if_str
.
at
(
0
)))
zone_id
=
if_nametoindex
(
if_str
.
c_str
());
else
zone_id
=
(
uint32_t
)
atoi
(
if_str
.
c_str
());
if
(
zone_id
==
0
)
{
errno
=
EINVAL
;
return
-
1
;
}
}
// Allow 0 specifically, to detect invalid port error in atoi if not
uint16_t
port
;
if
(
port_str
==
"*"
||
port_str
==
"0"
)
...
...
@@ -454,14 +472,18 @@ int zmq::tcp_address_t::resolve (const char *name_, bool local_, bool ipv6_, boo
// Set the port into the address structure.
if
(
is_src_
)
{
if
(
source_address
.
generic
.
sa_family
==
AF_INET6
)
if
(
source_address
.
generic
.
sa_family
==
AF_INET6
)
{
source_address
.
ipv6
.
sin6_port
=
htons
(
port
);
source_address
.
ipv6
.
sin6_scope_id
=
zone_id
;
}
else
source_address
.
ipv4
.
sin_port
=
htons
(
port
);
}
else
{
if
(
address
.
generic
.
sa_family
==
AF_INET6
)
if
(
address
.
generic
.
sa_family
==
AF_INET6
)
{
address
.
ipv6
.
sin6_port
=
htons
(
port
);
address
.
ipv6
.
sin6_scope_id
=
zone_id
;
}
else
address
.
ipv4
.
sin_port
=
htons
(
port
);
}
...
...
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