├── LICENSE ├── README.md ├── dnsserver.go ├── dnsserver_test.go └── examples └── server └── server.go /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | Copyright 2014 Docker, Inc. 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dnsserver - a simple DNS service toolkit 2 | 3 | This provides a very basic API for programming a DNS service that serves over 4 | UDP. Single A (non-RR) records and SRV records are currently supported, 5 | although this may change in the future. 6 | 7 | ## Stability 8 | 9 | This should be considered alpha quality software and is currently not suitable 10 | for production use. 11 | 12 | ## Documentation 13 | 14 | You can find comprehensive documentation in the source comments or at the URL below: 15 | 16 | [http://godoc.org/github.com/docker/dnsserver](http://godoc.org/github.com/docker/dnsserver) 17 | 18 | ## Usage 19 | 20 | There is an example program [here](https://github.com/docker/dnsserver/blob/master/examples/server/server.go). 21 | 22 | ## Dependencies 23 | 24 | [github.com/miekg/dns](https://github.com/miekg/dns) 25 | 26 | ## License 27 | 28 | We use the Apache 2.0 License as with all public Docker projects. You can read 29 | this [here](https://github.com/docker/dnsserver/blob/master/LICENSE). 30 | 31 | ## Contribution Guidelines 32 | 33 | * Fork the project and send a pull request 34 | * Please do not modify any license or version information. 35 | * Thanks! 36 | 37 | ## Maintainer 38 | 39 | Erik Hollensbe 40 | -------------------------------------------------------------------------------- /dnsserver.go: -------------------------------------------------------------------------------- 1 | package dnsserver 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "sync" 7 | 8 | "github.com/miekg/dns" 9 | ) 10 | 11 | // Encapsulates the data segment of a SRV record. Priority and Weight are 12 | // always 0 in our SRV records. 13 | type SRVRecord struct { 14 | Port uint16 15 | Host string 16 | } 17 | 18 | func (s SRVRecord) Equal(s2 SRVRecord) bool { 19 | return s.Port == s2.Port && s.Host == s2.Host 20 | } 21 | 22 | // Struct which describes the DNS server. 23 | type DNSServer struct { 24 | Domain string // using the constructor, this will always end in a '.', making it a FQDN. 25 | aRecords map[string]net.IP // FQDN -> IP 26 | srvRecords map[string][]SRVRecord // service (e.g., _test._tcp) -> SRV 27 | aMutex sync.RWMutex // mutex for A record operations 28 | srvMutex sync.RWMutex // mutex for SRV record operations 29 | } 30 | 31 | // Create a new DNS server. Domain is an unqualified domain that will be used 32 | // as the TLD. 33 | func NewDNSServer(domain string) *DNSServer { 34 | return &DNSServer{ 35 | Domain: domain + ".", 36 | aRecords: map[string]net.IP{}, 37 | srvRecords: map[string][]SRVRecord{}, 38 | aMutex: sync.RWMutex{}, 39 | srvMutex: sync.RWMutex{}, 40 | } 41 | } 42 | 43 | // Listen for DNS requests. listenSpec is a dotted-quad + port, e.g., 44 | // 127.0.0.1:53. This function blocks and only returns when the DNS service is 45 | // no longer functioning. 46 | func (ds *DNSServer) Listen(listenSpec string) error { 47 | return dns.ListenAndServe(listenSpec, "udp", ds) 48 | } 49 | 50 | // Convenience function to ensure the fqdn is well-formed, and keeps the 51 | // set/delete interface easy. 52 | func (ds *DNSServer) qualifyHost(host string) string { 53 | return host + "." + ds.Domain 54 | } 55 | 56 | // Convenience function to ensure that SRV names are well-formed. 57 | func (ds *DNSServer) qualifySrv(service, protocol string) string { 58 | return fmt.Sprintf("_%s._%s.%s", service, protocol, ds.Domain) 59 | } 60 | 61 | // rewrites supplied host entries to use the domain this dns server manages 62 | func (ds *DNSServer) qualifySrvHosts(srvs []SRVRecord) []SRVRecord { 63 | newsrvs := []SRVRecord{} 64 | 65 | for _, srv := range srvs { 66 | newsrvs = append(newsrvs, SRVRecord{ 67 | Host: ds.qualifyHost(srv.Host), 68 | Port: srv.Port, 69 | }) 70 | } 71 | 72 | return newsrvs 73 | } 74 | 75 | // Receives a FQDN; looks up and supplies the A record. 76 | func (ds *DNSServer) GetA(fqdn string) *dns.A { 77 | ds.aMutex.RLock() 78 | defer ds.aMutex.RUnlock() 79 | val, ok := ds.aRecords[fqdn] 80 | 81 | if ok { 82 | return &dns.A{ 83 | Hdr: dns.RR_Header{ 84 | Name: fqdn, 85 | Rrtype: dns.TypeA, 86 | Class: dns.ClassINET, 87 | // 0 TTL results in UB for DNS resolvers and generally causes problems. 88 | Ttl: 1, 89 | }, 90 | A: val, 91 | } 92 | } 93 | 94 | return nil 95 | } 96 | 97 | // Sets a host to an IP. Note that this is not the FQDN, but a hostname. 98 | func (ds *DNSServer) SetA(host string, ip net.IP) { 99 | ds.aMutex.Lock() 100 | ds.aRecords[ds.qualifyHost(host)] = ip 101 | ds.aMutex.Unlock() 102 | } 103 | 104 | // Deletes a host. Note that this is not the FQDN, but a hostname. 105 | func (ds *DNSServer) DeleteA(host string) { 106 | ds.aMutex.Lock() 107 | delete(ds.aRecords, ds.qualifyHost(host)) 108 | ds.aMutex.Unlock() 109 | } 110 | 111 | // Given a service spec, looks up and returns an array of *dns.SRV objects. 112 | // These must be massaged into the []dns.RR after the fact. 113 | func (ds *DNSServer) GetSRV(spec string) []*dns.SRV { 114 | ds.srvMutex.RLock() 115 | defer ds.srvMutex.RUnlock() 116 | 117 | srv, ok := ds.srvRecords[spec] 118 | 119 | if ok { 120 | records := []*dns.SRV{} 121 | for _, record := range srv { 122 | srvRecord := &dns.SRV{ 123 | Hdr: dns.RR_Header{ 124 | Name: spec, 125 | Rrtype: dns.TypeSRV, 126 | Class: dns.ClassINET, 127 | // 0 TTL results in UB for DNS resolvers and generally causes problems. 128 | Ttl: 1, 129 | }, 130 | Priority: 0, 131 | Weight: 0, 132 | Port: record.Port, 133 | Target: record.Host, 134 | } 135 | 136 | records = append(records, srvRecord) 137 | } 138 | 139 | return records 140 | } 141 | 142 | return nil 143 | } 144 | 145 | // Sets a SRV with a service and protocol. See SRVRecord for more information 146 | // on what that requires. 147 | func (ds *DNSServer) SetSRV(service, protocol string, srvs []SRVRecord) { 148 | ds.srvMutex.Lock() 149 | ds.srvRecords[ds.qualifySrv(service, protocol)] = ds.qualifySrvHosts(srvs) 150 | ds.srvMutex.Unlock() 151 | } 152 | 153 | // Deletes a SRV record based on the service and protocol. 154 | func (ds *DNSServer) DeleteSRV(service, protocol string) { 155 | ds.srvMutex.Lock() 156 | delete(ds.srvRecords, ds.qualifySrv(service, protocol)) 157 | ds.srvMutex.Unlock() 158 | } 159 | 160 | // Main callback for miekg/dns. Collects information about the query, 161 | // constructs a response, and returns it to the connector. 162 | func (ds *DNSServer) ServeDNS(w dns.ResponseWriter, r *dns.Msg) { 163 | m := &dns.Msg{} 164 | m.SetReply(r) 165 | 166 | answers := []dns.RR{} 167 | 168 | for _, question := range r.Question { 169 | // nil records == not found 170 | switch question.Qtype { 171 | case dns.TypeA: 172 | a := ds.GetA(question.Name) 173 | if a != nil { 174 | answers = append(answers, a) 175 | } 176 | case dns.TypeSRV: 177 | srv := ds.GetSRV(question.Name) 178 | 179 | if srv != nil { 180 | for _, record := range srv { 181 | answers = append(answers, record) 182 | } 183 | } 184 | } 185 | } 186 | 187 | // If we have no answers, that means we found nothing or didn't get a query 188 | // we can reply to. Reply with no answers so we ensure the query moves on to 189 | // the next server. 190 | if len(answers) == 0 { 191 | m.SetRcode(r, dns.RcodeSuccess) 192 | w.WriteMsg(m) 193 | return 194 | } 195 | 196 | // Without these the glibc resolver gets very angry. 197 | m.Authoritative = true 198 | m.RecursionAvailable = true 199 | m.Answer = answers 200 | 201 | w.WriteMsg(m) 202 | } 203 | -------------------------------------------------------------------------------- /dnsserver_test.go: -------------------------------------------------------------------------------- 1 | package dnsserver 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "testing" 7 | 8 | "github.com/miekg/dns" 9 | ) 10 | 11 | // 53 could be in use by a local cache or w/e. 5353 is in use by avahi mDNS on 12 | // my machine. Basically I don't want to have to write a port allocator. 13 | const service = "127.0.0.1:5300" 14 | 15 | var server = NewDNSServer("docker") 16 | 17 | func init() { 18 | go func() { 19 | err := server.Listen(service) 20 | if err != nil { 21 | panic(err) 22 | } 23 | }() 24 | } 25 | 26 | func msgClient(fqdn string, dnsType uint16) (*dns.Msg, error) { 27 | m := new(dns.Msg) 28 | m.SetQuestion(fqdn, dnsType) 29 | return dns.Exchange(m, service) 30 | } 31 | 32 | func TestARecordCRUD(t *testing.T) { 33 | table := map[string]net.IP{ 34 | "test": net.ParseIP("127.0.0.2"), 35 | "test2": net.ParseIP("127.0.0.3"), 36 | } 37 | 38 | // do this in independent parts so both records exist. This tests some 39 | // collision issues. 40 | for host, ip := range table { 41 | server.SetA(host, ip) 42 | } 43 | 44 | for host, ip := range table { 45 | msg, err := msgClient(fmt.Sprintf("%s.docker.", host), dns.TypeA) 46 | 47 | if err != nil { 48 | t.Fatal(err) 49 | } 50 | 51 | if len(msg.Answer) != 1 { 52 | t.Fatalf("Server did not reply with a valid answer.") 53 | } 54 | 55 | if msg.Answer[0].Header().Ttl != 1 { 56 | t.Fatalf("TTL was %d instead of 1", msg.Answer[0].Header().Ttl) 57 | } 58 | 59 | if msg.Answer[0].Header().Rrtype != dns.TypeA { 60 | t.Fatalf("Expected A record, got a record of type %d instead.", msg.Answer[0].Header().Rrtype) 61 | } 62 | 63 | if msg.Answer[0].Header().Name != fmt.Sprintf("%s.docker.", host) { 64 | // If this fails, we probably need to look at miekg/dns as this should 65 | // not be possible. 66 | t.Fatalf("Name does not match query sent, %q was provided", msg.Answer[0].Header().Name) 67 | } 68 | 69 | aRecord := msg.Answer[0].(*dns.A).A 70 | if !aRecord.Equal(ip) { 71 | t.Fatalf("IP %q does not match registered IP %q", aRecord, ip) 72 | } 73 | } 74 | 75 | for host := range table { 76 | server.DeleteA(host) 77 | } 78 | 79 | for host := range table { 80 | msg, err := msgClient(fmt.Sprintf("%s.docker.", host), dns.TypeA) 81 | 82 | if err != nil { 83 | t.Fatal(err) 84 | } 85 | 86 | if len(msg.Answer) != 0 { 87 | t.Fatal("Server gave a reply after record has been deleted") 88 | } 89 | } 90 | } 91 | 92 | func TestSRVRecordCRUD(t *testing.T) { 93 | table := map[string][]SRVRecord{ 94 | "test": {{80, "test"}}, 95 | "test2": {{81, "test2"}}, 96 | } 97 | 98 | // do this in independent parts so both records exist. This tests some 99 | // collision issues. 100 | for name, srv := range table { 101 | server.SetSRV(name, "tcp", srv) 102 | } 103 | 104 | for name, srv := range table { 105 | msg, err := msgClient(fmt.Sprintf("_%s._tcp.docker.", name), dns.TypeSRV) 106 | 107 | if err != nil { 108 | t.Fatal(err) 109 | } 110 | 111 | if len(msg.Answer) != 1 { 112 | t.Fatalf("Server did not reply with a valid answer.") 113 | } 114 | 115 | if msg.Answer[0].Header().Ttl != 1 { 116 | t.Fatalf("TTL was %d instead of 1", msg.Answer[0].Header().Ttl) 117 | } 118 | 119 | if msg.Answer[0].Header().Rrtype != dns.TypeSRV { 120 | t.Fatalf("Expected SRV record, got a record of type %d instead.", msg.Answer[0].Header().Rrtype) 121 | } 122 | 123 | if msg.Answer[0].Header().Name != fmt.Sprintf("_%s._tcp.docker.", name) { 124 | // If this fails, we probably need to look at miekg/dns as this should 125 | // not be possible. 126 | t.Fatalf("Name does not match query sent, %q was provided", msg.Answer[0].Header().Name) 127 | } 128 | 129 | srvRecord := msg.Answer[0].(*dns.SRV) 130 | 131 | if srvRecord.Priority != 0 || srvRecord.Weight != 0 { 132 | t.Fatal("Defaults for priority and weight do not equal 0") 133 | } 134 | 135 | if srvRecord.Port != srv[0].Port || srvRecord.Target != fmt.Sprintf("%s.docker.", name) { 136 | t.Fatalf("SRV records are not equivalent: received host %q port %d", srvRecord.Target, srvRecord.Port) 137 | } 138 | } 139 | 140 | for name := range table { 141 | server.DeleteSRV(name, "tcp") 142 | } 143 | 144 | for name := range table { 145 | msg, err := msgClient(fmt.Sprintf("_%s._tcp.docker.", name), dns.TypeSRV) 146 | 147 | if err != nil { 148 | t.Fatal(err) 149 | } 150 | 151 | if len(msg.Answer) != 0 { 152 | t.Fatal("Server gave a reply after record has been deleted") 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /examples/server/server.go: -------------------------------------------------------------------------------- 1 | /* 2 | This implements a basic DNS service that has two A records: 3 | 4 | test.docker 5 | test2.docker 6 | 7 | This also implements two SRV records for 'test' on tcp that point at 80 and 443 8 | for test.docker. 9 | 10 | You can supply an argument with an IP:Port pair to listen on, or with no 11 | arguments it listens on 127.0.0.1:53 udp. In that event, it needs to run as 12 | root. 13 | 14 | Testing: 15 | 16 | $ host test.docker 17 | $ host test2.docker 18 | $ host -t srv _test._tcp.docker 19 | */ 20 | 21 | package main 22 | 23 | import ( 24 | "net" 25 | "os" 26 | 27 | dnsserver "github.com/docker/dnsserver" 28 | ) 29 | 30 | func main() { 31 | // this is your domain. All records will be scoped under it, e.g., 32 | // 'test.docker' below. 33 | ds := dnsserver.NewDNSServer("docker") 34 | 35 | // set an A record. RRs are not supported. 36 | ds.SetA("test", net.ParseIP("127.0.0.2")) 37 | ds.SetA("test2", net.ParseIP("127.0.0.3")) 38 | 39 | // Set a SRV record. The host values will be qualified for you with the 40 | // domain you provide. 41 | ds.SetSRV("test", "tcp", []dnsserver.SRVRecord{ 42 | {Port: 80, Host: "test"}, 43 | {Port: 443, Host: "test"}, 44 | }) 45 | 46 | if len(os.Args) > 1 { 47 | if err := ds.Listen(os.Args[1]); err != nil { 48 | panic(err) 49 | } 50 | } else { 51 | if err := ds.Listen("127.0.0.1:53"); err != nil { 52 | panic(err) 53 | } 54 | } 55 | } 56 | --------------------------------------------------------------------------------