func UnpackSrcOfAuth(in *bytes.Reader, n uint16, p []byte) (*SrcOfAuth, error) { if n <= 22 { return nil, fmt.Errorf("soa with %d bytes", n) } ret := new(SrcOfAuth) was := in.Len() labels, e := domain.UnpackLabels(in, p) if e != nil { return nil, e } ret.Mname = labels labels, e = domain.UnpackLabels(in, p) if e != nil { return nil, e } ret.Rname = labels now := in.Len() if was-now+20 != int(n) { return nil, errors.New("invalid soa field length") } buf := make([]byte, 20) _, e = in.Read(buf) if e != nil { return nil, e } ret.Serial = enc.Uint32(buf[0:4]) ret.Refresh = enc.Uint32(buf[4:8]) ret.Retry = enc.Uint32(buf[8:12]) ret.Expire = enc.Uint32(buf[12:16]) ret.Minimum = enc.Uint32(buf[16:20]) return ret, nil }
func unpackLabels(in *bytes.Reader, n uint16, p []byte) ([]string, error) { if n == 0 { return nil, errors.New("zero labels len") } was := in.Len() d, e := domain.UnpackLabels(in, p) now := in.Len() if was-now != int(n) { return nil, fmt.Errorf("domain length expect %d, actual %d", n, was-now) } return d, e }