Modify the sd_event_loop to use systemd activated socket

Change-Id: I98cd7c3b5f8aad132e2671cbc2387a0f8b62cb6e
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/main.cpp b/main.cpp
index 27b27c9..89ef15c 100644
--- a/main.cpp
+++ b/main.cpp
@@ -98,8 +98,6 @@
 
 int startEventLoop()
 {
-    struct sockaddr_in6 in {};
-
     sd_event_source* event_source = nullptr;
     sd_event* event = nullptr;
     int fd = -1, r;
@@ -139,21 +137,13 @@
         goto finish;
     }
 
-    fd = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
-    if (fd < 0)
+    if (sd_listen_fds(0) != 1)
     {
-        r = -errno;
+        fprintf(stderr, "No or too many file descriptors received.\n");
         goto finish;
     }
 
-    in.sin6_family = AF_INET6;
-    in.sin6_port = htons(IPMI_STD_PORT);
-
-    if (bind(fd, (struct sockaddr*)&in, sizeof(in)) < 0)
-    {
-        r = -errno;
-        goto finish;
-    }
+    fd = SD_LISTEN_FDS_START;
 
     r = sd_event_add_io(event, &event_source, fd, EPOLLIN, io_handler, nullptr);
     if (r < 0)