import "github.com/miekg/dns" message := new(dns.Msg) message.SetId(1234)
import "github.com/miekg/dns" buffer := make([]byte, 1024) n, _, _ := conn.ReadFromUDP(buffer) message := new(dns.Msg) message.Unpack(buffer[:n]) id := message.IdThis code reads a DNS message from a UDP connection and extracts the Msg Id field. Package library: github.com/miekg/dns.