diff options
Diffstat (limited to 'libusbmuxd/sock_stuff.c')
| -rw-r--r-- | libusbmuxd/sock_stuff.c | 26 |
1 files changed, 26 insertions, 0 deletions
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> | ||
| 35 | static 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; |
