ncsid: Import from gBMC

This is the initial code drop from gBMC.

Google-Bug-Id: 179618516
Upstream: 1e71af914bc8c54d8b91d0a1cf377e2696713c2f
Change-Id: Ic653e8271dacd205e04f2bc713071ef2ec5936a4
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/ncsid/test/sock_test.cpp b/ncsid/test/sock_test.cpp
new file mode 100644
index 0000000..2ff2638
--- /dev/null
+++ b/ncsid/test/sock_test.cpp
@@ -0,0 +1,21 @@
+#include "ncsi_sockio.h"
+#include "net_iface_mock.h"
+
+#include <gmock/gmock.h>
+
+TEST(TestSockIO, TestBind)
+{
+    mock::IFace iface_mock;
+    constexpr int test_index = 5;
+    iface_mock.index = test_index;
+
+    // This needs to be negative so that ncsi::SockIO
+    // won't try to close the socket upon desctrution.
+    constexpr int sock_fake_fd = -10;
+    ncsi::SockIO ncsi_sock(sock_fake_fd);
+
+    ncsi_sock.bind_to_iface(iface_mock);
+    EXPECT_THAT(iface_mock.bound_socks.size(), testing::Ge(0));
+    EXPECT_THAT(iface_mock.bound_socks, testing::Contains(sock_fake_fd));
+    EXPECT_EQ(iface_mock.flags & IFF_PROMISC, IFF_PROMISC);
+}