summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/contrib/srvrec.cc14
-rw-r--r--apt-pkg/contrib/srvrec.h6
2 files changed, 20 insertions, 0 deletions
diff --git a/apt-pkg/contrib/srvrec.cc b/apt-pkg/contrib/srvrec.cc
index 352a56970..c473192fc 100644
--- a/apt-pkg/contrib/srvrec.cc
+++ b/apt-pkg/contrib/srvrec.cc
@@ -8,15 +8,29 @@
/*}}}*/
#include <config.h>
+#include <netdb.h>
+
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <algorithm>
+#include <apt-pkg/strutl.h>
#include <apt-pkg/error.h>
#include "srvrec.h"
+bool GetSrvRecords(std::string host, int port, std::vector<SrvRec> &Result)
+{
+ std::string target;
+ struct servent *s_ent = getservbyport(htons(port), "tcp");
+ if (s_ent == NULL)
+ return false;
+
+ strprintf(target, "_%s._tcp.%s", s_ent->s_name, host.c_str());
+ return GetSrvRecords(target, Result);
+}
+
bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result)
{
unsigned char answer[PACKETSZ];
diff --git a/apt-pkg/contrib/srvrec.h b/apt-pkg/contrib/srvrec.h
index 78d238c46..fd71e697f 100644
--- a/apt-pkg/contrib/srvrec.h
+++ b/apt-pkg/contrib/srvrec.h
@@ -26,6 +26,12 @@ class SrvRec
}
};
+/** \brief Get SRV records from host/port (builds the query string internally)
+ */
bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result);
+/** \brief Get SRV records for query string like: _http._tcp.example.com
+ */
+bool GetSrvRecords(std::string host, int port, std::vector<SrvRec> &Result);
+
#endif