From 3317160c1978e4ace9ff093ff50e678645854964 Mon Sep 17 00:00:00 2001 From: Guenter Knauf Date: Wed, 21 Sep 2011 18:09:34 +0200 Subject: [PATCH] Fixed sample to compile for Windows platform. --- docs/examples/externalsocket.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c index 39440af..5951c07 100644 --- a/docs/examples/externalsocket.c +++ b/docs/examples/externalsocket.c @@ -28,13 +28,17 @@ #include #include -#include -#include - -#include /* socket definitions */ +#ifdef WIN32 +#include +#include +#include +#define close closesocket +#else #include /* socket types */ +#include /* socket definitions */ #include /* inet (3) funtions */ #include /* misc. UNIX functions */ +#endif #include @@ -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)) == -- 2.7.4