From ada9bc2b24ecb73c78e07aed933dc99f1d44ed3c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 20 Feb 2001 13:56:38 +0000 Subject: win32sockets.c is now added with winsock init/cleanup example functions --- docs/examples/Makefile.am | 1 + docs/examples/curlgtk.c | 10 +++++++++- docs/examples/postit.c | 3 +++ docs/examples/sepheaders.c | 13 +++++++++++++ docs/examples/simple.c | 13 +++++++++++++ docs/examples/win32sockets.c | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 docs/examples/win32sockets.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index b8e9bc6a2..35b0a8817 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -6,6 +6,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c \ + win32sockets.c \ getpageinvar.php simpleget.php simplepost.php all: diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c index 48b10e9c7..7c9ce2a1b 100644 --- a/docs/examples/curlgtk.c +++ b/docs/examples/curlgtk.c @@ -1,4 +1,12 @@ -/* curlgtk.c */ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ /* Copyright (c) 2000 David Odin (aka DindinX) for MandrakeSoft */ /* an attempt to use the curl library in concert with a gtk-threaded application */ diff --git a/docs/examples/postit.c b/docs/examples/postit.c index 710a14967..e811aa24a 100644 --- a/docs/examples/postit.c +++ b/docs/examples/postit.c @@ -21,6 +21,9 @@ * This exact source code has not been verified to work. */ +/* to make this work under windows, use the win32-functions from the + win32socket.c file as well */ + #include #include diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index 724e14157..ead557214 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -1,3 +1,16 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +/* to make this work under windows, use the win32-functions from the + win32socket.c file as well */ + #include #include #include diff --git a/docs/examples/simple.c b/docs/examples/simple.c index e6138c4e1..907d5e8e4 100644 --- a/docs/examples/simple.c +++ b/docs/examples/simple.c @@ -1,9 +1,22 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + #include #include #include #include +/* to make this work under windows, use the win32-functions from the + win32socket.c file as well */ + int main(int argc, char **argv) { CURL *curl; diff --git a/docs/examples/win32sockets.c b/docs/examples/win32sockets.c new file mode 100644 index 000000000..f052299d6 --- /dev/null +++ b/docs/examples/win32sockets.c @@ -0,0 +1,41 @@ +/* + * These are example functions doing socket init that Windows + * require. If you don't use windows, you can safely ignore this crap. + */ + +#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) +static void win32_cleanup(void) +{ + WSACleanup(); +} + +static CURLcode 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 */ +} -- cgit v1.2.3