summaryrefslogtreecommitdiff
path: root/src/network/core/address.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/core/address.cpp')
-rw-r--r--src/network/core/address.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp
index 14b52faa8..6045cc98b 100644
--- a/src/network/core/address.cpp
+++ b/src/network/core/address.cpp
@@ -16,7 +16,10 @@ const char *NetworkAddress::GetHostname()
{
if (StrEmpty(this->hostname)) {
assert(this->address_length != 0);
- getnameinfo((struct sockaddr *)&this->address, this->address_length, this->hostname, sizeof(this->hostname), NULL, 0, NI_NUMERICHOST);
+ char *buf = this->hostname;
+ if (this->address.ss_family == AF_INET6) buf = strecpy(buf, "[", lastof(this->hostname));
+ getnameinfo((struct sockaddr *)&this->address, this->address_length, buf, lastof(this->hostname) - buf, NULL, 0, NI_NUMERICHOST);
+ if (this->address.ss_family == AF_INET6) strecat(buf, "]", lastof(this->hostname));
}
return this->hostname;
}
@@ -92,6 +95,14 @@ const sockaddr_storage *NetworkAddress::GetAddress()
return &this->address;
}
+bool NetworkAddress::IsFamily(int family)
+{
+ if (!this->IsResolved()) {
+ this->Resolve(family, SOCK_STREAM, AI_ADDRCONFIG, NULL, ResolveLoopProc);
+ }
+ return this->address.ss_family == family;
+}
+
bool NetworkAddress::IsInNetmask(char *netmask)
{
/* Resolve it if we didn't do it already */