Skip to content

Commit

Permalink
limit read buffer size to 9000B
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Feb 2, 2024
1 parent a32023d commit 9b9c7c6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ const (
destinationAddress = "224.0.0.251:5353"
maxMessageRecords = 3
responseTTL = 120
// maxPacketSize is the maximum size of a mdns packet.
// From RFC 6762:
// Even when fragmentation is used, a Multicast DNS packet, including IP
// and UDP headers, MUST NOT exceed 9000 bytes.
// https://datatracker.ietf.org/doc/html/rfc6762#section-17
maxPacketSize = 9000
)

var errNoPositiveMTUFound = errors.New("no positive MTU found")
Expand Down Expand Up @@ -81,6 +87,9 @@ func Server(conn *ipv4.PacketConn, config *Config) (*Conn, error) {
if inboundBufferSize == 0 {
return nil, errNoPositiveMTUFound
}
if inboundBufferSize > maxPacketSize {
inboundBufferSize = maxPacketSize
}
if joinErrCount >= len(ifaces) {
return nil, errJoiningMulticastGroup
}
Expand Down

0 comments on commit 9b9c7c6

Please sign in to comment.