diff options
Diffstat (limited to 'libusbmuxd')
-rw-r--r-- | libusbmuxd/CMakeLists.txt | 3 | ||||
-rw-r--r-- | libusbmuxd/libusbmuxd.c | 6 | ||||
-rw-r--r-- | libusbmuxd/sock_stuff.c | 26 |
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) if (HAVE_PLIST) message("-- libusbmuxd will be built with protocol version 1 support") endif() +if(WIN32) + set(OPT_LIBS ${OPT_LIBS} ws2_32) +endif() target_link_libraries (libusbmuxd ${CMAKE_THREAD_LIBS_INIT} ${OPT_LIBS}) # '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 #include <errno.h> #include <stdio.h> #include <string.h> +#ifdef WIN32 +#include <windows.h> +#include <winsock2.h> +#define sleep(x) Sleep(x*1000) +#else #include <sys/socket.h> #include <arpa/inet.h> +#endif #include <unistd.h> #include <signal.h> #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 #include <errno.h> #include <sys/time.h> #include <sys/stat.h> +#ifdef WIN32 +#include <windows.h> +#include <winsock2.h> +static int wsa_init = 0; +#else #include <sys/socket.h> #include <sys/un.h> #include <netinet/in.h> #include <netdb.h> #include <arpa/inet.h> +#endif #include "sock_stuff.h" #define RECV_TIMEOUT 20000 @@ -143,6 +149,16 @@ int create_socket(uint16_t port) { int sfd = -1; int yes = 1; +#ifdef WIN32 + WSADATA wsa_data; + if (!wsa_init) { + if (WSAStartup(MAKEWORD(2,2), &wsa_data) != ERROR_SUCCESS) { + fprintf(stderr, "WSAStartup failed!\n"); + ExitProcess(-1); + } + wsa_init = 1; + } +#endif struct sockaddr_in saddr; if (0 > (sfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP))) { @@ -182,6 +198,16 @@ int connect_socket(const char *addr, uint16_t port) int yes = 1; struct hostent *hp; struct sockaddr_in saddr; +#ifdef WIN32 + WSADATA wsa_data; + if (!wsa_init) { + if (WSAStartup(MAKEWORD(2,2), &wsa_data) != ERROR_SUCCESS) { + fprintf(stderr, "WSAStartup failed!\n"); + ExitProcess(-1); + } + wsa_init = 1; + } +#endif if (!addr) { errno = EINVAL; |