aboutsummaryrefslogtreecommitdiff
path: root/bbot/tftp
diff options
context:
space:
mode:
Diffstat (limited to 'bbot/tftp')
-rw-r--r--bbot/tftp44
1 files changed, 44 insertions, 0 deletions
diff --git a/bbot/tftp b/bbot/tftp
new file mode 100644
index 0000000..cc39419
--- /dev/null
+++ b/bbot/tftp
@@ -0,0 +1,44 @@
+// file : bbot/tftp -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef BBOT_TFTP
+#define BBOT_TFTP
+
+#include <bbot/types>
+#include <bbot/utility>
+
+namespace bbot
+{
+ // A TFTP server "wrapper" over tftpd-hpa.
+ //
+ // In a nutshell, we are pretending to be inetd and when a request arrives,
+ // spawn tftpd-hpa to handle it.
+ //
+ class tftp_server
+ {
+ public:
+ // The map argument specifies the path mapping rules, one per line (see
+ // the tftpd-hpa --map-file|-m option for details).
+ //
+ tftp_server (const string& map);
+
+ // Return the assigned port.
+ //
+ uint16_t
+ port () const;
+
+ // Wait for a TFTP request for up to the specified number of seconds. If
+ // a request was served, update the timeout value and return true. Retain
+ // the original timeout value and return false otherwise.
+ //
+ bool
+ serve (size_t& seconds);
+
+ private:
+ auto_fd fd_;
+ auto_rmfile map_;
+ };
+}
+
+#endif // BBOT_TFTP