mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-27 15:41:05 +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:
parent
39285cb969
commit
7d224d7871
1
.gitignore
vendored
1
.gitignore
vendored
@ -137,3 +137,4 @@ zeromq-*.tar.gz
|
||||
zeromq-*.zip
|
||||
core
|
||||
build
|
||||
test-suite.log
|
||||
|
@ -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.
|
||||
|
@ -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 ();
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user