diff options
author | Guenter Knauf <lists@gknw.net> | 2011-09-21 18:09:34 +0200 |
---|---|---|
committer | Guenter Knauf <lists@gknw.net> | 2011-09-21 18:09:34 +0200 |
commit | 3317160c1978e4ace9ff093ff50e678645854964 (patch) | |
tree | b876c825e5af233687f3ee45999b883f6e0da778 | |
parent | 28526ed6e080b5c74fde65fd24abb1324f742789 (diff) |
Fixed sample to compile for Windows platform.
-rw-r--r-- | docs/examples/externalsocket.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c index 39440afd5..5951c078e 100644 --- a/docs/examples/externalsocket.c +++ b/docs/examples/externalsocket.c @@ -28,13 +28,17 @@ #include <stdlib.h> #include <curl/curl.h> -#include <sys/types.h> -#include <sys/socket.h> - -#include <sys/socket.h> /* socket definitions */ +#ifdef WIN32 +#include <windows.h> +#include <winsock2.h> +#include <ws2tcpip.h> +#define close closesocket +#else #include <sys/types.h> /* socket types */ +#include <sys/socket.h> /* socket definitions */ #include <arpa/inet.h> /* inet (3) funtions */ #include <unistd.h> /* misc. UNIX functions */ +#endif #include <errno.h> @@ -72,6 +76,16 @@ int main(void) struct sockaddr_in servaddr; /* socket address structure */ curl_socket_t sockfd; +#ifdef WIN32 + WSADATA wsaData; + int initwsa; + + if((initwsa = WSAStartup(MAKEWORD(2,0), &wsaData)) != 0) { + printf("WSAStartup failed: %d\n", initwsa); + return 1; + } +#endif + curl = curl_easy_init(); if(curl) { /* @@ -81,16 +95,16 @@ int main(void) curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999"); /* Create the socket "manually" */ - if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { - fprintf(stderr, "ECHOCLNT: Error creating listening socket.\n"); + if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { + printf("Error creating listening socket.\n"); return 3; } memset(&servaddr, 0, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_port = htons(PORTNUM); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(PORTNUM); - if(inet_aton(IPADDR, &servaddr.sin_addr) <= 0 ) + if (INADDR_NONE == (servaddr.sin_addr.s_addr = inet_addr(IPADDR))) return 2; if(connect(sockfd,(struct sockaddr *) &servaddr, sizeof(servaddr)) == |