func (r ResourceRecord) CNAME() (*dns.CNAME, error) {
	rr, err := r.Unpack()
	if err != nil {
		return nil, err
	}
	if rr.Header().Rrtype != dns.TypeCNAME {
		return nil, errors.New("not an CNAME record type")
	}
	cname, ok := rr.(*dns.CNAME)
	if !ok {
		return nil, errors.New("dns.RR is not a *dns.CNAME")
	}
	return cname, nil
}
CNAME unpacks a ResourceRecord to *dns.CNAME.
package resolved
import (
	"context"
	"errors"
	"fmt"
	"net"
	"os"
	"strconv"
	"github.com/godbus/dbus/v5"
	"github.com/miekg/dns"
)
const (
	dbusDest      = "org.freedesktop.resolve1"
	dbusInterface = "org.freedesktop.resolve1.Manager"
	dbusPath      = "/org/freedesktop/resolve1"
)
type Conn struct {
	conn *dbus.Conn
	obj  dbus.BusObject
}
func NewConn() (*Conn, error) {
	conn, err := dbus.SystemBusPrivate()
	if err != nil {
		return nil, fmt.Errorf("failed to init private conn to system bus: %v", err)
	}
	methods := []dbus.Auth{dbus.AuthExternal(strconv.Itoa(os.Getuid()))}
	err = conn.Auth(methods)
	if err != nil {
		conn.Close()
		return nil, fmt.Errorf("failed to auth with external method: %v", err)
	}
	err = conn.Hello()
	if err != nil {
		conn.Close()
		return nil, fmt.Errorf("failed to make hello call: %v", err)
	}
	return &Conn{
		conn: conn,
		obj:  conn.Object(dbusDest, dbus.ObjectPath(dbusPath)),
	}, nil
}
func (c *Conn) Call(ctx context.Context, method string, args ...interface{}) *dbus.Call {
	return c.obj.CallWithContext(ctx, fmt.Sprintf("%s.%s", dbusInterface, method), 0, args...)
}
func (c *Conn) Close() error {
	return c.conn.Close()
}
const (
	SD_RESOLVED_DNS           = uint64(1) << 0
	SD_RESOLVED_LLMNR_IPV4    = uint64(1) << 1
	SD_RESOLVED_LLMNR_IPV6    = uint64(1) << 2
	SD_RESOLVED_MDNS_IPV4     = uint64(1) << 3
	SD_RESOLVED_MDNS_IPV6     = uint64(1) << 4
	SD_RESOLVED_NO_CNAME      = uint64(1) << 5
	SD_RESOLVED_NO_TXT        = uint64(1) << 6
	SD_RESOLVED_NO_ADDRESS    = uint64(1) << 7
	SD_RESOLVED_NO_SEARCH     = uint64(1) << 8
	SD_RESOLVED_AUTHENTICATED = uint64(1) << 9
)
type Address struct {
	IfIndex int     
	Family  int     
	Address net.IP  
}
func (a Address) String() string {
	return fmt.Sprintf(`{
	IfIndex: %d,
	Family:  %d,
	IP:      %s,
}`, a.IfIndex, a.Family, a.Address.String())
}
func (c *Conn) ResolveHostname(ctx context.Context, ifindex int, name string, family int, flags uint64) (addresses []Address, canonical string, outflags uint64, err error) {
	err = c.Call(ctx, "ResolveHostname", ifindex, name, family, flags).Store(&addresses, &canonical, &outflags)
	return
}
type Name struct {
	IfIndex  int     
	Hostname string  
}
func (n Name) String() string {
	return fmt.Sprintf(`{
	IfIndex: %d,
	Name:    %s,
}`, n.IfIndex, n.Hostname)
}
func (c *Conn) ResolveAddress(ctx context.Context, ifindex int, family int, address net.IP, flags uint64) (names []Name, outflags uint64, err error) {
	err = c.Call(ctx, "ResolveAddress", ifindex, family, address, flags).Store(&names, &outflags)
	return
}
type ResourceRecord struct {
	IfIndex int        
	Type    dns.Type   
	Class   dns.Class  
	Data []byte
}
func (r ResourceRecord) String() string {
	return fmt.Sprintf(`{
	IfIndex: %d,
	Type:    %s,
	Class:   %s,
	Data:    %v,
}`, r.IfIndex, r.Type.String(), r.Class.String(), r.Data)
}
func (r ResourceRecord) Unpack() (dns.RR, error) {
	rr, _, err := dns.UnpackRR(r.Data, 0)
	if err != nil {
		return nil, err
	}
	return rr, nil
}