Add RemoteAddr() to the RequestWriter interface

This commit is contained in:
Miek Gieben 2012-05-08 13:51:12 +02:00
parent 2385ca18a3
commit 2574856aa6
2 changed files with 15 additions and 3 deletions

View File

@ -15,7 +15,11 @@ type QueryHandler interface {
// The RequestWriter interface is used by a DNS query handler to
// construct a DNS request.
type RequestWriter interface {
// Write returns the request message and the reply back to the client.
// RemoteAddr returns the net.Addr of the server
RemoteAddr() net.Addr
// TsigStatus returns the TSIG validation status.
TsigStatus() error
// Write returns the request message and the reply back to the client (i.e. your Go code).
Write(*Msg) error
// Send sends the message to the server.
Send(*Msg) error
@ -25,8 +29,6 @@ type RequestWriter interface {
Close() error
// Dials calls the server.
Dial() error
// TsigStatus returns the TSIG validation status.
TsigStatus() error
}
// hijacked connections...?
@ -222,6 +224,15 @@ func (w *reply) Write(m *Msg) error {
return nil
}
func (w *reply) RemoteAddr() net.Addr {
if w.conn == nil {
return nil
} else {
return w.conn.RemoteAddr()
}
return nil
}
// Do performs an asynchronous query. The result is returned on the
// QueryChan channel set in the *Client c. Basic use pattern for
// sending message m to the server listening on port 53 on localhost

View File

@ -24,6 +24,7 @@ func q(w dns.RequestWriter, m *dns.Msg) {
w.Write(nil)
return
}
w.Close()
if w.TsigStatus() != nil {
fmt.Printf(";; Couldn't verify TSIG signature: %s\n", w.TsigStatus().Error())
}