Add tests for interface add/remove binder API

Bug: 30298058

(cherry picked from commit 46ae27cd20e70393843799efe8de9180295a4953)

Change-Id: I06cd226c75a8cc42eac5b5d1d27031af30c0662e
diff --git a/server/NetdConstants.h b/server/NetdConstants.h
index e3f533a..605362c 100644
--- a/server/NetdConstants.h
+++ b/server/NetdConstants.h
@@ -19,6 +19,8 @@
 
 #include <string>
 #include <list>
+#include <ifaddrs.h>
+#include <netdb.h>
 #include <stdarg.h>
 
 #include <chrono>
@@ -73,6 +75,28 @@
     std::chrono::time_point<std::chrono::steady_clock> mStart;
 };
 
+
+struct AddrinfoDeleter {
+    void operator()(struct addrinfo* p) const {
+        if (p != nullptr) {
+            freeaddrinfo(p);
+        }
+    }
+};
+
+typedef std::unique_ptr<struct addrinfo, struct AddrinfoDeleter> ScopedAddrinfo;
+
+
+struct IfaddrsDeleter {
+    void operator()(struct ifaddrs *p) const {
+        if (p != nullptr) {
+            freeifaddrs(p);
+        }
+    }
+};
+
+typedef std::unique_ptr<struct ifaddrs, struct IfaddrsDeleter> ScopedIfaddrs;
+
 namespace android {
 namespace net {
 
diff --git a/server/SockDiag.cpp b/server/SockDiag.cpp
index 6b93a97..55d8dea 100644
--- a/server/SockDiag.cpp
+++ b/server/SockDiag.cpp
@@ -42,12 +42,6 @@
 
 namespace {
 
-struct AddrinfoDeleter {
-  void operator()(addrinfo *a) { if (a) freeaddrinfo(a); }
-};
-
-typedef std::unique_ptr<addrinfo, AddrinfoDeleter> ScopedAddrinfo;
-
 int checkError(int fd) {
     struct {
         nlmsghdr h;