本文整理汇总了Golang中github.com/miekg/dns.A.Hdr方法的典型用法代码示例。如果您正苦于以下问题:Golang A.Hdr方法的具体用法?Golang A.Hdr怎么用?Golang A.Hdr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/miekg/dns.A
的用法示例。
在下文中一共展示了A.Hdr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GenerateServeDNS
func (c *Config) GenerateServeDNS(hostname string) func(dns.ResponseWriter, *dns.Msg) {
if len(hostname) > 0 {
if hostname[len(hostname)-1] != '.' {
hostname += "."
}
}
return func(w dns.ResponseWriter, r *dns.Msg) {
m := new(dns.Msg)
m.SetReply(r)
m.Authoritative = true
ip, err := c.GetOrLaunchInstance()
if err != nil {
// TODO: error handling
log.Println("Error in GetOrLaunchInstance:", err)
w.Close()
return
}
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: hostname, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: uint32(c.MaxIdleTime.Seconds())}
rr.A = ip
m.Answer = []dns.RR{rr}
w.WriteMsg(m)
}
}
示例2: handleARequest
func (s *DNSServer) handleARequest(r *dns.Msg, m *dns.Msg) {
m.Answer = make([]dns.RR, 0, 2)
query := r.Question[0].Name
if query[len(query)-1] == '.' {
query = query[:len(query)-1]
}
for service := range s.queryServices(query) {
rr := new(dns.A)
var ttl int
if service.Ttl != -1 {
ttl = service.Ttl
} else {
ttl = s.config.ttl
}
rr.Hdr = dns.RR_Header{
Name: r.Question[0].Name,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: uint32(ttl),
}
rr.A = service.Ip
m.Answer = append(m.Answer, rr)
}
}
示例3: handleIPQuery
func (r *resolver) handleIPQuery(name string, query *dns.Msg, ipType int) (*dns.Msg, error) {
addr := r.sb.ResolveName(name, ipType)
if addr == nil {
return nil, nil
}
log.Debugf("Lookup for %s: IP %v", name, addr)
resp := new(dns.Msg)
resp.SetReply(query)
setCommonFlags(resp)
if len(addr) > 1 {
addr = shuffleAddr(addr)
}
if ipType == netutils.IPv4 {
for _, ip := range addr {
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
rr.A = ip
resp.Answer = append(resp.Answer, rr)
}
} else {
for _, ip := range addr {
rr := new(dns.AAAA)
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: respTTL}
rr.AAAA = ip
resp.Answer = append(resp.Answer, rr)
}
}
return resp, nil
}
示例4: handleIPQuery
func (r *resolver) handleIPQuery(name string, query *dns.Msg, ipType int) (*dns.Msg, error) {
addr, ipv6Miss := r.sb.ResolveName(name, ipType)
if addr == nil && ipv6Miss {
// Send a reply without any Answer sections
log.Debugf("Lookup name %s present without IPv6 address", name)
resp := createRespMsg(query)
return resp, nil
}
if addr == nil {
return nil, nil
}
log.Debugf("Lookup for %s: IP %v", name, addr)
resp := createRespMsg(query)
if len(addr) > 1 {
addr = shuffleAddr(addr)
}
if ipType == types.IPv4 {
for _, ip := range addr {
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
rr.A = ip
resp.Answer = append(resp.Answer, rr)
}
} else {
for _, ip := range addr {
rr := new(dns.AAAA)
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: respTTL}
rr.AAAA = ip
resp.Answer = append(resp.Answer, rr)
}
}
return resp, nil
}
示例5: handleSRVQuery
func (r *resolver) handleSRVQuery(svc string, query *dns.Msg) (*dns.Msg, error) {
srv, ip := r.backend.ResolveService(svc)
if len(srv) == 0 {
return nil, nil
}
if len(srv) != len(ip) {
return nil, fmt.Errorf("invalid reply for SRV query %s", svc)
}
resp := createRespMsg(query)
for i, r := range srv {
rr := new(dns.SRV)
rr.Hdr = dns.RR_Header{Name: svc, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: respTTL}
rr.Port = r.Port
rr.Target = r.Target
resp.Answer = append(resp.Answer, rr)
rr1 := new(dns.A)
rr1.Hdr = dns.RR_Header{Name: r.Target, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
rr1.A = ip[i]
resp.Extra = append(resp.Extra, rr1)
}
return resp, nil
}
示例6: newRR
func newRR(host string, addr net.IP) dns.RR {
rr := new(dns.A)
rr.Hdr = dns.RR_Header{
Name: host,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: 0}
rr.A = addr.To4()
return rr
}
示例7: hijackResponse
// hijackResponse returns a modified version on the input dns.Msg with the A record modified
// to point to our server
func hijackResponse(r *dns.Msg) (m *dns.Msg) {
m = new(dns.Msg)
m.SetReply(r)
m.Answer = make([]dns.RR, 1)
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: m.Question[0].Name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 600}
rr.A = net.ParseIP(config.EXTERNAL_ADDRESS)
m.Answer[0] = rr
return m
}
示例8: dnsAddressRecord
func dnsAddressRecord(query *dns.Msg, name string, addrs []net.IP) *dns.Msg {
resp := new(dns.Msg)
resp.SetReply(query)
for _, addr := range addrs {
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 0}
rr.A = addr
resp.Answer = append(resp.Answer, rr)
}
return resp
}
示例9: dnsHandler
func dnsHandler(w dns.ResponseWriter, r *dns.Msg) {
defer w.Close()
m := new(dns.Msg)
m.SetReply(r)
m.Compress = false
for _, q := range r.Question {
fmt.Printf("dns-srv: Query -- [%s] %s\n", q.Name, dns.TypeToString[q.Qtype])
switch q.Qtype {
case dns.TypeA:
record := new(dns.A)
record.Hdr = dns.RR_Header{
Name: q.Name,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: 0,
}
record.A = net.ParseIP("127.0.0.1")
m.Answer = append(m.Answer, record)
case dns.TypeMX:
record := new(dns.MX)
record.Hdr = dns.RR_Header{
Name: q.Name,
Rrtype: dns.TypeMX,
Class: dns.ClassINET,
Ttl: 0,
}
record.Mx = "mail." + q.Name
record.Preference = 10
m.Answer = append(m.Answer, record)
}
}
w.WriteMsg(m)
return
}
示例10: AddressRecords
func (s *server) AddressRecords(q dns.Question, name string) (records []dns.RR, err error) {
results, err := s.hosts.FindHosts(name)
if err != nil {
return nil, err
}
for _, ip := range results {
switch {
case ip.To4() != nil && (q.Qtype == dns.TypeA || q.Qtype == dns.TypeANY):
r := new(dns.A)
r.Hdr = dns.RR_Header{Name: q.Name, Rrtype: dns.TypeA,
Class: dns.ClassINET, Ttl: s.config.HostsTtl}
r.A = ip.To4()
records = append(records, r)
case ip.To4() == nil && (q.Qtype == dns.TypeAAAA || q.Qtype == dns.TypeANY):
r := new(dns.AAAA)
r.Hdr = dns.RR_Header{Name: q.Name, Rrtype: dns.TypeAAAA,
Class: dns.ClassINET, Ttl: s.config.HostsTtl}
r.AAAA = ip.To16()
records = append(records, r)
}
}
return records, nil
}
示例11: handleIPv4Query
func (r *resolver) handleIPv4Query(name string, query *dns.Msg) (*dns.Msg, error) {
addr := r.sb.ResolveName(name)
if addr == nil {
return nil, nil
}
log.Debugf("Lookup for %s: IP %s", name, addr.String())
resp := new(dns.Msg)
resp.SetReply(query)
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
rr.A = addr
resp.Answer = append(resp.Answer, rr)
return resp, nil
}
示例12: serveResponse
/* ----------------------------------------------------------------------------
FUNCTION
Name: Serve Response
Prototype: func serveResponse(w dns.ResponseWriter, r *dns.Msg)
Developer: Andrew Burian
Created On: 2015-09-24
Parameters:
w dns.ResponseWriter
the writer that will respond to the dns query
r dns.Msg
the dns query to respond to
Return Values:
(none)
Description:
Handles a single dns request by generating and writing
a response to the provided writer.
Also strips out the contained data and sends it over a
channel
Revisions:
(none)
---------------------------------------------------------------------------- */
func serveResponse(w dns.ResponseWriter, r *dns.Msg) {
// create a message to respond with
respMsg := new(dns.Msg)
// set this message to be a response to the first
respMsg.SetReply(r)
// create a new record to respond with
respRec := new(dns.A)
respRec.Hdr = dns.RR_Header{
Name: r.Question[0].Name,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: 0} // 0 TTL to avoid caching
// pseudo random IP
rand_bytes := make([]byte, 4)
rand.Read(rand_bytes)
respRec.A = rand_bytes
respMsg.Answer = append(respMsg.Answer, respRec)
w.WriteMsg(respMsg)
// now that the response has been handled
// process the covert data
// get the data from the query
data := (strings.Split(r.Question[0].Name, "."))[0]
// create the new message channel
datachan := make(chan byte, len(data))
// send it to the main
messages <- datachan
// read all the bytes into the channel
for _, b := range []byte(data) {
datachan <- b
}
close(datachan)
}
示例13: route
func route(w dns.ResponseWriter, req *dns.Msg) {
if len(req.Question) != 1 {
failWithRcode(w, req, dns.RcodeRefused)
return
}
question := req.Question[0]
qtype := question.Qtype
if question.Qclass != dns.ClassINET {
failWithRcode(w, req, dns.RcodeRefused)
return
}
remoteIP := w.RemoteAddr().(*net.UDPAddr).IP
m := new(dns.Msg)
m.Id = req.Id
switch qtype {
case dns.TypeA:
if remoteIP4 := remoteIP.To4(); remoteIP4 != nil {
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: question.Qtype,
Class: dns.ClassINET, Ttl: 10}
rr.A = remoteIP4
m.Answer = []dns.RR{rr}
}
case dns.TypeAAAA:
if remoteIP16 := remoteIP.To16(); remoteIP16 != nil {
rr := new(dns.AAAA)
rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: question.Qtype,
Class: dns.ClassINET, Ttl: 10}
rr.AAAA = remoteIP16
m.Answer = []dns.RR{rr}
}
case dns.TypeTXT:
rr := new(dns.TXT)
rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: question.Qtype,
Class: dns.ClassINET, Ttl: 10}
rr.Txt = []string{fmt.Sprintf("Resolver IP: %v", remoteIP.String())}
m.Answer = []dns.RR{rr}
}
m.Question = req.Question
m.Response = true
m.Authoritative = true
w.WriteMsg(m)
}
示例14: fillWithData
func (s *SenseDNS) fillWithData(pairs api.KVPairs, network string) {
zs := s.dnsServer.zones
zs.Lock()
defer zs.Unlock()
key := s.dnsServer.getNetDomain(network)
zs.store[key] = make(map[dns.RR_Header][]dns.RR)
for _, value := range pairs {
path := strings.Split(value.Key, "/")
hostname := fmt.Sprintf("%s.%s.%s", path[3], network, s.dnsServer.networkTLD)
ip := string(value.Value)
rr := new(dns.A)
rr.A = net.ParseIP(ip)
rr.Hdr = dns.RR_Header{Name: dns.Fqdn(hostname), Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 3600}
key2 := dns.RR_Header{Name: dns.Fqdn(rr.Header().Name), Rrtype: rr.Header().Rrtype, Class: rr.Header().Class}
zs.store[key][key2] = append(zs.store[key][key2], rr)
}
if log.Level == logrus.DebugLevel {
s.dnsServer.printRoutingTable()
}
}
示例15: parseValue
func parseValue(t uint16, value string, h dns.RR_Header) dns.RR {
switch t {
case dns.TypeA:
a := new(dns.A)
a.Hdr = h
a.A, _ = parseA(value)
return a
case dns.TypeAAAA:
aaaa := new(dns.AAAA)
aaaa.Hdr = h
aaaa.AAAA, _ = parseAAAA(value)
return aaaa
case dns.TypeSRV:
srv := new(dns.SRV)
srv.Hdr = h
srv.Priority, srv.Weight, srv.Port, srv.Target, _ = parseSRV(value)
return srv
}
return nil
}