UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
addrinfo.hpp
Go to the documentation of this file.
1#ifndef UPnPsdk_INCLUDE_ADDRINFO_HPP
2#define UPnPsdk_INCLUDE_ADDRINFO_HPP
3// Copyright (C) 2023+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
4// Redistribution only with this Copyright remark. Last modified: 2025-06-11
10#include <UPnPsdk/sockaddr.hpp>
11
12namespace UPnPsdk {
13
50// This is a stripped version. It is only as snapshot to get information about
51// a netaddress. There is no need to copy the object. The last full featured
52// version with copy constructor, copy asignment operator, compare operator,
53// additional getter and its unit tests can be found at Github commit
54// e2ffc0c46a2d8f15390f2816e1a18782e500fd09
56 public:
58 // -----------------------------------------------------------------------
62 std::string_view a_node,
65 std::string_view a_service,
72 const int a_flags = 0,
75 const int a_socktype = SOCK_STREAM);
76
77
80 // -------------------------------------------------------------------
84 std::string_view a_node,
91 const int a_flags = 0,
94 const int a_socktype = SOCK_STREAM);
95
97 // Destructor
98 virtual ~CAddrinfo();
99
100 // Copy constructor
101 // We cannot use the default copy constructor because there is also
102 // allocated memory for the addrinfo structure to copy. We get segfaults
103 // and program aborts. This class is not usable for copying the object.
104 CAddrinfo(const CAddrinfo&) = delete;
105
106 // Copy assignment operator
107 // Same as with the copy constructor.
108 CAddrinfo& operator=(CAddrinfo) = delete;
110
111
129 // REF:_<a_href="https://stackoverflow.com/a/8782794/5014688">Overloading_member_access_operators_->,_.*</a>
130 const ::addrinfo* operator->() const noexcept;
131
132
166 bool get_first();
167
168
185 bool get_next() noexcept;
186
187
189 void sockaddr( //
194 SSockaddr& a_saddr);
195
207 const std::string& what() const;
209
210 private:
211 // Cache the hints that are given with the constructor by the user, so we
212 // can always get identical address information from the operating system.
213 DISABLE_MSVC_WARN_4251
214 const std::string m_node;
215 const std::string m_service;
216 ENABLE_MSVC_WARN
217 addrinfo m_hints{};
218
219 // Pointer to the address information returned from systemcall
220 // ::getaddrinfo(). This pointer must be freed. That is done with the
221 // destructor. It is initialized to point to the hints so there is never a
222 // dangling pointer that may segfault. Pointing to the hints means there is
223 // no information available, e.g.
224 // if (m_res == &m_hints) { // do nothing }
225 ::addrinfo* m_res{&m_hints};
226 // This points to the current used address info. If more than one address
227 // info is available it is modified with CAddrinfo::get_next() or
228 // CAddrinfo::find().
229 ::addrinfo* m_res_current{&m_hints};
230
231 // Storage for a message in case of an error, that can be called afterwards.
232 SUPPRESS_MSVC_WARN_4251_NEXT_LINE
233 std::string m_error_msg{"Success."};
234
235 // Private method to free allocated memory for address information.
236 void free_addrinfo() noexcept;
237};
238
239} // namespace UPnPsdk
240
241#endif // UPnPsdk_INCLUDE_ADDRINFO_HPP
Get information from the operating system about an internet address.
Definition addrinfo.hpp:55
Reengineered Object Oriented UPnP+ program code.
Declaration of the Sockaddr class and some free helper functions.
Trivial ::sockaddr structures enhanced with methods.
Definition sockaddr.hpp:94
#define UPnPsdk_VIS
Prefix to export symbol for external use.