diff options
author | fuzzard <fuzzard@users.noreply.github.com> | 2023-12-08 18:48:25 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-08 18:48:25 +1000 |
commit | 38b7bcef9c99cba9687ef32054731232f2af249c (patch) | |
tree | 8593050240f6c1104e17b5f4560d8bc8d4b212e4 | |
parent | ff07dd77605fdd30c6e8fe26730b356b2b808a97 (diff) | |
parent | a2853dab480a33b439032dace6f67e5b62db61e1 (diff) |
Merge pull request #24200 from joseluismarti/DNSNameCache-host-ipv6
DNSNameCache: check hostname can be an IPv6 address
-rw-r--r-- | xbmc/network/DNSNameCache.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/xbmc/network/DNSNameCache.cpp b/xbmc/network/DNSNameCache.cpp index af2ac1ad1f..63fcfae9ed 100644 --- a/xbmc/network/DNSNameCache.cpp +++ b/xbmc/network/DNSNameCache.cpp @@ -24,6 +24,10 @@ #include <netdb.h> #include <netinet/in.h> +#if defined(TARGET_FREEBSD) +#include <sys/socket.h> +#endif + CDNSNameCache g_DNSCache; CCriticalSection CDNSNameCache::m_critical; @@ -38,18 +42,19 @@ bool CDNSNameCache::Lookup(const std::string& strHostName, std::string& strIpAdd return false; // first see if this is already an ip address - unsigned long address = inet_addr(strHostName.c_str()); + in_addr addr4; + in6_addr addr6; strIpAddress.clear(); - if (address != INADDR_NONE) + if (inet_pton(AF_INET, strHostName.c_str(), &addr4) || + inet_pton(AF_INET6, strHostName.c_str(), &addr6)) { - strIpAddress = StringUtils::Format("{}.{}.{}.{}", (address & 0xFF), (address & 0xFF00) >> 8, - (address & 0xFF0000) >> 16, (address & 0xFF000000) >> 24); + strIpAddress = strHostName; return true; } // check if there's a custom entry or if it's already cached - if(g_DNSCache.GetCached(strHostName, strIpAddress)) + if (g_DNSCache.GetCached(strHostName, strIpAddress)) return true; // perform dns lookup |