address.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifndef __ZMQ_ADDRESS_HPP_INCLUDED__
4 #define __ZMQ_ADDRESS_HPP_INCLUDED__
5 
6 #include "fd.hpp"
7 
8 #include <string>
9 
10 #ifndef ZMQ_HAVE_WINDOWS
11 #include <sys/socket.h>
12 #else
13 #include <ws2tcpip.h>
14 #endif
15 
16 namespace zmq
17 {
18 class ctx_t;
19 class tcp_address_t;
20 class udp_address_t;
21 class ws_address_t;
22 #ifdef ZMQ_HAVE_WSS
23 class wss_address_t;
24 #endif
25 #if defined ZMQ_HAVE_IPC
26 class ipc_address_t;
27 #endif
28 #if defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_VXWORKS
29 class tipc_address_t;
30 #endif
31 #if defined ZMQ_HAVE_VMCI
32 class vmci_address_t;
33 #endif
34 
35 namespace protocol_name
36 {
37 static const char inproc[] = "inproc";
38 static const char tcp[] = "tcp";
39 static const char udp[] = "udp";
40 #ifdef ZMQ_HAVE_OPENPGM
41 static const char pgm[] = "pgm";
42 static const char epgm[] = "epgm";
43 #endif
44 #ifdef ZMQ_HAVE_NORM
45 static const char norm[] = "norm";
46 #endif
47 #ifdef ZMQ_HAVE_WS
48 static const char ws[] = "ws";
49 #endif
50 #ifdef ZMQ_HAVE_WSS
51 static const char wss[] = "wss";
52 #endif
53 #if defined ZMQ_HAVE_IPC
54 static const char ipc[] = "ipc";
55 #endif
56 #if defined ZMQ_HAVE_TIPC
57 static const char tipc[] = "tipc";
58 #endif
59 #if defined ZMQ_HAVE_VMCI
60 static const char vmci[] = "vmci";
61 #endif
62 }
63 
64 struct address_t
65 {
66  address_t (const std::string &protocol_,
67  const std::string &address_,
68  ctx_t *parent_);
69 
70  ~address_t ();
71 
74  ctx_t *const parent;
75 
76  // Protocol specific resolved address
77  // All members must be pointers to allow for consistent initialization
78  union
79  {
80  void *dummy;
83 #ifdef ZMQ_HAVE_WS
84  ws_address_t *ws_addr;
85 #endif
86 #ifdef ZMQ_HAVE_WSS
87  wss_address_t *wss_addr;
88 #endif
89 #if defined ZMQ_HAVE_IPC
90  ipc_address_t *ipc_addr;
91 #endif
92 #if defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_VXWORKS
93  tipc_address_t *tipc_addr;
94 #endif
95 #if defined ZMQ_HAVE_VMCI
96  vmci_address_t *vmci_addr;
97 #endif
98  } resolved;
99 
100  int to_string (std::string &addr_) const;
101 };
102 
103 #if defined(ZMQ_HAVE_HPUX) || defined(ZMQ_HAVE_VXWORKS) \
104  || defined(ZMQ_HAVE_WINDOWS)
105 typedef int zmq_socklen_t;
106 #else
107 typedef socklen_t zmq_socklen_t;
108 #endif
109 
111 {
114 };
115 
117 get_socket_address (fd_t fd_, socket_end_t socket_end_, sockaddr_storage *ss_);
118 
119 template <typename T>
121 {
122  struct sockaddr_storage ss;
123  const zmq_socklen_t sl = get_socket_address (fd_, socket_end_, &ss);
124  if (sl == 0) {
125  return std::string ();
126  }
127 
128  const T addr (reinterpret_cast<struct sockaddr *> (&ss), sl);
129  std::string address_string;
130  addr.to_string (address_string);
131  return address_string;
132 }
133 }
134 
135 #endif
zmq::get_socket_name
std::string get_socket_name(fd_t fd_, socket_end_t socket_end_)
Definition: address.hpp:120
zmq::protocol_name::udp
static const char udp[]
Definition: address.hpp:39
zmq::socket_end_local
@ socket_end_local
Definition: address.hpp:112
zmq::wss_address_t
Definition: wss_address.hpp:10
zmq::protocol_name::tcp
static const char tcp[]
Definition: address.hpp:38
zmq::address_t::address
const std::string address
Definition: address.hpp:73
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
zmq::address_t::resolved
union zmq::address_t::@23 resolved
T
#define T(upbtypeconst, upbtype, ctype, default_value)
zmq::socket_end_remote
@ socket_end_remote
Definition: address.hpp:113
zmq::address_t::dummy
void * dummy
Definition: address.hpp:80
zmq::fd_t
int fd_t
Definition: zmq.hpp:287
zmq::address_t::~address_t
~address_t()
Definition: address.cpp:29
zmq::udp_address_t
Definition: udp_address.hpp:17
zmq
Definition: zmq.hpp:229
zmq::tcp_address_t
Definition: tcp_address.hpp:15
zmq::address_t::protocol
const std::string protocol
Definition: address.hpp:72
zmq::get_socket_address
zmq_socklen_t get_socket_address(fd_t fd_, socket_end_t socket_end_, sockaddr_storage *ss_)
Definition: address.cpp:102
fd.hpp
zmq::protocol_name::inproc
static const char inproc[]
Definition: address.hpp:37
zmq::address_t::udp_addr
udp_address_t * udp_addr
Definition: address.hpp:82
zmq::ws_address_t
Definition: ws_address.hpp:15
zmq::address_t::to_string
int to_string(std::string &addr_) const
Definition: address.cpp:65
zmq::address_t
Definition: address.hpp:64
zmq::zmq_socklen_t
socklen_t zmq_socklen_t
Definition: address.hpp:107
zmq::address_t::address_t
address_t(const std::string &protocol_, const std::string &address_, ctx_t *parent_)
Definition: address.cpp:21
fd_t
zmq_fd_t fd_t
Definition: libzmq/tests/testutil.hpp:98
zmq::address_t::tcp_addr
tcp_address_t * tcp_addr
Definition: address.hpp:81
zmq::socket_end_t
socket_end_t
Definition: address.hpp:110
zmq::address_t::parent
ctx_t *const parent
Definition: address.hpp:74


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:47