예제 #1
0
파일: dns.go 프로젝트: guilhem/netcore
func answerSRV(q *dns.Question, v *DNSValue) dns.RR {
	answer := new(dns.SRV)
	answer.Header().Name = q.Name
	answer.Header().Rrtype = dns.TypeSRV
	answer.Header().Class = dns.ClassINET
	answer.Priority = 50 // default if not defined
	priority, err := strconv.Atoi(v.Attr["priority"])
	if err == nil {
		answer.Priority = uint16(priority)
	}
	answer.Weight = 50 // default if not defined
	weight, err := strconv.Atoi(v.Attr["weight"])
	if err == nil {
		answer.Weight = uint16(weight)
	}
	answer.Port = 0 // default if not defined
	port, err := strconv.Atoi(v.Attr["port"])
	if err == nil {
		answer.Port = uint16(port)
	}
	if target, ok := v.Attr["target"]; ok {
		answer.Target = strings.TrimSuffix(target, ".") + "."
	} else if v.Value != "" { // allows for simplified setting
		targetParts := strings.Split(v.Value, ":")
		answer.Target = strings.TrimSuffix(targetParts[0], ".") + "."
		if len(targetParts) > 1 {
			port, err := strconv.Atoi(targetParts[1])
			if err == nil {
				answer.Port = uint16(port)
			}
		}
	}
	return answer
}
예제 #2
0
파일: dns_test.go 프로젝트: 0x27/coyim
func (s *DNSXmppSuite) Test_convertAnswerToSRV_returnsAValidNetSRV(c *C) {
	srv := new(dns.SRV)
	srv.Target = "foo.com"
	srv.Port = 123
	srv.Priority = 5
	srv.Weight = 42
	res := convertAnswerToSRV(srv)
	c.Assert(res, Not(IsNil))
	c.Assert(res.Target, Equals, "foo.com")
	c.Assert(res.Port, Equals, uint16(123))
	c.Assert(res.Priority, Equals, uint16(5))
	c.Assert(res.Weight, Equals, uint16(42))
}