aboutsummaryrefslogtreecommitdiff
path: root/docs/examples/win32sockets.c
blob: 5f791c8b5e5fa26a7d4fd78dbc3b50681f5072aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

/*
 * Note: This is only required if you use curl 7.8 or lower, later 
 * versions provide an option to curl_global_init() that does the
 * win32 initialization for you.
 */

/*
 * These are example functions doing socket init that Windows
 * require. If you don't use windows, you can safely ignore this crap.
 */

#include <windows.h>

void win32_cleanup(void)
{
  WSACleanup();
}

int win32_init(void)
{
  WORD wVersionRequested;  
  WSADATA wsaData; 
  int err; 
  wVersionRequested = MAKEWORD(1, 1); 
    
  err = WSAStartup(wVersionRequested, &wsaData); 
    
  if (err != 0) 
    /* Tell the user that we couldn't find a useable */ 
    /* winsock.dll.     */ 
    return 1;
    
  /* Confirm that the Windows Sockets DLL supports 1.1.*/ 
  /* Note that if the DLL supports versions greater */ 
  /* than 1.1 in addition to 1.1, it will still return */ 
  /* 1.1 in wVersion since that is the version we */ 
  /* requested. */ 
    
  if ( LOBYTE( wsaData.wVersion ) != 1 || 
       HIBYTE( wsaData.wVersion ) != 1 ) { 
    /* Tell the user that we couldn't find a useable */ 

    /* winsock.dll. */ 
    WSACleanup(); 
    return 1; 
  }
  return 0; /* 0 is ok */
}