mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 18:55:10 +01:00
commit
00fe56c4bf
@ -32,7 +32,7 @@ zmq::address_t::address_t (
|
|||||||
: protocol (protocol_),
|
: protocol (protocol_),
|
||||||
address (address_)
|
address (address_)
|
||||||
{
|
{
|
||||||
memset (&resolved, 0, sizeof (resolved));
|
memset (&resolved, 0, sizeof resolved);
|
||||||
}
|
}
|
||||||
|
|
||||||
zmq::address_t::~address_t ()
|
zmq::address_t::~address_t ()
|
||||||
@ -53,7 +53,8 @@ zmq::address_t::~address_t ()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined ZMQ_HAVE_TIPC
|
#if defined ZMQ_HAVE_TIPC
|
||||||
else if (protocol == "tipc") {
|
else
|
||||||
|
if (protocol == "tipc") {
|
||||||
if (resolved.tipc_addr) {
|
if (resolved.tipc_addr) {
|
||||||
delete resolved.tipc_addr;
|
delete resolved.tipc_addr;
|
||||||
resolved.tipc_addr = 0;
|
resolved.tipc_addr = 0;
|
||||||
@ -76,11 +77,11 @@ int zmq::address_t::to_string (std::string &addr_) const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined ZMQ_HAVE_TIPC
|
#if defined ZMQ_HAVE_TIPC
|
||||||
else if (protocol == "tipc") {
|
else
|
||||||
if (resolved.tipc_addr) {
|
if (protocol == "tipc") {
|
||||||
|
if (resolved.tipc_addr)
|
||||||
return resolved.tipc_addr->to_string (addr_);
|
return resolved.tipc_addr->to_string (addr_);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!protocol.empty () && !address.empty ()) {
|
if (!protocol.empty () && !address.empty ()) {
|
||||||
|
@ -28,18 +28,17 @@
|
|||||||
|
|
||||||
zmq::ipc_address_t::ipc_address_t ()
|
zmq::ipc_address_t::ipc_address_t ()
|
||||||
{
|
{
|
||||||
memset (&address, 0, sizeof (address));
|
memset (&address, 0, sizeof address);
|
||||||
}
|
}
|
||||||
|
|
||||||
zmq::ipc_address_t::ipc_address_t (const sockaddr *sa, socklen_t sa_len)
|
zmq::ipc_address_t::ipc_address_t (const sockaddr *sa, socklen_t sa_len)
|
||||||
{
|
{
|
||||||
zmq_assert (sa && sa_len > 0);
|
zmq_assert (sa && sa_len > 0);
|
||||||
|
|
||||||
memset (&address, 0, sizeof (address));
|
memset (&address, 0, sizeof address);
|
||||||
if (sa->sa_family == AF_UNIX) {
|
if (sa->sa_family == AF_UNIX)
|
||||||
memcpy(&address, sa, sa_len);
|
memcpy(&address, sa, sa_len);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
zmq::ipc_address_t::~ipc_address_t ()
|
zmq::ipc_address_t::~ipc_address_t ()
|
||||||
{
|
{
|
||||||
@ -47,7 +46,7 @@ zmq::ipc_address_t::~ipc_address_t ()
|
|||||||
|
|
||||||
int zmq::ipc_address_t::resolve (const char *path_)
|
int zmq::ipc_address_t::resolve (const char *path_)
|
||||||
{
|
{
|
||||||
if (strlen (path_) >= sizeof (address.sun_path)) {
|
if (strlen (path_) >= sizeof address.sun_path) {
|
||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -90,7 +89,7 @@ socklen_t zmq::ipc_address_t::addrlen () const
|
|||||||
{
|
{
|
||||||
if (!address.sun_path [0] && address.sun_path [1])
|
if (!address.sun_path [0] && address.sun_path [1])
|
||||||
return (socklen_t) strlen (address.sun_path + 1) + sizeof (sa_family_t) + 1;
|
return (socklen_t) strlen (address.sun_path + 1) + sizeof (sa_family_t) + 1;
|
||||||
return (socklen_t) sizeof (address);
|
return (socklen_t) sizeof address;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -116,7 +116,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
|
|||||||
(void) ipv6_;
|
(void) ipv6_;
|
||||||
|
|
||||||
// Create a socket.
|
// Create a socket.
|
||||||
int sd = open_socket (AF_INET, SOCK_DGRAM, 0);
|
const int sd = open_socket (AF_INET, SOCK_DGRAM, 0);
|
||||||
errno_assert (sd != -1);
|
errno_assert (sd != -1);
|
||||||
|
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
@ -125,7 +125,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
|
|||||||
strncpy (ifr.ifr_name, nic_, sizeof ifr.ifr_name);
|
strncpy (ifr.ifr_name, nic_, sizeof ifr.ifr_name);
|
||||||
|
|
||||||
// Fetch interface address.
|
// Fetch interface address.
|
||||||
int rc = ioctl (sd, SIOCGIFADDR, (caddr_t) &ifr, sizeof (struct ifreq));
|
const int rc = ioctl (sd, SIOCGIFADDR, (caddr_t) &ifr, sizeof ifr);
|
||||||
|
|
||||||
// Clean up.
|
// Clean up.
|
||||||
close (sd);
|
close (sd);
|
||||||
|
@ -28,18 +28,17 @@
|
|||||||
|
|
||||||
zmq::tipc_address_t::tipc_address_t ()
|
zmq::tipc_address_t::tipc_address_t ()
|
||||||
{
|
{
|
||||||
memset (&address, 0, sizeof (address));
|
memset (&address, 0, sizeof address);
|
||||||
}
|
}
|
||||||
|
|
||||||
zmq::tipc_address_t::tipc_address_t (const sockaddr *sa, socklen_t sa_len)
|
zmq::tipc_address_t::tipc_address_t (const sockaddr *sa, socklen_t sa_len)
|
||||||
{
|
{
|
||||||
zmq_assert (sa && sa_len > 0);
|
zmq_assert (sa && sa_len > 0);
|
||||||
|
|
||||||
memset (&address, 0, sizeof (address));
|
memset (&address, 0, sizeof address);
|
||||||
if (sa->sa_family == AF_TIPC) {
|
if (sa->sa_family == AF_TIPC)
|
||||||
memcpy (&address, sa, sa_len);
|
memcpy (&address, sa, sa_len);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
zmq::tipc_address_t::~tipc_address_t ()
|
zmq::tipc_address_t::~tipc_address_t ()
|
||||||
{
|
{
|
||||||
@ -47,15 +46,15 @@ zmq::tipc_address_t::~tipc_address_t ()
|
|||||||
|
|
||||||
int zmq::tipc_address_t::resolve (const char *name)
|
int zmq::tipc_address_t::resolve (const char *name)
|
||||||
{
|
{
|
||||||
int res;
|
|
||||||
unsigned int type = 0;
|
unsigned int type = 0;
|
||||||
unsigned int lower = 0;
|
unsigned int lower = 0;
|
||||||
unsigned int upper = 0;
|
unsigned int upper = 0;
|
||||||
|
|
||||||
res = sscanf(name, "{%u,%u,%u}", &type, &lower, &upper);
|
const int res = sscanf (name, "{%u,%u,%u}", &type, &lower, &upper);
|
||||||
if (res == 3)
|
if (res == 3)
|
||||||
goto nameseq;
|
goto nameseq;
|
||||||
else if (res == 2 && type > TIPC_RESERVED_TYPES) {
|
else
|
||||||
|
if (res == 2 && type > TIPC_RESERVED_TYPES) {
|
||||||
address.family = AF_TIPC;
|
address.family = AF_TIPC;
|
||||||
address.addrtype = TIPC_ADDR_NAME;
|
address.addrtype = TIPC_ADDR_NAME;
|
||||||
address.addr.name.name.type = type;
|
address.addr.name.name.type = type;
|
||||||
@ -102,8 +101,7 @@ const sockaddr *zmq::tipc_address_t::addr () const
|
|||||||
|
|
||||||
socklen_t zmq::tipc_address_t::addrlen () const
|
socklen_t zmq::tipc_address_t::addrlen () const
|
||||||
{
|
{
|
||||||
return (socklen_t) sizeof (address);
|
return (socklen_t) sizeof address;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user