Move socket and collection functions to a convenience library

This avoids the iproxy tool from relying on undocumented library ABI.
diff --git a/Makefile.am b/Makefile.am
index 4655b8f..26188a5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
 AUTOMAKE_OPTIONS = foreign
 ACLOCAL_AMFLAGS = -I m4
-SUBDIRS = src include tools
+SUBDIRS = common src include tools
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libusbmuxd.pc
diff --git a/common/Makefile.am b/common/Makefile.am
new file mode 100644
index 0000000..8acf04b
--- /dev/null
+++ b/common/Makefile.am
@@ -0,0 +1,14 @@
+AM_CFLAGS = $(GLOBAL_CFLAGS)
+
+noinst_LTLIBRARIES = libinternalcommon.la
+
+libinternalcommon_la_LIBADD =
+libinternalcommon_la_SOURCES =			\
+	socket.c				\
+	collection.c				\
+	socket.h				\
+	collection.h
+
+if WIN32
+libinternalcommon_la_LIBADD += -lws2_32
+endif
diff --git a/src/collection.c b/common/collection.c
similarity index 100%
rename from src/collection.c
rename to common/collection.c
diff --git a/src/collection.h b/common/collection.h
similarity index 100%
rename from src/collection.h
rename to common/collection.h
diff --git a/src/socket.c b/common/socket.c
similarity index 100%
rename from src/socket.c
rename to common/socket.c
diff --git a/src/socket.h b/common/socket.h
similarity index 100%
rename from src/socket.h
rename to common/socket.h
diff --git a/configure.ac b/configure.ac
index d168d95..93c01c5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,6 +88,7 @@
 
 AC_OUTPUT([
 Makefile
+common/Makefile
 src/Makefile
 include/Makefile
 tools/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 4cd338e..cc6b589 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,15 +1,12 @@
-AM_CPPFLAGS = -I$(top_srcdir)/include
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/common
 
 AM_CFLAGS = $(GLOBAL_CFLAGS) $(libplist_CFLAGS)
 AM_LDFLAGS = $(GLOBAL_LIBS) $(libpthread_LIBS) $(libplist_LIBS)
 
 lib_LTLIBRARIES = libusbmuxd.la
 libusbmuxd_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBUSBMUXD_SO_VERSION) -no-undefined
-libusbmuxd_la_LIBADD =
-libusbmuxd_la_SOURCES = \
-		collection.c collection.h \
-		socket.c socket.h \
-		libusbmuxd.c
+libusbmuxd_la_LIBADD = $(top_builddir)/common/libinternalcommon.la
+libusbmuxd_la_SOURCES = libusbmuxd.c
 
 if WIN32
 libusbmuxd_la_LDFLAGS += -avoid-version
diff --git a/tools/Makefile.am b/tools/Makefile.am
index df6c803..40fa851 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,4 +1,4 @@
-AM_CFLAGS = $(GLOBAL_CFLAGS) -I$(top_srcdir)/src -I$(top_srcdir)/include
+AM_CFLAGS = $(GLOBAL_CFLAGS) -I$(top_srcdir)/common -I$(top_srcdir)/src -I$(top_srcdir)/include
 AM_LDFLAGS = $(libpthread_LIBS)
 
 bin_PROGRAMS = iproxy
@@ -6,5 +6,5 @@
 iproxy_SOURCES = iproxy.c
 iproxy_CFLAGS = $(AM_CFLAGS)
 iproxy_LDFLAGS = $(AM_LDFLAGS)
-iproxy_LDADD = $(top_builddir)/src/libusbmuxd.la
+iproxy_LDADD = $(top_builddir)/src/libusbmuxd.la $(top_builddir)/common/libinternalcommon.la