Skip to content

Commit

Permalink
Sending the question back with the answer
Browse files Browse the repository at this point in the history
  • Loading branch information
atomirex committed Nov 24, 2024
1 parent 0722a4b commit 9ea59ae
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
11 changes: 6 additions & 5 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Check warning on line 714 in conn.go

View check run for this annotation

Codecov / codecov/patch

conn.go#L713-L714

Added lines #L713 - L714 were not covered by tests
if err != nil {
return dnsmessage.Message{}, err
}
Expand All @@ -722,6 +722,7 @@ func createAnswer(id uint16, name string, addr netip.Addr) (dnsmessage.Message,
Response: true,
Authoritative: true,
},
Questions: []dnsmessage.Question{q},

Check warning on line 725 in conn.go

View check run for this annotation

Codecov / codecov/patch

conn.go#L725

Added line #L725 was not covered by tests
Answers: []dnsmessage.Resource{
{
Header: dnsmessage.ResourceHeader{
Expand Down Expand Up @@ -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)

Check warning on line 762 in conn.go

View check run for this annotation

Codecov / codecov/patch

conn.go#L761-L762

Added lines #L761 - L762 were not covered by tests
if err != nil {
c.log.Warnf("[%s] failed to create mDNS answer %v", c.name, err)
return
Expand Down Expand Up @@ -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)

Check warning on line 1047 in conn.go

View check run for this annotation

Codecov / codecov/patch

conn.go#L1047

Added line #L1047 was not covered by tests
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,17 +704,18 @@ 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)
}
lookForIP(answer, []byte{127, 0, 0, 1}, 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)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion examples/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion examples/server/publish_ip/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/pion/mdns/v2
module github.com/atomirex/mdns

go 1.20

Expand Down

0 comments on commit 9ea59ae

Please sign in to comment.