UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
sockaddr.hpp
Go to the documentation of this file.
1#ifndef UPnPsdk_NET_SOCKADDR_HPP
2#define UPnPsdk_NET_SOCKADDR_HPP
3// Copyright (C) 2022+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
4// Redistribution only with this Copyright remark. Last modified: 2025-03-18
11#include <UPnPsdk/port.hpp>
12#include <UPnPsdk/port_sock.hpp>
14#ifdef _MSC_VER
15#include <afunix.h>
16#else
17#include <sys/un.h>
18#endif
19
20#include <string>
22
23namespace UPnPsdk {
24
35 ::sockaddr_storage ss;
36 ::sockaddr_un sun;
37 ::sockaddr_in6 sin6;
38 ::sockaddr_in sin;
39 ::sockaddr sa;
40};
41
42
67void split_addr_port( //
70 const std::string& a_addr_str,
73 std::string& a_addr,
75 std::string& a_serv);
76
77
94struct UPnPsdk_API SSockaddr {
96 sockaddr_storage& ss = m_sa_union.ss;
98 sockaddr_un& sun = m_sa_union.sun;
100 sockaddr_in6& sin6 = m_sa_union.sin6;
102 sockaddr_in& sin = m_sa_union.sin;
104 sockaddr& sa = m_sa_union.sa;
105
106 // Constructor
107 // -----------
108 SSockaddr();
109
110 // Destructor
111 // ----------
112 virtual ~SSockaddr();
113
114 // Get reference to the sockaddr_storage structure.
115 // Only as example, I don't use it because it may be confusing. I only use
116 // SSockaddr::ss (instantiated e.g. ssObj.ss) to access the trivial
117 // member structure.
118 // operator const ::sockaddr_storage&() const;
119
120 // Copy constructor
129 SSockaddr(const SSockaddr&);
130
131
132 // Copy assignment operator
139 // Strong exception guarantee with value argument as given.
140 SSockaddr& operator=(SSockaddr); // value argument
141
142
146 // Assignment operator to set a netaddress
147 // ---------------------------------------
190 void operator=(
192 const std::string& a_addr_str); // noexept?
193
194
195 // Assignment operator= to set socket port from an integer
196 // -------------------------------------------------------
203 void operator=(const in_port_t a_port);
204
205
206 // Assignment operator= to set socket address from a trivial socket address
207 // structure
208 // ------------------------------------------------------------------------
216 void operator=(const ::sockaddr_storage& a_ss);
218
219
223 // Compare operator
224 // ----------------
232 bool operator==(const SSockaddr&) const;
233
234
235 // Getter for a netaddress
236 // -----------------------
244 const std::string netaddr() noexcept;
245
246
247 // Getter for a netaddress with port
248 // ---------------------------------
255 const std::string netaddrp() noexcept;
256
257
259 // ----------------------------
260 in_port_t port() const;
261
262
264 // ----------------------------------------------------------------------
265 socklen_t sizeof_saddr() const;
267
268
270 // -------------------------------------------------------
271 bool is_loopback() const;
272
273
274 private:
275 sockaddr_t m_sa_union{}; // this is the union of trivial sockaddr structures
276 // that is managed.
277};
278
279
280// Getter of the netaddress to output stream
281// -----------------------------------------
291UPnPsdk_API ::std::ostream& operator<<(::std::ostream& os, SSockaddr& saddr);
292
293} // namespace UPnPsdk
294
295#endif // UPnPsdk_NET_SOCKADDR_HPP
Helpful union of the different socket address structures.
Definition sockaddr.hpp:34
void split_addr_port(const std::string &a_addr_str, std::string &a_addr, std::string &a_serv)
Free function to split inet address and port(service)
Definition sockaddr.cpp:210
UPnPsdk_API::std::ostream & operator<<(::std::ostream &os, SSockaddr &saddr)
output the netaddress
Reengineered Object Oriented UPnP+ program code.
Specifications to be portable between different platforms.
Specifications to be portable with sockets between different platforms.
Trivial ::sockaddr structures enhanced with methods.
Definition sockaddr.hpp:94
sockaddr_storage & ss
Reference to sockaddr_storage struct.
Definition sockaddr.hpp:96
Macros to support visibility of external symbols.