0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-26 23:01:04 +08:00

Add 'Peer-Address' property to connection metadata

Allows non-C/C++ based clients easy access to the peer's IP address via
zmq_msg_gets(&msg, "Peer-Address") instead of zmq_msg_get(&msg, ZMQ_SRCFD)
followed by calls to getpeername and getnameinfo
This commit is contained in:
Thomas Rodgers 2015-01-16 14:52:16 -06:00
parent 39285cb969
commit 7d224d7871
4 changed files with 11 additions and 2 deletions

1
.gitignore vendored
View File

@ -137,3 +137,4 @@ zeromq-*.tar.gz
zeromq-*.zip
core
build
test-suite.log

View File

@ -28,6 +28,7 @@ function:
Socket-Type
Identity
Resource
Peer-Address
Other properties may be defined based on the underlying security, see ZAP
auththenticated connection sample below.

View File

@ -671,7 +671,7 @@ bool zmq::stream_engine_t::handshake ()
options.mechanism == ZMQ_GSSAPI? "GSSAPI":
"OTHER",
mechanism);
error (protocol_error);
return false;
}
@ -806,6 +806,11 @@ void zmq::stream_engine_t::mechanism_ready ()
properties_t properties;
properties_t::const_iterator it;
// If we have a peer_address, add it to metadata
if (!peer_address.empty()) {
properties.insert(std::make_pair("Peer-Address", peer_address));
}
// Add ZAP properties.
const properties_t& zap_properties = mechanism->get_zap_properties ();
it = zap_properties.begin ();

View File

@ -41,7 +41,7 @@ zap_handler (void *handler)
assert (streq (version, "1.0"));
assert (streq (mechanism, "NULL"));
s_sendmore (handler, version);
s_sendmore (handler, sequence);
if (streq (domain, "DOMAIN")) {
@ -100,6 +100,8 @@ int main (void)
assert (streq (zmq_msg_gets (&msg, "Hello"), "World"));
assert (streq (zmq_msg_gets (&msg, "Socket-Type"), "DEALER"));
assert (streq (zmq_msg_gets (&msg, "User-Id"), "anonymous"));
assert (streq (zmq_msg_gets (&msg, "Peer-Address"), "127.0.0.1"));
assert (zmq_msg_gets (&msg, "No Such") == NULL);
assert (zmq_errno () == EINVAL);
zmq_msg_close (&msg);