Coverage Report

Created: 2026-05-30 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libzmq/src/address.hpp
Line
Count
Source
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
#if defined ZMQ_HAVE_VSOCK
35
class vsock_address_t;
36
#endif
37
38
namespace protocol_name
39
{
40
static const char inproc[] = "inproc";
41
static const char tcp[] = "tcp";
42
static const char udp[] = "udp";
43
#ifdef ZMQ_HAVE_OPENPGM
44
static const char pgm[] = "pgm";
45
static const char epgm[] = "epgm";
46
#endif
47
#ifdef ZMQ_HAVE_NORM
48
static const char norm[] = "norm";
49
#endif
50
#ifdef ZMQ_HAVE_WS
51
static const char ws[] = "ws";
52
#endif
53
#ifdef ZMQ_HAVE_WSS
54
static const char wss[] = "wss";
55
#endif
56
#if defined ZMQ_HAVE_IPC
57
static const char ipc[] = "ipc";
58
#endif
59
#if defined ZMQ_HAVE_TIPC
60
static const char tipc[] = "tipc";
61
#endif
62
#if defined ZMQ_HAVE_VMCI
63
static const char vmci[] = "vmci";
64
#endif
65
#if defined ZMQ_HAVE_VSOCK
66
static const char vsock[] = "vsock";
67
#endif
68
}
69
70
struct address_t
71
{
72
    address_t (const std::string &protocol_,
73
               const std::string &address_,
74
               ctx_t *parent_);
75
76
    ~address_t ();
77
78
    const std::string protocol;
79
    const std::string address;
80
    ctx_t *const parent;
81
82
    //  Protocol specific resolved address
83
    //  All members must be pointers to allow for consistent initialization
84
    union
85
    {
86
        void *dummy;
87
        tcp_address_t *tcp_addr;
88
        udp_address_t *udp_addr;
89
#ifdef ZMQ_HAVE_WS
90
        ws_address_t *ws_addr;
91
#endif
92
#ifdef ZMQ_HAVE_WSS
93
        wss_address_t *wss_addr;
94
#endif
95
#if defined ZMQ_HAVE_IPC
96
        ipc_address_t *ipc_addr;
97
#endif
98
#if defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_VXWORKS
99
        tipc_address_t *tipc_addr;
100
#endif
101
#if defined ZMQ_HAVE_VMCI
102
        vmci_address_t *vmci_addr;
103
#endif
104
#if defined ZMQ_HAVE_VSOCK
105
        vsock_address_t *vsock_addr;
106
#endif
107
    } resolved;
108
109
    int to_string (std::string &addr_) const;
110
};
111
112
#if defined(ZMQ_HAVE_HPUX) || defined(ZMQ_HAVE_VXWORKS)                        \
113
  || defined(ZMQ_HAVE_WINDOWS)
114
typedef int zmq_socklen_t;
115
#else
116
typedef socklen_t zmq_socklen_t;
117
#endif
118
119
enum socket_end_t
120
{
121
    socket_end_local,
122
    socket_end_remote
123
};
124
125
zmq_socklen_t
126
get_socket_address (fd_t fd_, socket_end_t socket_end_, sockaddr_storage *ss_);
127
128
template <typename T>
129
std::string get_socket_name (fd_t fd_, socket_end_t socket_end_)
130
0
{
131
0
    struct sockaddr_storage ss;
132
0
    const zmq_socklen_t sl = get_socket_address (fd_, socket_end_, &ss);
133
0
    if (sl == 0) {
134
0
        return std::string ();
135
0
    }
136
137
0
    const T addr (reinterpret_cast<struct sockaddr *> (&ss), sl);
138
0
    std::string address_string;
139
0
    addr.to_string (address_string);
140
0
    return address_string;
141
0
}
Unexecuted instantiation: 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)
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)
Unexecuted instantiation: 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)
Unexecuted instantiation: 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)
142
}
143
144
#endif