| 1 |
/* Sinit.c: this file contains interfaces to initialize and cleanup. |
| 2 |
* Most o/s's don't need this, but some (WIN32, MSDOS) do. |
| 3 |
* Authors: Charles E. Campbell, Jr. |
| 4 |
* Terry McRoberts |
| 5 |
* Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1 |
| 6 |
* Permission is hereby granted to use and distribute this code, |
| 7 |
* with or without modifications, provided that this copyright |
| 8 |
* notice is copied with it. Like anything else that's free, |
| 9 |
* Sinit.c is provided *as is* and comes with no warranty |
| 10 |
* of any kind, either expressed or implied. By using this |
| 11 |
* software, you agree that in no event will the copyright |
| 12 |
* holder be liable for any damages resulting from the use |
| 13 |
* of this software. |
| 14 |
* Date: Aug 22, 2005 |
| 15 |
*/ |
| 16 |
#include <stdio.h> |
| 17 |
#include "sockets.h" |
| 18 |
|
| 19 |
#if defined(MSDOS) || defined(__WIN32__) || defined(_MSC_VER) |
| 20 |
static int ssl_init= 0; |
| 21 |
#endif |
| 22 |
|
| 23 |
/* --------------------------------------------------------------------- */ |
| 24 |
|
| 25 |
/* Sinit: initializes Sockets */ |
| 26 |
void Sinit() |
| 27 |
{ |
| 28 |
|
| 29 |
#ifdef MSDOS //<<-- Old version (changed back) |
| 30 |
/* initialize WIN/API DOS Socket library */ |
| 31 |
if(ssl_init == 0) { |
| 32 |
ssl_init= 1; |
| 33 |
if(socket_init()) error(XTDIO_ERROR,"socket_init() returned -1, cannot start\n"); |
| 34 |
} |
| 35 |
#endif |
| 36 |
|
| 37 |
#if defined(__WIN32__) || defined(_MSC_VER) //<<-- Old version (changed back) |
| 38 |
if(ssl_init == 0) { |
| 39 |
static WORD wVersionRequested; |
| 40 |
static WSADATA wsaData; |
| 41 |
int err; |
| 42 |
ssl_init= 1; |
| 43 |
wVersionRequested= MAKEWORD(1,1); |
| 44 |
err= WSAStartup(wVersionRequested,&wsaData); |
| 45 |
if(err) error(XTDIO_ERROR,"unable to use sockets, needs version 2.0 or better\n"); |
| 46 |
if(LOBYTE(wsaData.wVersion) != 1 || |
| 47 |
HIBYTE(wsaData.wVersion) != 1) { |
| 48 |
int hiver; |
| 49 |
int lover; |
| 50 |
hiver= LOBYTE(wsaData.wVersion); |
| 51 |
lover= HIBYTE(wsaData.wVersion); |
| 52 |
WSACleanup(); |
| 53 |
error(XTDIO_ERROR,"wrong sockets version (wants 1.1, has %d.%d)\n", |
| 54 |
hiver,lover); |
| 55 |
} |
| 56 |
atexit((void (*)(void)) WSACleanup); |
| 57 |
} |
| 58 |
#endif |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
/* --------------------------------------------------------------------- |
| 63 |
* vim: ts=4 |
| 64 |
*/ |