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
69a65227
Unverified
Commit
69a65227
authored
Feb 05, 2019
by
Luca Boccassi
Committed by
GitHub
Feb 05, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3386 from sigiesec/remove-locale-dependency
Problem: tcp address strings are dependent on locale
parents
14da2ab6
74d62bb9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
13 deletions
+49
-13
tcp_address.cpp
src/tcp_address.cpp
+49
-13
No files found.
src/tcp_address.cpp
View file @
69a65227
...
...
@@ -29,7 +29,6 @@
#include "precompiled.hpp"
#include <string>
#include <sstream>
#include "macros.hpp"
#include "tcp_address.hpp"
...
...
@@ -113,6 +112,27 @@ int zmq::tcp_address_t::resolve (const char *name_, bool local_, bool ipv6_)
return
resolver
.
resolve
(
&
_address
,
name_
);
}
template
<
size_t
N1
,
size_t
N2
>
static
std
::
string
make_address_string
(
const
char
*
hbuf
,
uint16_t
port
,
const
char
(
&
ipv6_prefix
)[
N1
],
const
char
(
&
ipv6_suffix
)[
N2
])
{
const
size_t
max_port_str_length
=
5
;
char
buf
[
NI_MAXHOST
+
sizeof
ipv6_prefix
+
sizeof
ipv6_suffix
+
max_port_str_length
];
char
*
pos
=
buf
;
memcpy
(
pos
,
ipv6_prefix
,
sizeof
ipv6_prefix
-
1
);
pos
+=
sizeof
ipv6_prefix
-
1
;
const
int
hbuf_len
=
strlen
(
hbuf
);
memcpy
(
pos
,
hbuf
,
hbuf_len
);
pos
+=
hbuf_len
;
memcpy
(
pos
,
ipv6_suffix
,
sizeof
ipv6_suffix
-
1
);
pos
+=
sizeof
ipv6_suffix
-
1
;
pos
+=
sprintf
(
pos
,
"%d"
,
ntohs
(
port
));
return
std
::
string
(
buf
,
pos
-
buf
);
}
int
zmq
::
tcp_address_t
::
to_string
(
std
::
string
&
addr_
)
const
{
if
(
_address
.
family
()
!=
AF_INET
&&
_address
.
family
()
!=
AF_INET6
)
{
...
...
@@ -130,14 +150,16 @@ int zmq::tcp_address_t::to_string (std::string &addr_) const
return
rc
;
}
const
char
ipv4_prefix
[]
=
"tcp://"
;
const
char
ipv4_suffix
[]
=
":"
;
const
char
ipv6_prefix
[]
=
"tcp://["
;
const
char
ipv6_suffix
[]
=
"]:"
;
if
(
_address
.
family
()
==
AF_INET6
)
{
std
::
stringstream
s
;
s
<<
"tcp://["
<<
hbuf
<<
"]:"
<<
ntohs
(
_address
.
ipv6
.
sin6_port
);
addr_
=
s
.
str
();
addr_
=
make_address_string
(
hbuf
,
_address
.
ipv6
.
sin6_port
,
ipv6_prefix
,
ipv6_suffix
);
}
else
{
std
::
stringstream
s
;
s
<<
"tcp://"
<<
hbuf
<<
":"
<<
ntohs
(
_address
.
ipv4
.
sin_port
);
addr_
=
s
.
str
();
addr_
=
make_address_string
(
hbuf
,
_address
.
ipv4
.
sin_port
,
ipv4_prefix
,
ipv4_suffix
);
}
return
0
;
}
...
...
@@ -263,15 +285,29 @@ int zmq::tcp_address_mask_t::to_string (std::string &addr_) const
return
rc
;
}
const
size_t
max_mask_len
=
4
;
const
char
ipv6_prefix
[]
=
"["
;
const
char
ipv6_suffix
[]
=
"]/"
;
const
char
ipv4_suffix
[]
=
"/"
;
char
buf
[
NI_MAXHOST
+
sizeof
ipv6_prefix
+
sizeof
ipv6_suffix
+
max_mask_len
];
char
*
pos
=
buf
;
if
(
_network_address
.
family
()
==
AF_INET6
)
{
memcpy
(
pos
,
ipv6_prefix
,
sizeof
ipv6_prefix
-
1
);
pos
+=
sizeof
ipv6_prefix
-
1
;
}
const
int
hbuf_len
=
strlen
(
hbuf
);
memcpy
(
pos
,
hbuf
,
hbuf_len
);
pos
+=
hbuf_len
;
if
(
_network_address
.
family
()
==
AF_INET6
)
{
std
::
stringstream
s
;
s
<<
"["
<<
hbuf
<<
"]/"
<<
_address_mask
;
addr_
=
s
.
str
();
memcpy
(
pos
,
ipv6_suffix
,
sizeof
ipv6_suffix
-
1
);
pos
+=
sizeof
ipv6_suffix
-
1
;
}
else
{
std
::
stringstream
s
;
s
<<
hbuf
<<
"/"
<<
_address_mask
;
addr_
=
s
.
str
();
memcpy
(
pos
,
ipv4_suffix
,
sizeof
ipv4_suffix
-
1
);
pos
+=
sizeof
ipv4_suffix
-
1
;
}
pos
+=
sprintf
(
pos
,
"%d"
,
_address_mask
);
addr_
.
assign
(
buf
,
pos
-
buf
);
return
0
;
}
...
...
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