rfc8427

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 6 Imported by: 0

README

rfc8427

This is a Go implementation of the RFC 8427 specification for miekg/dns objects.

Usage

import (
	"fmt"
	
	"github.com/miekg/dns"
	"github.com/tired-engineer/rfc8427"
)

func main() {

	msg := new(dns.Msg)
	msg.SetQuestion(dns.Fqdn("example.com"), dns.TypeA)
	msg.Id = 1234
	msg.RecursionDesired = true
	msg.Response = true
	msg.Authoritative = true

	cl := new(dns.Client)
	resp, _, err := cl.Exchange(msg, "8.8.8.8:53")
	if err != nil {
		panic(err)
	}

	json, err := rfc8427.Marshal(resp)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(json))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(msg *dns.Msg) ([]byte, error)

Marshal serializes a DNS message to RFC 8427 JSON format.

func Unmarshal

func Unmarshal(data []byte, msg *dns.Msg) error

Unmarshal parses RFC 8427 JSON into a DNS message.

Types

type RFC8427Message

type RFC8427Message struct {
	ID               *uint16                 `json:"ID,omitempty"`
	QR               *int                    `json:"QR,omitempty"` // Represent bool as int (0 or 1) as per RFC for some fields
	Opcode           *int                    `json:"Opcode,omitempty"`
	AA               *int                    `json:"AA,omitempty"`
	TC               *int                    `json:"TC,omitempty"`
	RD               *int                    `json:"RD,omitempty"`
	RA               *int                    `json:"RA,omitempty"`
	AD               *int                    `json:"AD,omitempty"`
	CD               *int                    `json:"CD,omitempty"`
	RCODE            *int                    `json:"RCODE,omitempty"`
	QDCOUNT          *uint16                 `json:"QDCOUNT,omitempty"`
	ANCOUNT          *uint16                 `json:"ANCOUNT,omitempty"`
	NSCOUNT          *uint16                 `json:"NSCOUNT,omitempty"`
	ARCOUNT          *uint16                 `json:"ARCOUNT,omitempty"`
	QNAME            *string                 `json:"QNAME,omitempty"`
	QTYPE            *uint16                 `json:"QTYPE,omitempty"`
	QCLASS           *uint16                 `json:"QCLASS,omitempty"`
	QuestionRRs      []RFC8427ResourceRecord `json:"questionRRs,omitempty"`
	AnswerRRs        []RFC8427ResourceRecord `json:"answerRRs,omitempty"`
	AuthorityRRs     []RFC8427ResourceRecord `json:"authorityRRs,omitempty"`
	AdditionalRRs    []RFC8427ResourceRecord `json:"additionalRRs,omitempty"`
	MessageOctetsHEX *string                 `json:"messageOctetsHEX,omitempty"` // Section 2.4
	HeaderOctetsHEX  *string                 `json:"headerOctetsHEX,omitempty"`  // Section 2.4

}

RFC8427Message represents a DNS message in RFC 8427 JSON format. See RFC 8427, Section 2.1.

type RFC8427ResourceRecord

type RFC8427ResourceRecord struct {
	NAME     *string `json:"NAME,omitempty"`
	TYPE     *uint16 `json:"TYPE,omitempty"`
	CLASS    *uint16 `json:"CLASS,omitempty"`
	TTL      *int32  `json:"TTL,omitempty"` // TTL can be large, int32 is appropriate
	RDLENGTH *uint16 `json:"RDLENGTH,omitempty"`
	RDATAHEX *string `json:"RDATAHEX,omitempty"` // Hex-encoded RDATA

	// Specific RDATA field members from Section 2.3
	RdataA     *string `json:"rdataA,omitempty"`
	RdataAAAA  *string `json:"rdataAAAA,omitempty"`
	RdataCNAME *string `json:"rdataCNAME,omitempty"`
	RdataDNAME *string `json:"rdataDNAME,omitempty"`
	RdataNS    *string `json:"rdataNS,omitempty"`
	RdataPTR   *string `json:"rdataPTR,omitempty"`
	RdataTXT   *string `json:"rdataTXT,omitempty"`
}

RFC8427ResourceRecord represents a DNS resource record in RFC 8427 JSON format. See RFC 8427, Section 2.2.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL