Commit 3317160c authored by Guenter Knauf's avatar Guenter Knauf
Browse files

Fixed sample to compile for Windows platform.

parent 28526ed6
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -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) {
    /*
@@ -82,7 +96,7 @@ int main(void)

    /* Create the socket "manually" */
    if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
      fprintf(stderr, "ECHOCLNT: Error creating listening socket.\n");
      printf("Error creating listening socket.\n");
      return 3;
    }

@@ -90,7 +104,7 @@ int main(void)
    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)) ==