From 0833499c76f78da21fc33874a485946189a33dad Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Wed, 26 May 2010 20:30:02 +0200 Subject: libusbmuxd: use winsock API for win32 --- libusbmuxd/sock_stuff.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'libusbmuxd/sock_stuff.c') 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 #include #include +#ifdef WIN32 +#include +#include +static int wsa_init = 0; +#else #include #include #include #include #include +#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; -- cgit v1.1-32-gdbae