Merge pull request #99 from egonelbre/master
Fix: UDP serving on windows
This commit is contained in:
commit
9af5c1f8a8
|
@ -45,22 +45,36 @@ func TestServing(t *testing.T) {
|
|||
c := new(Client)
|
||||
m := new(Msg)
|
||||
m.SetQuestion("miek.nl.", TypeTXT)
|
||||
r, _, _ := c.Exchange(m, "127.0.0.1:8053")
|
||||
r, _, err := c.Exchange(m, "127.0.0.1:8053")
|
||||
if err != nil {
|
||||
t.Log("Failed to exchange miek.nl", err)
|
||||
t.Fail()
|
||||
}
|
||||
txt := r.Extra[0].(*TXT).Txt[0]
|
||||
if txt != "Hello world" {
|
||||
t.Log("Unexpected result for miek.nl", txt, "!= Hello world")
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
m.SetQuestion("example.com.", TypeTXT)
|
||||
r, _, _ = c.Exchange(m, "127.0.0.1:8053")
|
||||
r, _, err = c.Exchange(m, "127.0.0.1:8053")
|
||||
if err != nil {
|
||||
t.Log("Failed to exchange example.com", err)
|
||||
t.Fail()
|
||||
}
|
||||
txt = r.Extra[0].(*TXT).Txt[0]
|
||||
if txt != "Hello example" {
|
||||
t.Log("Unexpected result for example.com", txt, "!= Hello example")
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Test Mixes cased as noticed by Ask.
|
||||
m.SetQuestion("eXaMplE.cOm.", TypeTXT)
|
||||
r, _, _ = c.Exchange(m, "127.0.0.1:8053")
|
||||
r, _, err = c.Exchange(m, "127.0.0.1:8053")
|
||||
if err != nil {
|
||||
t.Log("Failed to exchange eXaMplE.cOm", err)
|
||||
t.Fail()
|
||||
}
|
||||
txt = r.Extra[0].(*TXT).Txt[0]
|
||||
if txt != "Hello example" {
|
||||
t.Log("Unexpected result for example.com", txt, "!= Hello example")
|
||||
|
|
2
udp.go
2
udp.go
|
@ -2,6 +2,8 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !windows
|
||||
|
||||
package dns
|
||||
|
||||
import (
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2011 Miek Gieben. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build windows
|
||||
|
||||
package dns
|
||||
|
||||
import "net"
|
||||
|
||||
type sessionUDP struct {
|
||||
raddr *net.UDPAddr
|
||||
}
|
||||
|
||||
// readFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a
|
||||
// net.UDPAddr.
|
||||
func readFromSessionUDP(conn *net.UDPConn, b []byte) (int, *sessionUDP, error) {
|
||||
n, raddr, err := conn.ReadFrom(b)
|
||||
if err != nil {
|
||||
return n, nil, err
|
||||
}
|
||||
session := &sessionUDP{raddr.(*net.UDPAddr)}
|
||||
return n, session, err
|
||||
}
|
||||
|
||||
// writeToSessionUDP acts just like net.UDPConn.WritetTo(), but uses a *sessionUDP instead of a net.Addr.
|
||||
func writeToSessionUDP(conn *net.UDPConn, b []byte, session *sessionUDP) (int, error) {
|
||||
n, err := conn.WriteTo(b, session.raddr)
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (s *sessionUDP) RemoteAddr() net.Addr { return s.raddr }
|
||||
|
||||
// setUDPSocketOptions sets the UDP socket options.
|
||||
// This function is implemented on a per platform basis. See udp_*.go for more details
|
||||
func setUDPSocketOptions(conn *net.UDPConn) error {
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue