Skip to content

Commit

Permalink
Merge pull request #89 from AlbanBedel/cope-with-broadcast
Browse files Browse the repository at this point in the history
Cope with clients using the broadcast address
  • Loading branch information
pin authored Oct 28, 2023
2 parents c10edb1 + 01410ee commit 5fda30d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ func (s *Server) Shutdown() {
func (s *Server) handlePacket(localAddr net.IP, remoteAddr *net.UDPAddr, buffer []byte, n, maxBlockLen int, listener chan []byte) error {
s.Lock()
defer s.Unlock()

// Cope with packets received on the broadcast address
// We can't use this address as the source address in responses
// so fallback to the OS default.
if localAddr.Equal(net.IPv4bcast) {
localAddr = net.IPv4zero
}

// handlePacket is always called with maxBlockLen = blockLength (above, in processRequest).
// As a result, the block size would always be capped at 512 bytes, even when the tftp
// client indicated to use a larger value. So override that value. And make sure to
Expand Down

0 comments on commit 5fda30d

Please sign in to comment.