bmc: add network bridge support

This data handler listens on a TCP port for the image bytes.

Signed-off-by: Benjamin Fair <benjaminfair@google.com>
Change-Id: I388fdd7303c5f8bc93a8f75e97b3abf8adbb81af
diff --git a/bmc/net_handler.hpp b/bmc/net_handler.hpp
new file mode 100644
index 0000000..0a0943f
--- /dev/null
+++ b/bmc/net_handler.hpp
@@ -0,0 +1,45 @@
+#pragma once
+
+#include "data_handler.hpp"
+
+#include <unistd.h>
+
+#include <cstdint>
+#include <optional>
+#include <stdplus/handle/managed.hpp>
+#include <vector>
+
+namespace ipmi_flash
+{
+
+/**
+ * Data Handler for receiving the image over a network port
+ */
+class NetDataHandler : public DataInterface
+{
+  public:
+    NetDataHandler() : listenFd(std::nullopt), connFd(std::nullopt)
+    {
+    }
+
+    bool open() override;
+    bool close() override;
+    std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
+    bool writeMeta(const std::vector<std::uint8_t>& configuration) override;
+    std::vector<std::uint8_t> readMeta() override;
+
+    static constexpr std::uint16_t listenPort = 623;
+    static constexpr int timeoutS = 5;
+
+  private:
+    static void closefd(int&& fd)
+    {
+        ::close(fd);
+    }
+    using Fd = stdplus::Managed<int>::Handle<closefd>;
+
+    Fd listenFd;
+    Fd connFd;
+};
+
+} // namespace ipmi_flash