2012-02-02 14:56:51 +01:00
|
|
|
/*
|
2016-01-28 15:07:31 +01:00
|
|
|
Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
|
2012-02-02 14:56:51 +01:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
This file is part of libzmq, the ZeroMQ core engine in C++.
|
2012-02-02 14:56:51 +01:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
libzmq is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
by the Free Software Foundation; either version 3 of the License, or
|
2012-02-02 14:56:51 +01:00
|
|
|
(at your option) any later version.
|
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
As a special exception, the Contributors give you permission to link
|
|
|
|
this library with independent modules to produce an executable,
|
|
|
|
regardless of the license terms of these independent modules, and to
|
|
|
|
copy and distribute the resulting executable under terms of your choice,
|
|
|
|
provided that you also meet, for each linked independent module, the
|
|
|
|
terms and conditions of the license of that module. An independent
|
|
|
|
module is a module which is not derived from or based on this library.
|
|
|
|
If you modify this library, you must extend this exception to your
|
|
|
|
version of the library.
|
|
|
|
|
|
|
|
libzmq is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
2012-02-02 14:56:51 +01:00
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ZMQ_ADDRESS_HPP_INCLUDED__
|
|
|
|
#define __ZMQ_ADDRESS_HPP_INCLUDED__
|
|
|
|
|
2019-02-01 10:47:31 -05:00
|
|
|
#include "fd.hpp"
|
|
|
|
|
2012-02-02 14:56:51 +01:00
|
|
|
#include <string>
|
|
|
|
|
2019-02-01 10:47:31 -05:00
|
|
|
#ifndef ZMQ_HAVE_WINDOWS
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#else
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#endif
|
|
|
|
|
2012-02-02 14:56:51 +01:00
|
|
|
namespace zmq
|
|
|
|
{
|
2018-02-01 11:46:09 +01:00
|
|
|
class ctx_t;
|
|
|
|
class tcp_address_t;
|
|
|
|
class udp_address_t;
|
2019-09-05 16:29:53 +03:00
|
|
|
class ws_address_t;
|
2019-10-19 14:46:53 +02:00
|
|
|
#if defined ZMQ_HAVE_IPC
|
2018-02-01 11:46:09 +01:00
|
|
|
class ipc_address_t;
|
2013-11-01 09:09:54 +01:00
|
|
|
#endif
|
2018-03-10 03:03:02 -08:00
|
|
|
#if defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_VXWORKS
|
2018-02-01 11:46:09 +01:00
|
|
|
class tipc_address_t;
|
2015-12-07 18:19:45 +06:00
|
|
|
#endif
|
|
|
|
#if defined ZMQ_HAVE_VMCI
|
2018-02-01 11:46:09 +01:00
|
|
|
class vmci_address_t;
|
2012-02-17 22:06:10 +00:00
|
|
|
#endif
|
2018-05-30 13:22:34 +02:00
|
|
|
|
|
|
|
namespace protocol_name
|
|
|
|
{
|
2018-08-15 13:19:59 +02:00
|
|
|
static const char inproc[] = "inproc";
|
2018-05-30 13:22:34 +02:00
|
|
|
static const char tcp[] = "tcp";
|
|
|
|
static const char udp[] = "udp";
|
2019-09-11 13:09:22 +03:00
|
|
|
#ifdef ZMQ_HAVE_WS
|
2019-07-14 13:45:07 +03:00
|
|
|
static const char ws[] = "ws";
|
2019-09-11 13:09:22 +03:00
|
|
|
#endif
|
2019-09-29 18:30:37 +03:00
|
|
|
#ifdef ZMQ_HAVE_WSS
|
|
|
|
static const char wss[] = "wss";
|
|
|
|
#endif
|
2019-10-19 14:46:53 +02:00
|
|
|
#if defined ZMQ_HAVE_IPC
|
2018-05-30 13:22:34 +02:00
|
|
|
static const char ipc[] = "ipc";
|
|
|
|
#endif
|
|
|
|
#if defined ZMQ_HAVE_TIPC
|
|
|
|
static const char tipc[] = "tipc";
|
|
|
|
#endif
|
|
|
|
#if defined ZMQ_HAVE_VMCI
|
|
|
|
static const char vmci[] = "vmci";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-02-01 11:46:09 +01:00
|
|
|
struct address_t
|
|
|
|
{
|
|
|
|
address_t (const std::string &protocol_,
|
|
|
|
const std::string &address_,
|
|
|
|
ctx_t *parent_);
|
2012-02-02 14:56:51 +01:00
|
|
|
|
2018-02-01 11:46:09 +01:00
|
|
|
~address_t ();
|
2012-02-02 14:56:51 +01:00
|
|
|
|
2018-02-01 11:46:09 +01:00
|
|
|
const std::string protocol;
|
|
|
|
const std::string address;
|
2018-02-02 17:08:52 +01:00
|
|
|
ctx_t *const parent;
|
2012-02-02 14:56:51 +01:00
|
|
|
|
2018-02-01 11:46:09 +01:00
|
|
|
// Protocol specific resolved address
|
2018-05-30 13:32:29 +02:00
|
|
|
// All members must be pointers to allow for consistent initialization
|
2018-02-01 11:46:09 +01:00
|
|
|
union
|
|
|
|
{
|
2018-05-30 13:32:29 +02:00
|
|
|
void *dummy;
|
2018-02-01 11:46:09 +01:00
|
|
|
tcp_address_t *tcp_addr;
|
|
|
|
udp_address_t *udp_addr;
|
2019-09-11 13:09:22 +03:00
|
|
|
#ifdef ZMQ_HAVE_WS
|
2019-09-05 16:29:53 +03:00
|
|
|
ws_address_t *ws_addr;
|
2019-09-11 13:09:22 +03:00
|
|
|
#endif
|
2019-10-19 14:46:53 +02:00
|
|
|
#if defined ZMQ_HAVE_IPC
|
2018-02-01 11:46:09 +01:00
|
|
|
ipc_address_t *ipc_addr;
|
2013-11-01 09:09:54 +01:00
|
|
|
#endif
|
2018-03-10 03:03:02 -08:00
|
|
|
#if defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_VXWORKS
|
2018-02-01 11:46:09 +01:00
|
|
|
tipc_address_t *tipc_addr;
|
2015-12-07 18:19:45 +06:00
|
|
|
#endif
|
|
|
|
#if defined ZMQ_HAVE_VMCI
|
2018-02-01 11:46:09 +01:00
|
|
|
vmci_address_t *vmci_addr;
|
2012-02-17 22:06:10 +00:00
|
|
|
#endif
|
2018-02-01 11:46:09 +01:00
|
|
|
} resolved;
|
2012-04-18 23:42:11 +04:00
|
|
|
|
2018-02-01 11:46:09 +01:00
|
|
|
int to_string (std::string &addr_) const;
|
|
|
|
};
|
2019-02-01 10:47:31 -05:00
|
|
|
|
|
|
|
#if defined(ZMQ_HAVE_HPUX) || defined(ZMQ_HAVE_VXWORKS) \
|
|
|
|
|| defined(ZMQ_HAVE_WINDOWS)
|
|
|
|
typedef int zmq_socklen_t;
|
|
|
|
#else
|
|
|
|
typedef socklen_t zmq_socklen_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum socket_end_t
|
|
|
|
{
|
|
|
|
socket_end_local,
|
|
|
|
socket_end_remote
|
|
|
|
};
|
|
|
|
|
|
|
|
zmq_socklen_t
|
|
|
|
get_socket_address (fd_t fd_, socket_end_t socket_end_, sockaddr_storage *ss_);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::string get_socket_name (fd_t fd_, socket_end_t socket_end_)
|
|
|
|
{
|
|
|
|
struct sockaddr_storage ss;
|
|
|
|
const zmq_socklen_t sl = get_socket_address (fd_, socket_end_, &ss);
|
|
|
|
if (sl == 0) {
|
|
|
|
return std::string ();
|
|
|
|
}
|
|
|
|
|
|
|
|
const T addr (reinterpret_cast<struct sockaddr *> (&ss), sl);
|
|
|
|
std::string address_string;
|
|
|
|
addr.to_string (address_string);
|
|
|
|
return address_string;
|
|
|
|
}
|
2012-02-02 14:56:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|