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
adc5d769
Commit
adc5d769
authored
Jan 24, 2010
by
Martin Sustrik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IPv6 patch - part IV.
parent
fca9a215
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
7 deletions
+34
-7
ip.cpp
src/ip.cpp
+34
-7
No files found.
src/ip.cpp
View file @
adc5d769
...
@@ -177,7 +177,7 @@ static int resolve_nic_name (in_addr* addr_, char const *interface_)
...
@@ -177,7 +177,7 @@ static int resolve_nic_name (in_addr* addr_, char const *interface_)
int
zmq
::
resolve_ip_interface
(
sockaddr_storage
*
addr_
,
socklen_t
*
addr_len_
,
int
zmq
::
resolve_ip_interface
(
sockaddr_storage
*
addr_
,
socklen_t
*
addr_len_
,
char
const
*
interface_
)
char
const
*
interface_
)
{
{
// Find the
end ':'
that separates NIC name from service.
// Find the
':' at end
that separates NIC name from service.
const
char
*
delimiter
=
strrchr
(
interface_
,
':'
);
const
char
*
delimiter
=
strrchr
(
interface_
,
':'
);
if
(
!
delimiter
)
{
if
(
!
delimiter
)
{
errno
=
EINVAL
;
errno
=
EINVAL
;
...
@@ -226,28 +226,55 @@ int zmq::resolve_ip_interface (sockaddr_storage* addr_, socklen_t *addr_len_,
...
@@ -226,28 +226,55 @@ int zmq::resolve_ip_interface (sockaddr_storage* addr_, socklen_t *addr_len_,
return
0
;
return
0
;
}
}
// There's no such interface name. Assume literal address.
addrinfo
*
res
=
NULL
;
#if defined ZMQ_HAVE_WINDOWS
#if defined ZMQ_HAVE_WINDOWS
// Old versions of Windows don't support inet_pton
// Old versions of Windows don't support inet_pton
// so let's rather use inet_addr instead.
// so let's rather use inet_addr instead.
// TODO: This code obviously doesn't work for IPv6 addresses...
ip4_addr
.
sin_addr
.
S_un
.
S_addr
=
inet_addr
(
iface
.
c_str
());
ip4_addr
.
sin_addr
.
S_un
.
S_addr
=
inet_addr
(
iface
.
c_str
());
if
(
ip4_addr
.
sin_addr
.
S_un
.
S_addr
==
INADDR_NONE
)
{
if
(
ip4_addr
.
sin_addr
.
S_un
.
S_addr
==
INADDR_NONE
)
{
errno
=
ENODEV
;
errno
=
ENODEV
;
return
-
1
;
return
-
1
;
}
}
#else
#else
// There's no such interface name. Assume literal address.
rc
=
inet_pton
(
AF_INET
,
iface
.
c_str
(),
&
ip4_addr
.
sin_addr
);
// Set up the query.
if
(
rc
==
0
)
{
addrinfo
req
;
memset
(
&
req
,
0
,
sizeof
(
req
));
// We don't care about family. IPv4 is as good as IPv6.
req
.
ai_family
=
AF_UNSPEC
;
// Arbitrary, not used in the output, but avoids duplicate results.
req
.
ai_socktype
=
SOCK_STREAM
;
// Restrict hostname/service to literals to avoid any DNS lookups or
// service-name irregularity due to indeterminate socktype.
req
.
ai_flags
=
AI_PASSIVE
|
AI_NUMERICHOST
|
AI_NUMERICSERV
;
// 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
(
iface
.
c_str
(),
service
.
c_str
(),
&
req
,
&
res
);
if
(
rc
)
{
errno
=
ENODEV
;
errno
=
ENODEV
;
return
-
1
;
return
-
1
;
}
}
if
(
rc
<
0
)
return
-
1
;
// Use the first result.
out_addr
=
res
->
ai_addr
;
out_addrlen
=
res
->
ai_addrlen
;
#endif
#endif
zmq_assert
(
out_addrlen
<=
sizeof
(
*
addr_
));
zmq_assert
(
out_addrlen
<=
sizeof
(
*
addr_
));
memcpy
(
addr_
,
out_addr
,
out_addrlen
);
memcpy
(
addr_
,
out_addr
,
out_addrlen
);
*
addr_len_
=
out_addrlen
;
*
addr_len_
=
out_addrlen
;
// Cleanup getaddrinfo after copying the possibly referenced result.
if
(
res
)
freeaddrinfo
(
res
);
return
0
;
return
0
;
}
}
...
@@ -265,7 +292,7 @@ int zmq::resolve_ip_hostname (sockaddr_storage *addr_, socklen_t *addr_len_,
...
@@ -265,7 +292,7 @@ int zmq::resolve_ip_hostname (sockaddr_storage *addr_, socklen_t *addr_len_,
std
::
string
hostname
(
hostname_
,
delimiter
-
hostname_
);
std
::
string
hostname
(
hostname_
,
delimiter
-
hostname_
);
std
::
string
service
(
delimiter
+
1
);
std
::
string
service
(
delimiter
+
1
);
// Setup the query.
// Set
up the query.
addrinfo
req
;
addrinfo
req
;
memset
(
&
req
,
0
,
sizeof
(
req
));
memset
(
&
req
,
0
,
sizeof
(
req
));
...
...
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