本文整理汇总了Golang中github.com/miekg/dns.RR_Header.Class方法的典型用法代码示例。如果您正苦于以下问题:Golang RR_Header.Class方法的具体用法?Golang RR_Header.Class怎么用?Golang RR_Header.Class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/miekg/dns.RR_Header
的用法示例。
在下文中一共展示了RR_Header.Class方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Resolve
// Resolve wraps Unbound's ub_resolve.
func (u *Unbound) Resolve(name string, rrtype, rrclass uint16) (*Result, error) {
res := C.new_ub_result()
r := new(Result)
defer C.ub_resolve_free(res)
i := C.ub_resolve(u.ctx, C.CString(name), C.int(rrtype), C.int(rrclass), &res)
err := newError(int(i))
if err != nil {
return nil, err
}
r.Qname = C.GoString(res.qname)
r.Qtype = uint16(res.qtype)
r.Qclass = uint16(res.qclass)
r.CanonName = C.GoString(res.canonname)
r.Rcode = int(res.rcode)
r.AnswerPacket = new(dns.Msg)
r.AnswerPacket.Unpack(C.GoBytes(res.answer_packet, res.answer_len)) // Should always work
r.HaveData = res.havedata == 1
r.NxDomain = res.nxdomain == 1
r.Secure = res.secure == 1
r.Bogus = res.bogus == 1
r.WhyBogus = C.GoString(res.why_bogus)
// Re-create the RRs
var h dns.RR_Header
h.Name = r.Qname
h.Rrtype = r.Qtype
h.Class = r.Qclass
h.Ttl = 0
r.Data = make([][]byte, 0)
r.Rr = make([]dns.RR, 0)
j := 0
if r.HaveData {
b := C.GoBytes(unsafe.Pointer(C.array_elem_char(res.data, C.int(j))), C.array_elem_int(res.len, C.int(j)))
for len(b) != 0 {
// Create the RR
h.Rdlength = uint16(len(b))
msg := make([]byte, 20+len(h.Name)) // Long enough
off, _ := dns.PackStruct(&h, msg, 0)
msg = msg[:off]
rrbuf := append(msg, b...)
rr, _, err := dns.UnpackRR(rrbuf, 0)
if err == nil {
r.Rr = append(r.Rr, rr)
}
r.Data = append(r.Data, b)
j++
b = C.GoBytes(unsafe.Pointer(C.array_elem_char(res.data, C.int(j))), C.array_elem_int(res.len, C.int(j)))
}
}
return r, err
}
示例2: setupZoneData
func setupZoneData(data map[string]interface{}, Zone *Zone) {
recordTypes := map[string]uint16{
"a": dns.TypeA,
"aaaa": dns.TypeAAAA,
"ns": dns.TypeNS,
"cname": dns.TypeCNAME,
"alias": dns.TypeMF,
}
for dk, dv_inter := range data {
dv := dv_inter.(map[string]interface{})
//log.Printf("K %s V %s TYPE-V %T\n", dk, dv, dv)
dk = strings.ToLower(dk)
Zone.Labels[dk] = new(Label)
label := Zone.Labels[dk]
label.Label = dk
label.Ttl = Zone.Options.Ttl
label.MaxHosts = Zone.Options.MaxHosts
if ttl, ok := dv["ttl"]; ok {
label.Ttl = valueToInt(ttl)
}
if maxHosts, ok := dv["max_hosts"]; ok {
label.MaxHosts = valueToInt(maxHosts)
}
for rType, dnsType := range recordTypes {
rdata := dv[rType]
if rdata == nil {
//log.Printf("No %s records for label %s\n", rType, dk)
continue
}
//log.Printf("rdata %s TYPE-R %T\n", rdata, rdata)
records := make(map[string][]interface{})
switch rdata.(type) {
case map[string]interface{}:
// Handle NS map syntax, map[ns2.example.net:<nil> ns1.example.net:<nil>]
tmp := make([]interface{}, 0)
for rdata_k, rdata_v := range rdata.(map[string]interface{}) {
if rdata_v == nil {
rdata_v = ""
}
tmp = append(tmp, []string{rdata_k, rdata_v.(string)})
}
records[rType] = tmp
case string:
// CNAME and alias
tmp := make([]interface{}, 1)
tmp[0] = rdata.(string)
records[rType] = tmp
default:
records[rType] = rdata.([]interface{})
}
//log.Printf("RECORDS %s TYPE-REC %T\n", Records, Records)
if label.Records == nil {
label.Records = make(map[uint16]Records)
label.Weight = make(map[uint16]int)
}
label.Records[dnsType] = make(Records, len(records[rType]))
for i := 0; i < len(records[rType]); i++ {
//log.Printf("RT %T %#v\n", records[rType][i], records[rType][i])
record := new(Record)
var h dns.RR_Header
// log.Println("TTL OPTIONS", Zone.Options.Ttl)
h.Ttl = uint32(label.Ttl)
h.Class = dns.ClassINET
h.Rrtype = dnsType
h.Name = label.Label + "." + Zone.Origin + "."
switch dnsType {
case dns.TypeA, dns.TypeAAAA:
rec := records[rType][i].([]interface{})
ip := rec[0].(string)
var err error
switch rec[1].(type) {
case string:
record.Weight, err = strconv.Atoi(rec[1].(string))
if err != nil {
panic("Error converting weight to integer")
}
label.Weight[dnsType] += record.Weight
case float64:
record.Weight = int(rec[1].(float64))
//.........这里部分代码省略.........
示例3: setupZoneData
func setupZoneData(data map[string]interface{}, Zone *Zone) {
recordTypes := map[string]uint16{
"a": dns.TypeA,
"aaaa": dns.TypeAAAA,
"alias": dns.TypeMF,
"cname": dns.TypeCNAME,
"mx": dns.TypeMX,
"ns": dns.TypeNS,
"txt": dns.TypeTXT,
"spf": dns.TypeSPF,
"srv": dns.TypeSRV,
"ptr": dns.TypePTR,
}
for dk, dv_inter := range data {
dv := dv_inter.(map[string]interface{})
//log.Printf("K %s V %s TYPE-V %T\n", dk, dv, dv)
label := Zone.AddLabel(dk)
for rType, rdata := range dv {
switch rType {
case "max_hosts":
label.MaxHosts = valueToInt(rdata)
continue
case "ttl":
label.Ttl = valueToInt(rdata)
continue
}
dnsType, ok := recordTypes[rType]
if !ok {
log.Printf("Unsupported record type '%s'\n", rType)
continue
}
if rdata == nil {
//log.Printf("No %s records for label %s\n", rType, dk)
continue
}
//log.Printf("rdata %s TYPE-R %T\n", rdata, rdata)
records := make(map[string][]interface{})
switch rdata.(type) {
case map[string]interface{}:
// Handle NS map syntax, map[ns2.example.net:<nil> ns1.example.net:<nil>]
tmp := make([]interface{}, 0)
for rdataK, rdataV := range rdata.(map[string]interface{}) {
if rdataV == nil {
rdataV = ""
}
tmp = append(tmp, []string{rdataK, rdataV.(string)})
}
records[rType] = tmp
case string:
// CNAME and alias
tmp := make([]interface{}, 1)
tmp[0] = rdata.(string)
records[rType] = tmp
default:
records[rType] = rdata.([]interface{})
}
//log.Printf("RECORDS %s TYPE-REC %T\n", Records, Records)
label.Records[dnsType] = make(Records, len(records[rType]))
for i := 0; i < len(records[rType]); i++ {
//log.Printf("RT %T %#v\n", records[rType][i], records[rType][i])
record := new(Record)
var h dns.RR_Header
h.Class = dns.ClassINET
h.Rrtype = dnsType
// We add the TTL as a last pass because we might not have
// processed it yet when we process the record data.
switch len(label.Label) {
case 0:
h.Name = Zone.Origin + "."
default:
h.Name = label.Label + "." + Zone.Origin + "."
}
switch dnsType {
case dns.TypeA, dns.TypeAAAA, dns.TypePTR:
str, weight := getStringWeight(records[rType][i].([]interface{}))
ip := str
record.Weight = weight
switch dnsType {
case dns.TypePTR:
record.RR = &dns.PTR{Hdr: h, Ptr: ip}
break
//.........这里部分代码省略.........