mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-24 19:02:55 +01:00
fix(HostEntry): DNS HostEntry returns multiple entries #3303
This commit is contained in:
parent
96a645e95b
commit
11bb74a847
@ -76,6 +76,14 @@ public:
|
||||
/// for the host.
|
||||
|
||||
private:
|
||||
template <typename C>
|
||||
void removeDuplicates(C& list)
|
||||
{
|
||||
std::sort(list.begin(), list.end());
|
||||
auto last = std::unique(list.begin(), list.end());
|
||||
list.erase(last, list.end());
|
||||
}
|
||||
|
||||
std::string _name;
|
||||
AliasList _aliases;
|
||||
AddressList _addresses;
|
||||
|
@ -25,11 +25,11 @@ HostEntry::HostEntry()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
HostEntry::HostEntry(struct hostent* entry)
|
||||
{
|
||||
poco_check_ptr (entry);
|
||||
|
||||
|
||||
_name = entry->h_name;
|
||||
char** alias = entry->h_aliases;
|
||||
if (alias)
|
||||
@ -40,6 +40,8 @@ HostEntry::HostEntry(struct hostent* entry)
|
||||
++alias;
|
||||
}
|
||||
}
|
||||
removeDuplicates(_aliases);
|
||||
|
||||
char** address = entry->h_addr_list;
|
||||
if (address)
|
||||
{
|
||||
@ -49,6 +51,7 @@ HostEntry::HostEntry(struct hostent* entry)
|
||||
++address;
|
||||
}
|
||||
}
|
||||
removeDuplicates(_addresses);
|
||||
}
|
||||
|
||||
|
||||
@ -80,6 +83,7 @@ HostEntry::HostEntry(struct addrinfo* ainfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
removeDuplicates(_addresses);
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,6 +88,17 @@ void DNSTest::testHostByAddress()
|
||||
|
||||
void DNSTest::testResolve()
|
||||
{
|
||||
HostEntry he1 = DNS::hostByName("localhost");
|
||||
|
||||
auto a = he1.addresses();
|
||||
sort(a.begin(), a.end());
|
||||
auto itA = std::unique(a.begin(), a.end());
|
||||
assertTrue (itA == a.end());
|
||||
|
||||
auto b = he1.aliases();
|
||||
sort(b.begin(), b.end());
|
||||
auto itB = std::unique(b.begin(), b.end());
|
||||
assertTrue (itB == b.end());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user