Implement network monitor
This commit listens for the ipaddress add event
and prints the message once it gets the NEWADDR
signal.
Change-Id: I5cdebc023dc8848fc736eca8d785c33387d401df
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/rtnetlink_server.hpp b/rtnetlink_server.hpp
new file mode 100644
index 0000000..51cf7bb
--- /dev/null
+++ b/rtnetlink_server.hpp
@@ -0,0 +1,55 @@
+#pragma once
+
+#include "types.hpp"
+
+#include <systemd/sd-event.h>
+
+namespace phosphor
+{
+namespace network
+{
+namespace rtnetlink
+{
+
+constexpr auto BUFSIZE = 4096;
+
+/** General rtnetlink server which waits for the POLLIN event
+ and calls the call back once it gets the event.
+ Usage would be create the server with the call back
+ and call the run method.
+ */
+
+class Server
+{
+
+ public:
+
+ /** @brief Constructor
+ *
+ * @param[in] event - Unique ptr reference to sd_event.
+ */
+
+ Server(EventPtr& event):
+ eventPtr(event) {};
+
+ Server(const Server&) = delete;
+ Server& operator=(const Server&) = delete;
+ Server(Server&&) = default;
+ Server& operator=(Server &&) = default;
+
+ /** @brief Initialise the event loop and add the handler for incoming
+ * RTNETLINK events.
+ *
+ * @return EXIT_SUCCESS on success and EXIT_FAILURE on failure.
+ */
+ int run();
+
+ private:
+ /** @brief reference to sd_event wrapped in unique_ptr */
+ EventPtr& eventPtr;
+
+};
+
+} //namespace rtnetlink
+} //namespce network
+} //namespace phosphor