SNode.C
Loading...
Searching...
No Matches
net::in6::SocketAddrInfo Class Reference

#include <SocketAddrInfo.h>

Collaboration diagram for net::in6::SocketAddrInfo:

Public Member Functions

 SocketAddrInfo ()=default
 ~SocketAddrInfo ()
int resolve (const std::string &node, const std::string &service, const addrinfo &hints)
bool useNext ()
sockaddr_in6 getSockAddr ()
std::string getCanonName ()
void logAddressInfo ()

Private Attributes

struct addrinfo * addrInfo = nullptr
struct addrinfo * currentAddrInfo = nullptr

Detailed Description

Definition at line 57 of file SocketAddrInfo.h.

Constructor & Destructor Documentation

◆ SocketAddrInfo()

net::in6::SocketAddrInfo::SocketAddrInfo ( )
default

◆ ~SocketAddrInfo()

net::in6::SocketAddrInfo::~SocketAddrInfo ( )

Definition at line 56 of file SocketAddrInfo.cpp.

56 {
57 if (addrInfo != nullptr) {
59 }
60 }
struct addrinfo * addrInfo
void freeaddrinfo(struct addrinfo *res)
Definition netdb.cpp:67

References addrInfo.

Member Function Documentation

◆ getCanonName()

std::string net::in6::SocketAddrInfo::getCanonName ( )

Definition at line 91 of file SocketAddrInfo.cpp.

91 {
92 return currentAddrInfo->ai_canonname != nullptr ? currentAddrInfo->ai_canonname : std::string{};
93 }
struct addrinfo * currentAddrInfo

References currentAddrInfo.

Referenced by net::in6::SocketAddress::init().

Here is the caller graph for this function:

◆ getSockAddr()

sockaddr_in6 net::in6::SocketAddrInfo::getSockAddr ( )

Definition at line 85 of file SocketAddrInfo.cpp.

85 {
86 return currentAddrInfo != nullptr
87 ? *reinterpret_cast<sockaddr_in6*>(currentAddrInfo->ai_addr) // cppcheck-suppress internalAstError
88 : sockaddr_in6{.sin6_family = AF_INET6, .sin6_port{}, .sin6_flowinfo{}, .sin6_addr{}, .sin6_scope_id{}};
89 }

References currentAddrInfo.

Referenced by net::in6::SocketAddress::init(), and net::in6::SocketAddress::useNext().

Here is the caller graph for this function:

◆ logAddressInfo()

void net::in6::SocketAddrInfo::logAddressInfo ( )

Definition at line 95 of file SocketAddrInfo.cpp.

95 {
96 if (currentAddrInfo != nullptr) {
97 static char hostBfr[NI_MAXHOST];
98 static char servBfr[NI_MAXSERV];
99 std::memset(hostBfr, 0, NI_MAXHOST);
100 std::memset(servBfr, 0, NI_MAXSERV);
101
103 currentAddrInfo->ai_addrlen,
104 hostBfr,
105 sizeof(hostBfr),
106 servBfr,
107 sizeof(servBfr),
108 NI_NUMERICHOST | NI_NUMERICSERV);
109
110 const struct sockaddr_in* aiAddr = reinterpret_cast<sockaddr_in*>(currentAddrInfo->ai_addr);
111
112 std::ostringstream formatted;
113 formatted << "AddressInfo:\n"
114 << " ai_next = " << currentAddrInfo->ai_next << "\n"
115 << " ai_flags = " << currentAddrInfo->ai_flags << "\n"
116 << " ai_family = " << currentAddrInfo->ai_family << " (PF_INET = " << PF_INET << ", PF_INET6 = " << PF_INET6
117 << ")\n"
118 << " ai_socktype = " << currentAddrInfo->ai_socktype << " (SOCK_STREAM = " << SOCK_STREAM
119 << ", SOCK_DGRAM = " << SOCK_DGRAM << ")\n"
120 << " ai_protocol = " << currentAddrInfo->ai_protocol << " (IPPROTO_TCP = " << IPPROTO_TCP
121 << ", IPPROTO_UDP = " << IPPROTO_UDP << ")\n"
122 << " ai_addrlen = " << currentAddrInfo->ai_addrlen << " (sockaddr_in = " << sizeof(struct sockaddr_in)
123 << ", sockaddr_in6 = " << sizeof(struct sockaddr_in6) << ")\n"
124 << " ai_addr = sin_family: " << aiAddr->sin_family << " (AF_INET = " << AF_INET
125 << ", AF_INET6 = " << AF_INET6 << ")\n"
126 << " sin_addr: " << hostBfr << "\n"
127 << " sin_port: " << servBfr;
128
129 LOG(TRACE) << formatted.str();
130 }
131 }
#define LOG(level)
Definition Logger.h:148
int getnameinfo(const sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
Definition netdb.cpp:72

References currentAddrInfo, logger::LogMessage::LogMessage(), and logger::TRACE.

Here is the call graph for this function:

◆ resolve()

int net::in6::SocketAddrInfo::resolve ( const std::string & node,
const std::string & service,
const addrinfo & hints )

Definition at line 62 of file SocketAddrInfo.cpp.

62 {
63 if (addrInfo != nullptr) {
65 addrInfo = nullptr;
66 }
67
68 int aiErrCode = 0;
69
70 if ((aiErrCode = core::system::getaddrinfo(node.c_str(), service.c_str(), &hints, &addrInfo)) == 0) {
72 }
73
74 return aiErrCode;
75 }
int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
Definition netdb.cpp:62

References addrInfo, currentAddrInfo, and core::system::getaddrinfo().

Here is the call graph for this function:

◆ useNext()

bool net::in6::SocketAddrInfo::useNext ( )

Definition at line 77 of file SocketAddrInfo.cpp.

77 {
78 if (currentAddrInfo != nullptr) {
80 }
81
82 return currentAddrInfo != nullptr;
83 }

References currentAddrInfo.

Referenced by net::in6::SocketAddress::useNext().

Here is the caller graph for this function:

Member Data Documentation

◆ addrInfo

struct addrinfo* net::in6::SocketAddrInfo::addrInfo = nullptr
private

Definition at line 72 of file SocketAddrInfo.h.

Referenced by resolve(), and ~SocketAddrInfo().

◆ currentAddrInfo

struct addrinfo* net::in6::SocketAddrInfo::currentAddrInfo = nullptr
private

Definition at line 73 of file SocketAddrInfo.h.

Referenced by getCanonName(), getSockAddr(), logAddressInfo(), resolve(), and useNext().


The documentation for this class was generated from the following files: