uvco 0.1
Loading...
Searching...
No Matches
uvco::AddressHandle::NtopHelper_ Struct Reference

A helper for calling inet_ntop(3). More...

Static Public Member Functions

static std::string operator() (const struct sockaddr_in &ipv4)
static std::string operator() (const struct sockaddr_in6 &ipv6)
static std::string ntop (int family, void *addr)

Detailed Description

A helper for calling inet_ntop(3).

Member Function Documentation

◆ ntop()

std::string uvco::AddressHandle::NtopHelper_::ntop ( int family,
void * addr )
static
147 {
148 std::string dst{};
149 if (family == AF_INET) {
150 dst.resize(4 * 3 + 3 + 1);
151 } else if (family == AF_INET6) {
152 dst.resize(8 * 4 + 7 + 1);
153 }
154 const char *result = inet_ntop(family, addr, dst.data(), dst.size());
155 if (result == nullptr) {
156 throw UvcoException(fmt::format("inet_ntop(): {}", std::strerror(errno)));
157 }
158 dst.resize(std::strlen(result));
159 return dst;
160}
int family() const
Family is either AF_INET or AF_INET6.
Definition name_resolution.cc:76

◆ operator()() [1/2]

std::string uvco::AddressHandle::NtopHelper_::operator() ( const struct sockaddr_in & ipv4)
static
168 {
169 return ntop(ipv4.sin_family, (void *)&ipv4.sin_addr);
170}
static std::string ntop(int family, void *addr)
Definition name_resolution.cc:147

◆ operator()() [2/2]

std::string uvco::AddressHandle::NtopHelper_::operator() ( const struct sockaddr_in6 & ipv6)
static
163 {
164 return ntop(ipv6.sin6_family, (void *)&ipv6.sin6_addr);
165}

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