From e1fb13bed85b6f85d0acab40a11f97d0fb414038 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Wed, 9 Nov 2016 13:30:58 +0100 Subject: [PATCH] Allow passing of service and protocol for DNS SRV requests --- simgear/io/DNSClient.cxx | 13 +++++++++++-- simgear/io/DNSClient.hxx | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/simgear/io/DNSClient.cxx b/simgear/io/DNSClient.cxx index c1c7b25f..35a599a5 100644 --- a/simgear/io/DNSClient.cxx +++ b/simgear/io/DNSClient.cxx @@ -75,6 +75,14 @@ SRVRequest::SRVRequest( const std::string & dn ) : _type = DNS_T_SRV; } +SRVRequest::SRVRequest( const std::string & dn, const string & service, const string & protocol ) : + Request(dn), + _service(service), + _protocol(protocol) +{ + _type = DNS_T_SRV; +} + static bool sortSRV( const SRVRequest::SRV_ptr a, const SRVRequest::SRV_ptr b ) { if( a->priority > b->priority ) return false; @@ -102,10 +110,11 @@ static void dnscbSRV(struct dns_ctx *ctx, struct dns_rr_srv *result, void *data) } r->setComplete(); } + void SRVRequest::submit() { - // protocol and service an already encoded in DN so pass in NULL for both - if (!dns_submit_srv(NULL, getDn().c_str(), NULL, NULL, 0, dnscbSRV, this )) { + // if service is defined, pass service and protocol + if (!dns_submit_srv(NULL, getDn().c_str(), _service.empty() ? NULL : _service.c_str(), _service.empty() ? NULL : _protocol.c_str(), 0, dnscbSRV, this )) { SG_LOG(SG_IO, SG_ALERT, "Can't submit dns request for " << getDn()); return; } diff --git a/simgear/io/DNSClient.hxx b/simgear/io/DNSClient.hxx index 2d2a4882..cdff6934 100644 --- a/simgear/io/DNSClient.hxx +++ b/simgear/io/DNSClient.hxx @@ -90,6 +90,7 @@ class SRVRequest : public Request { public: SRVRequest( const std::string & dn ); + SRVRequest( const std::string & dn, const string & service, const string & protocol ); virtual void submit(); struct SRV : SGReferenced { @@ -101,6 +102,9 @@ public: typedef SGSharedPtr SRV_ptr; typedef std::vector SRV_list; SRV_list entries; +private: + std::string _service; + std::string _protocol; }; class TXTRequest : public Request