Skip to content

Commit

Permalink
feat(coresmd): add log messages to tftp
Browse files Browse the repository at this point in the history
  • Loading branch information
synackd committed Dec 11, 2024
1 parent d8fa710 commit b1d1a31
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions coresmd/tftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,33 @@ func startTFTPServer(directory string) {

func readHandler(directory string) func(string, io.ReaderFrom) error {
return func(filename string, rf io.ReaderFrom) error {
var raddr string
ot, ok := rf.(tftp.OutgoingTransfer)
if !ok {
log.Error("unable to get remote address, setting to (unknown)")
raddr = "(unknown)"
} else {
ra := ot.RemoteAddr()
raptr := &ra
raddr = raptr.IP.String()
}
if filename == defaultScriptName {
log.Infof("tftp: %s requested default script")
var sr ScriptReader
_, err := rf.ReadFrom(sr)
nbytes, err := rf.ReadFrom(sr)
log.Infof("tftp: sent %d bytes of default script to %s", nbytes, raddr)
return err
}
log.Infof("tftp: %s requested file %s", raddr, filename)
filePath := filepath.Join(directory, filename)
file, err := os.Open(filePath)
if err != nil {
return err
}
defer file.Close()

_, err = rf.ReadFrom(file)
nbytes, err := rf.ReadFrom(file)
log.Infof("tftp: sent %d bytes of file %s to %s", nbytes, filename, raddr)
return err
}
}

0 comments on commit b1d1a31

Please sign in to comment.