summaryrefslogtreecommitdiffstats
path: root/libusbmuxd
diff options
context:
space:
mode:
Diffstat (limited to 'libusbmuxd')
-rw-r--r--libusbmuxd/CMakeLists.txt3
-rw-r--r--libusbmuxd/libusbmuxd.c6
-rw-r--r--libusbmuxd/sock_stuff.c26
3 files changed, 35 insertions, 0 deletions
diff --git a/libusbmuxd/CMakeLists.txt b/libusbmuxd/CMakeLists.txt
index 236cca3..0d7d897 100644
--- a/libusbmuxd/CMakeLists.txt
+++ b/libusbmuxd/CMakeLists.txt
@@ -7,6 +7,9 @@ find_library (PTHREAD pthread)
7if (HAVE_PLIST) 7if (HAVE_PLIST)
8 message("-- libusbmuxd will be built with protocol version 1 support") 8 message("-- libusbmuxd will be built with protocol version 1 support")
9endif() 9endif()
10if(WIN32)
11 set(OPT_LIBS ${OPT_LIBS} ws2_32)
12endif()
10target_link_libraries (libusbmuxd ${CMAKE_THREAD_LIBS_INIT} ${OPT_LIBS}) 13target_link_libraries (libusbmuxd ${CMAKE_THREAD_LIBS_INIT} ${OPT_LIBS})
11 14
12# 'lib' is a UNIXism, the proper CMake target is usbmuxd 15# 'lib' is a UNIXism, the proper CMake target is usbmuxd
diff --git a/libusbmuxd/libusbmuxd.c b/libusbmuxd/libusbmuxd.c
index f465deb..80ffdd7 100644
--- a/libusbmuxd/libusbmuxd.c
+++ b/libusbmuxd/libusbmuxd.c
@@ -26,8 +26,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26#include <errno.h> 26#include <errno.h>
27#include <stdio.h> 27#include <stdio.h>
28#include <string.h> 28#include <string.h>
29#ifdef WIN32
30#include <windows.h>
31#include <winsock2.h>
32#define sleep(x) Sleep(x*1000)
33#else
29#include <sys/socket.h> 34#include <sys/socket.h>
30#include <arpa/inet.h> 35#include <arpa/inet.h>
36#endif
31#include <unistd.h> 37#include <unistd.h>
32#include <signal.h> 38#include <signal.h>
33#include <pthread.h> 39#include <pthread.h>
diff --git a/libusbmuxd/sock_stuff.c b/libusbmuxd/sock_stuff.c
index 33ac3e6..0592f6b 100644
--- a/libusbmuxd/sock_stuff.c
+++ b/libusbmuxd/sock_stuff.c
@@ -29,11 +29,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29#include <errno.h> 29#include <errno.h>
30#include <sys/time.h> 30#include <sys/time.h>
31#include <sys/stat.h> 31#include <sys/stat.h>
32#ifdef WIN32
33#include <windows.h>
34#include <winsock2.h>
35static int wsa_init = 0;
36#else
32#include <sys/socket.h> 37#include <sys/socket.h>
33#include <sys/un.h> 38#include <sys/un.h>
34#include <netinet/in.h> 39#include <netinet/in.h>
35#include <netdb.h> 40#include <netdb.h>
36#include <arpa/inet.h> 41#include <arpa/inet.h>
42#endif
37#include "sock_stuff.h" 43#include "sock_stuff.h"
38 44
39#define RECV_TIMEOUT 20000 45#define RECV_TIMEOUT 20000
@@ -143,6 +149,16 @@ int create_socket(uint16_t port)
143{ 149{
144 int sfd = -1; 150 int sfd = -1;
145 int yes = 1; 151 int yes = 1;
152#ifdef WIN32
153 WSADATA wsa_data;
154 if (!wsa_init) {
155 if (WSAStartup(MAKEWORD(2,2), &wsa_data) != ERROR_SUCCESS) {
156 fprintf(stderr, "WSAStartup failed!\n");
157 ExitProcess(-1);
158 }
159 wsa_init = 1;
160 }
161#endif
146 struct sockaddr_in saddr; 162 struct sockaddr_in saddr;
147 163
148 if (0 > (sfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP))) { 164 if (0 > (sfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP))) {
@@ -182,6 +198,16 @@ int connect_socket(const char *addr, uint16_t port)
182 int yes = 1; 198 int yes = 1;
183 struct hostent *hp; 199 struct hostent *hp;
184 struct sockaddr_in saddr; 200 struct sockaddr_in saddr;
201#ifdef WIN32
202 WSADATA wsa_data;
203 if (!wsa_init) {
204 if (WSAStartup(MAKEWORD(2,2), &wsa_data) != ERROR_SUCCESS) {
205 fprintf(stderr, "WSAStartup failed!\n");
206 ExitProcess(-1);
207 }
208 wsa_init = 1;
209 }
210#endif
185 211
186 if (!addr) { 212 if (!addr) {
187 errno = EINVAL; 213 errno = EINVAL;