diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2019-11-29 14:40:22 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2019-11-29 14:40:22 +0300 |
commit | 3263f4b47a7145e255563aa6970d0c248f7f1ca6 (patch) | |
tree | 903482119c868de7ecfc00e47ef3dada460653ed | |
parent | b0fec477a67e299f5ba1f3943d899edc31d20f5a (diff) | |
download | apt-3263f4b47a7145e255563aa6970d0c248f7f1ca6.tar.gz |
Use appropriate getservbyport_r()
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | apt-pkg/contrib/srvrec.cc | 7 |
2 files changed, 18 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2520fd53c..384337e89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ include(Misc) include(CheckIncludeFiles) include(CheckFunctionExists) include(CheckStructHasMember) +include(CheckPrototypeDefinition) include(GNUInstallDirs) include(TestBigEndian) find_package(Threads REQUIRED) @@ -157,6 +158,17 @@ check_function_exists(ptsname_r HAVE_PTSNAME_R) check_function_exists(timegm HAVE_TIMEGM) test_big_endian(WORDS_BIGENDIAN) +check_prototype_definition(getservbyport_r +"struct servent *getservbyport_r (int port, const char * proto, struct servent *res, char *but, int buf_size)" +"NULL" +"netdb.h" +SOLARIS_GETSERVBYPORT_R +) + +if (SOLARIS_GETSERVBYPORT_R) + add_definitions(-DSOLARIS_GETSERVBYPORT_R) +endif() + # FreeBSD add_definitions(-D_WITH_GETLINE=1) diff --git a/apt-pkg/contrib/srvrec.cc b/apt-pkg/contrib/srvrec.cc index 7d9bf116e..522e8ab9c 100644 --- a/apt-pkg/contrib/srvrec.cc +++ b/apt-pkg/contrib/srvrec.cc @@ -49,10 +49,15 @@ bool GetSrvRecords(std::string host, int port, std::vector<SrvRec> &Result) struct servent *s_ent = nullptr; std::vector<char> buf(1024); +#ifdef SOLARIS_GETSERVBYPORT_R + s_ent = getservbyport_r(htons(port), "tcp", &s_ent_buf, buf.data(), buf.size()); + if (s_ent == nullptr) + return false; +#else res = getservbyport_r(htons(port), "tcp", &s_ent_buf, buf.data(), buf.size(), &s_ent); if (res != 0 || s_ent == nullptr) return false; - +#endif strprintf(target, "_%s._tcp.%s", s_ent->s_name, host.c_str()); return GetSrvRecords(target, Result); } |