From 9ea59aefc435a0410b1148026749ee2f0fe6afe7 Mon Sep 17 00:00:00 2001 From: atomirex Date: Sun, 24 Nov 2024 11:23:20 -0500 Subject: [PATCH] Sending the question back with the answer --- conn.go | 11 ++++++----- conn_test.go | 5 +++-- examples/query/main.go | 2 +- examples/server/main.go | 2 +- examples/server/publish_ip/main.go | 2 +- go.mod | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/conn.go b/conn.go index d300163..26ac6da 100644 --- a/conn.go +++ b/conn.go @@ -710,8 +710,8 @@ func (c *Conn) writeToSocket( } } -func createAnswer(id uint16, name string, addr netip.Addr) (dnsmessage.Message, error) { - packedName, err := dnsmessage.NewName(name) +func createAnswer(id uint16, q dnsmessage.Question, addr netip.Addr) (dnsmessage.Message, error) { + packedName, err := dnsmessage.NewName(q.Name.String()) if err != nil { return dnsmessage.Message{}, err } @@ -722,6 +722,7 @@ func createAnswer(id uint16, name string, addr netip.Addr) (dnsmessage.Message, Response: true, Authoritative: true, }, + Questions: []dnsmessage.Question{q}, Answers: []dnsmessage.Resource{ { Header: dnsmessage.ResourceHeader{ @@ -757,8 +758,8 @@ func createAnswer(id uint16, name string, addr netip.Addr) (dnsmessage.Message, return msg, nil } -func (c *Conn) sendAnswer(queryID uint16, name string, ifIndex int, result netip.Addr, dst *net.UDPAddr) { - answer, err := createAnswer(queryID, name, result) +func (c *Conn) sendAnswer(queryID uint16, q dnsmessage.Question, ifIndex int, result netip.Addr, dst *net.UDPAddr) { + answer, err := createAnswer(queryID, q, result) if err != nil { c.log.Warnf("[%s] failed to create mDNS answer %v", c.name, err) return @@ -1043,7 +1044,7 @@ func (c *Conn) readLoop(name string, pktConn ipPacketConn, inboundBufferSize int continue } c.log.Debugf("[%s] sending response for %s on ifc %d of %s to %s", c.name, q.Name, ifIndex, *localAddress, dst) - c.sendAnswer(header.ID, q.Name.String(), ifIndex, *localAddress, dst) + c.sendAnswer(header.ID, q, ifIndex, *localAddress, dst) } } } diff --git a/conn_test.go b/conn_test.go index 2ae4e18..01ea52b 100644 --- a/conn_test.go +++ b/conn_test.go @@ -704,9 +704,10 @@ func TestResourceParsing(t *testing.T) { } name := "test-server." + q := dnsmessage.Question{Name: dnsmessage.MustNewName(name)} t.Run("A Record", func(t *testing.T) { - answer, err := createAnswer(1, name, mustAddr(net.IP{127, 0, 0, 1})) + answer, err := createAnswer(1, q, mustAddr(net.IP{127, 0, 0, 1})) if err != nil { t.Fatal(err) } @@ -714,7 +715,7 @@ func TestResourceParsing(t *testing.T) { }) t.Run("AAAA Record", func(t *testing.T) { - answer, err := createAnswer(1, name, netip.MustParseAddr("::1")) + answer, err := createAnswer(1, q, netip.MustParseAddr("::1")) if err != nil { t.Fatal(err) } diff --git a/examples/query/main.go b/examples/query/main.go index 3539d05..56b200e 100644 --- a/examples/query/main.go +++ b/examples/query/main.go @@ -10,7 +10,7 @@ import ( "net" "os" - "github.com/pion/mdns/v2" + "github.com/atomirex/mdns" "golang.org/x/net/ipv4" "golang.org/x/net/ipv6" ) diff --git a/examples/server/main.go b/examples/server/main.go index ce9b20b..e1394ea 100644 --- a/examples/server/main.go +++ b/examples/server/main.go @@ -7,7 +7,7 @@ package main import ( "net" - "github.com/pion/mdns/v2" + "github.com/atomirex/mdns" "golang.org/x/net/ipv4" "golang.org/x/net/ipv6" ) diff --git a/examples/server/publish_ip/main.go b/examples/server/publish_ip/main.go index 968991f..8e26e41 100644 --- a/examples/server/publish_ip/main.go +++ b/examples/server/publish_ip/main.go @@ -9,7 +9,7 @@ import ( "flag" "net" - "github.com/pion/mdns/v2" + "github.com/atomirex/mdns" "golang.org/x/net/ipv4" "golang.org/x/net/ipv6" ) diff --git a/go.mod b/go.mod index b48598f..8d87d09 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/pion/mdns/v2 +module github.com/atomirex/mdns go 1.20