X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/c7609dd7a418428ffbca4c81a7950c4f53c92450..34b491e735ad47c4805e63f3b83a659b8d10262b:/apt-pkg/contrib/srvrec.cc?ds=inline diff --git a/apt-pkg/contrib/srvrec.cc b/apt-pkg/contrib/srvrec.cc index 837f2c84e..327e59937 100644 --- a/apt-pkg/contrib/srvrec.cc +++ b/apt-pkg/contrib/srvrec.cc @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -25,11 +26,22 @@ #include "srvrec.h" +bool SrvRec::operator==(SrvRec const &other) const +{ + return (std::tie(target, priority, weight, port) == + std::tie(other.target, other.priority, other.weight, other.port)); +} + bool GetSrvRecords(std::string host, int port, std::vector &Result) { std::string target; - struct servent *s_ent = getservbyport(htons(port), "tcp"); - if (s_ent == NULL) + int res; + struct servent s_ent_buf; + struct servent *s_ent = nullptr; + std::vector buf(1024); + + res = getservbyport_r(htons(port), "tcp", &s_ent_buf, buf.data(), buf.size(), &s_ent); + if (res != 0 || s_ent == nullptr) return false; strprintf(target, "_%s._tcp.%s", s_ent->s_name, host.c_str()); @@ -173,7 +185,7 @@ SrvRec PopFromSrvRecs(std::vector &Recs) [&I](SrvRec const &J) { return I->priority != J.priority; }); // clock seems random enough. - I += clock() % std::distance(I, J); + I += std::max(static_cast(0), clock()) % std::distance(I, J); SrvRec const selected = std::move(*I); Recs.erase(I);