mirror of
https://github.com/miekg/dns.git
synced 2025-10-18 13:21:15 +02:00
Keep Exchange as it was, but still check ID.
This commit is contained in:
parent
dddcd696ba
commit
b9c528f99c
27
client.go
27
client.go
@ -46,9 +46,30 @@ type Client struct {
|
|||||||
// co.Close()
|
// co.Close()
|
||||||
//
|
//
|
||||||
func Exchange(m *Msg, a string) (r *Msg, err error) {
|
func Exchange(m *Msg, a string) (r *Msg, err error) {
|
||||||
c := Client{}
|
var co *Conn
|
||||||
r, _, err = c.Exchange(m, a)
|
co, err = DialTimeout("udp", a, dnsTimeout)
|
||||||
return
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer co.Close()
|
||||||
|
co.SetReadDeadline(time.Now().Add(dnsTimeout))
|
||||||
|
co.SetWriteDeadline(time.Now().Add(dnsTimeout))
|
||||||
|
|
||||||
|
opt := m.IsEdns0()
|
||||||
|
// If EDNS0 is used use that for size.
|
||||||
|
if opt != nil && opt.UDPSize() >= MinMsgSize {
|
||||||
|
co.UDPSize = opt.UDPSize()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = co.WriteMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r, err = co.ReadMsg()
|
||||||
|
if err == nil && r.Id != m.Id {
|
||||||
|
err = ErrId
|
||||||
|
}
|
||||||
|
return r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExchangeConn performs a synchronous query. It sends the message m via the connection
|
// ExchangeConn performs a synchronous query. It sends the message m via the connection
|
||||||
|
Loading…
x
Reference in New Issue
Block a user