summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2010-05-26 20:30:02 +0200
committerGravatar Nikias Bassen2010-05-26 20:30:02 +0200
commit0833499c76f78da21fc33874a485946189a33dad (patch)
tree3406bc2729986945020748d176d492c6c4a4628a
parent6cb505257ff848aa7ead80b60b575effc3a915fa (diff)
downloadusbmuxd-0833499c76f78da21fc33874a485946189a33dad.tar.gz
usbmuxd-0833499c76f78da21fc33874a485946189a33dad.tar.bz2
libusbmuxd: use winsock API for win32
-rw-r--r--libusbmuxd/CMakeLists.txt3
-rw-r--r--libusbmuxd/libusbmuxd.c6
-rw-r--r--libusbmuxd/sock_stuff.c26
-rw-r--r--tools/CMakeLists.txt6
-rw-r--r--tools/iproxy.c12
5 files changed, 49 insertions, 4 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;
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 08ea714..64d0d0e 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -2,6 +2,10 @@ include_directories (${CMAKE_SOURCE_DIR}/libusbmuxd)
2link_directories (${CMAKE_BINARY_DIR}/libusbmuxd) 2link_directories (${CMAKE_BINARY_DIR}/libusbmuxd)
3 3
4add_executable(iproxy iproxy.c) 4add_executable(iproxy iproxy.c)
5target_link_libraries(iproxy libusbmuxd pthread) 5if(WIN32)
6 target_link_libraries(iproxy libusbmuxd pthread ws2_32)
7else()
8 target_link_libraries(iproxy libusbmuxd pthread)
9endif()
6 10
7install(TARGETS iproxy RUNTIME DESTINATION bin) 11install(TARGETS iproxy RUNTIME DESTINATION bin)
diff --git a/tools/iproxy.c b/tools/iproxy.c
index 707724a..1855c67 100644
--- a/tools/iproxy.c
+++ b/tools/iproxy.c
@@ -30,11 +30,17 @@ TODO: improve code...
30#include <string.h> 30#include <string.h>
31#include <fcntl.h> 31#include <fcntl.h>
32#include <stddef.h> 32#include <stddef.h>
33#include <sys/socket.h>
34#include <sys/un.h>
35#include <unistd.h> 33#include <unistd.h>
36#include <errno.h> 34#include <errno.h>
35#ifdef WIN32
36#include <windows.h>
37#include <winsock2.h>
38typedef unsigned int socklen_t;
39#else
40#include <sys/socket.h>
41#include <sys/un.h>
37#include <arpa/inet.h> 42#include <arpa/inet.h>
43#endif
38#include <pthread.h> 44#include <pthread.h>
39#include "sock_stuff.h" 45#include "sock_stuff.h"
40#include "usbmuxd.h" 46#include "usbmuxd.h"
@@ -98,7 +104,7 @@ void *run_ctos_loop(void *arg)
98 int recv_len; 104 int recv_len;
99 int sent; 105 int sent;
100 char buffer[131072]; 106 char buffer[131072];
101 pthread_t stoc = 0; 107 pthread_t stoc;
102 108
103 printf("%s: fd = %d\n", __func__, cdata->fd); 109 printf("%s: fd = %d\n", __func__, cdata->fd);
104 110