/src/libzmq/src/address.hpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
72 | | const std::string protocol; |
73 | | const std::string address; |
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; |
81 | | tcp_address_t *tcp_addr; |
82 | | udp_address_t *udp_addr; |
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 | | |
110 | | enum socket_end_t |
111 | | { |
112 | | socket_end_local, |
113 | | socket_end_remote |
114 | | }; |
115 | | |
116 | | zmq_socklen_t |
117 | | get_socket_address (fd_t fd_, socket_end_t socket_end_, sockaddr_storage *ss_); |
118 | | |
119 | | template <typename T> |
120 | | std::string get_socket_name (fd_t fd_, socket_end_t socket_end_) |
121 | 221 | { |
122 | 221 | struct sockaddr_storage ss; |
123 | 221 | const zmq_socklen_t sl = get_socket_address (fd_, socket_end_, &ss); |
124 | 221 | if (sl == 0) { |
125 | 0 | return std::string (); |
126 | 0 | } |
127 | | |
128 | 221 | const T addr (reinterpret_cast<struct sockaddr *> (&ss), sl); |
129 | 221 | std::string address_string; |
130 | 221 | addr.to_string (address_string); |
131 | 221 | return address_string; |
132 | 221 | } std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > zmq::get_socket_name<zmq::tcp_address_t>(int, zmq::socket_end_t) Line | Count | Source | 121 | 4 | { | 122 | 4 | struct sockaddr_storage ss; | 123 | 4 | const zmq_socklen_t sl = get_socket_address (fd_, socket_end_, &ss); | 124 | 4 | if (sl == 0) { | 125 | 0 | return std::string (); | 126 | 0 | } | 127 | | | 128 | 4 | const T addr (reinterpret_cast<struct sockaddr *> (&ss), sl); | 129 | 4 | std::string address_string; | 130 | 4 | addr.to_string (address_string); | 131 | 4 | return address_string; | 132 | 4 | } |
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > zmq::get_socket_name<zmq::tipc_address_t>(int, zmq::socket_end_t) std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > zmq::get_socket_name<zmq::ws_address_t>(int, zmq::socket_end_t) Line | Count | Source | 121 | 176 | { | 122 | 176 | struct sockaddr_storage ss; | 123 | 176 | const zmq_socklen_t sl = get_socket_address (fd_, socket_end_, &ss); | 124 | 176 | if (sl == 0) { | 125 | 0 | return std::string (); | 126 | 0 | } | 127 | | | 128 | 176 | const T addr (reinterpret_cast<struct sockaddr *> (&ss), sl); | 129 | 176 | std::string address_string; | 130 | 176 | addr.to_string (address_string); | 131 | 176 | return address_string; | 132 | 176 | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > zmq::get_socket_name<zmq::ipc_address_t>(int, zmq::socket_end_t) Line | Count | Source | 121 | 41 | { | 122 | 41 | struct sockaddr_storage ss; | 123 | 41 | const zmq_socklen_t sl = get_socket_address (fd_, socket_end_, &ss); | 124 | 41 | if (sl == 0) { | 125 | 0 | return std::string (); | 126 | 0 | } | 127 | | | 128 | 41 | const T addr (reinterpret_cast<struct sockaddr *> (&ss), sl); | 129 | 41 | std::string address_string; | 130 | 41 | addr.to_string (address_string); | 131 | 41 | return address_string; | 132 | 41 | } |
|
133 | | } |
134 | | |
135 | | #endif |