Skip to content

Commit 5fda30d

Browse files
authored
Merge pull request #89 from AlbanBedel/cope-with-broadcast
Cope with clients using the broadcast address
2 parents c10edb1 + 01410ee commit 5fda30d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

server.go

+8
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ func (s *Server) Shutdown() {
321321
func (s *Server) handlePacket(localAddr net.IP, remoteAddr *net.UDPAddr, buffer []byte, n, maxBlockLen int, listener chan []byte) error {
322322
s.Lock()
323323
defer s.Unlock()
324+
325+
// Cope with packets received on the broadcast address
326+
// We can't use this address as the source address in responses
327+
// so fallback to the OS default.
328+
if localAddr.Equal(net.IPv4bcast) {
329+
localAddr = net.IPv4zero
330+
}
331+
324332
// handlePacket is always called with maxBlockLen = blockLength (above, in processRequest).
325333
// As a result, the block size would always be capped at 512 bytes, even when the tftp
326334
// client indicated to use a larger value. So override that value. And make sure to

0 commit comments

Comments
 (0)