Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 1 | From f98c12b9f04ef3a9daec822c210044095b41a0ac Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Sat, 20 Mar 2021 12:33:34 -0700 |
| 4 | Subject: [PATCH] srvrec: Keep support for older resolver |
| 5 | |
| 6 | Some C libraries e.g. musl do not implement the new res_n* APIs |
| 7 | therefore keep the old implementation as fallback and check __RES |
| 8 | version macro to determine the API level |
| 9 | |
| 10 | Upstream-Status: Submitted [https://github.com/Debian/apt/pull/129] |
| 11 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 12 | Cc: Julian Andres Klode <julian.klode@canonical.com> |
| 13 | --- |
| 14 | apt-pkg/contrib/srvrec.cc | 7 +++++++ |
| 15 | 1 file changed, 7 insertions(+) |
| 16 | |
| 17 | diff --git a/apt-pkg/contrib/srvrec.cc b/apt-pkg/contrib/srvrec.cc |
| 18 | index 4ca208273..3eb5f1d4c 100644 |
| 19 | --- a/apt-pkg/contrib/srvrec.cc |
| 20 | +++ b/apt-pkg/contrib/srvrec.cc |
| 21 | @@ -62,6 +62,7 @@ bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result) |
| 22 | unsigned char answer[PACKETSZ]; |
| 23 | int answer_len, compressed_name_len; |
| 24 | int answer_count; |
| 25 | +#if __RES >= 19991006 |
| 26 | struct __res_state res; |
| 27 | |
| 28 | if (res_ninit(&res) != 0) |
| 29 | @@ -71,6 +72,12 @@ bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result) |
| 30 | std::shared_ptr<void> guard(&res, res_nclose); |
| 31 | |
| 32 | answer_len = res_nquery(&res, name.c_str(), C_IN, T_SRV, answer, sizeof(answer)); |
| 33 | +#else |
| 34 | + if (res_init() != 0) |
| 35 | + return _error->Errno("res_init", "Failed to init resolver"); |
| 36 | + |
| 37 | + answer_len = res_query(name.c_str(), C_IN, T_SRV, answer, sizeof(answer)); |
| 38 | +#endif //__RES >= 19991006 |
| 39 | if (answer_len == -1) |
| 40 | return false; |
| 41 | if (answer_len < (int)sizeof(HEADER)) |
| 42 | -- |
| 43 | 2.31.0 |
| 44 | |