Commit 7d224d78 authored by Thomas Rodgers's avatar Thomas Rodgers

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
parent 39285cb9
...@@ -137,3 +137,4 @@ zeromq-*.tar.gz ...@@ -137,3 +137,4 @@ zeromq-*.tar.gz
zeromq-*.zip zeromq-*.zip
core core
build build
test-suite.log
...@@ -28,6 +28,7 @@ function: ...@@ -28,6 +28,7 @@ function:
Socket-Type Socket-Type
Identity Identity
Resource Resource
Peer-Address
Other properties may be defined based on the underlying security, see ZAP Other properties may be defined based on the underlying security, see ZAP
auththenticated connection sample below. auththenticated connection sample below.
......
...@@ -671,7 +671,7 @@ bool zmq::stream_engine_t::handshake () ...@@ -671,7 +671,7 @@ bool zmq::stream_engine_t::handshake ()
options.mechanism == ZMQ_GSSAPI? "GSSAPI": options.mechanism == ZMQ_GSSAPI? "GSSAPI":
"OTHER", "OTHER",
mechanism); mechanism);
error (protocol_error); error (protocol_error);
return false; return false;
} }
...@@ -806,6 +806,11 @@ void zmq::stream_engine_t::mechanism_ready () ...@@ -806,6 +806,11 @@ void zmq::stream_engine_t::mechanism_ready ()
properties_t properties; properties_t properties;
properties_t::const_iterator it; 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. // Add ZAP properties.
const properties_t& zap_properties = mechanism->get_zap_properties (); const properties_t& zap_properties = mechanism->get_zap_properties ();
it = zap_properties.begin (); it = zap_properties.begin ();
......
...@@ -41,7 +41,7 @@ zap_handler (void *handler) ...@@ -41,7 +41,7 @@ zap_handler (void *handler)
assert (streq (version, "1.0")); assert (streq (version, "1.0"));
assert (streq (mechanism, "NULL")); assert (streq (mechanism, "NULL"));
s_sendmore (handler, version); s_sendmore (handler, version);
s_sendmore (handler, sequence); s_sendmore (handler, sequence);
if (streq (domain, "DOMAIN")) { if (streq (domain, "DOMAIN")) {
...@@ -100,6 +100,8 @@ int main (void) ...@@ -100,6 +100,8 @@ int main (void)
assert (streq (zmq_msg_gets (&msg, "Hello"), "World")); assert (streq (zmq_msg_gets (&msg, "Hello"), "World"));
assert (streq (zmq_msg_gets (&msg, "Socket-Type"), "DEALER")); assert (streq (zmq_msg_gets (&msg, "Socket-Type"), "DEALER"));
assert (streq (zmq_msg_gets (&msg, "User-Id"), "anonymous")); 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_msg_gets (&msg, "No Such") == NULL);
assert (zmq_errno () == EINVAL); assert (zmq_errno () == EINVAL);
zmq_msg_close (&msg); zmq_msg_close (&msg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment