1 /*--------------------------------------------------------------------*/
2 /*       W S o c k . c                                                */
3 /*                                                                    */
4 /*       Part of BinkD project                                        */
5 /*       WinSock Initialisation/Deinitialisation module               */
6 /*--------------------------------------------------------------------*/
7 
8 /*--------------------------------------------------------------------*/
9 /*       Copyright (c) 1996 by Fydodor Ustinov                        */
10 /*                             FIDONet 2:5020/79                      */
11 /*                                                                    */
12 /*  This program is  free software;  you can  redistribute it and/or  */
13 /*  modify it  under  the terms of the GNU General Public License as  */
14 /*  published  by the  Free Software Foundation; either version 2 of  */
15 /*  the License, or (at your option) any later version. See COPYING.  */
16 /*--------------------------------------------------------------------*/
17 
18 /*--------------------------------------------------------------------*/
19 /*                          RCS Information                           */
20 /*--------------------------------------------------------------------*/
21 
22 /*
23  * $Id: WSock.c,v 2.4.2.1 2014/08/20 06:12:40 gul Exp $
24  *
25  * Revision history:
26  * $Log: WSock.c,v $
27  * Revision 2.4.2.1  2014/08/20 06:12:40  gul
28  * Fixed 100% cpu load if called with poll flag,
29  * backport many fixes related to compilation on win32 and os/2.
30  *
31  * Revision 2.4  2012/01/03 17:25:35  green
32  * Implemented IPv6 support
33  * - replace (almost) all getXbyY function calls with getaddrinfo/getnameinfo (RFC2553) calls
34  * - Add compatibility layer for target systems not supporting RFC2553 calls in rfc2553.[ch]
35  * - Add support for multiple listen sockets -- one for IPv4 and one for IPv6 (use V6ONLY)
36  * - For WIN32 platform add configuration parameter IPV6 (mutually exclusive with BINKD9X)
37  * - On WIN32 platform use Winsock2 API if IPV6 support is requested
38  * - config: node IP address literal + port supported: [<ipv6 address>]:<port>
39  *
40  * Revision 2.3  2003/08/26 22:18:49  gul
41  * Fix compilation under w32-mingw and os2-emx
42  *
43  * Revision 2.2  2003/08/05 05:36:14  hbrew
44  * 'static const char rcsid[]' removed
45  *
46  * Revision 2.1  2003/02/13 19:44:45  gul
47  * Change \r\n -> \n
48  *
49  * Revision 2.0  2001/01/10 12:12:40  gul
50  * Binkd is under CVS again
51  *
52  * Revision 0.01  1996/12/03  10:57:05  ufm
53  *      First revision
54  *
55  */
56 
57 /*--------------------------------------------------------------------*/
58 /*                        System include files                        */
59 /*--------------------------------------------------------------------*/
60 
61 
62 /*--------------------------------------------------------------------*/
63 /*                        Local include files                         */
64 /*--------------------------------------------------------------------*/
65 
66 #include "../sys.h"
67 #include "../iphdr.h"
68 #include "../readcfg.h"
69 #include "../tools.h"
70 
71 /*--------------------------------------------------------------------*/
72 /*                         Global definitions                         */
73 /*--------------------------------------------------------------------*/
74 
75 /*--------------------------------------------------------------------*/
76 /*                          Global variables                          */
77 /*--------------------------------------------------------------------*/
78 
79 /*--------------------------------------------------------------------*/
80 /*                           Local variables                          */
81 /*--------------------------------------------------------------------*/
82 
83 /*--------------------------------------------------------------------*/
84 /*                    Local functions prototypes                      */
85 /*--------------------------------------------------------------------*/
86 
87 /*--------------------------------------------------------------------*/
88 /*    int WinsockIni(void)                                            */
89 /*                                                                    */
90 /*    Initialise Winsock.                                             */
91 /*--------------------------------------------------------------------*/
92 
WinsockIni(void)93 int WinsockIni(void) {
94     WORD wVersionRequested;
95     WSADATA wsaData;
96     int Err;
97 
98     wVersionRequested = MAKEWORD( 1, 1 );
99 
100     Err = WSAStartup(wVersionRequested, &wsaData);
101     if (Err != 0) {
102        Log (0, "Cannot initialise WinSock");
103        return (-1);
104     }
105     /*----------------------------------------------------------------*/
106     /* than 1.1 in addition to 1.1, it will still return 1.1 in       */
107     /* wVersion since that is the version we requested                */
108     /*----------------------------------------------------------------*/
109 
110     if (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1) {
111        Log (0, "WinSock %d.%d detected. Required version 1.1",LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));
112        WSACleanup( );
113        return (-1);
114     }
115     return 0;
116 }
117 
118 /*--------------------------------------------------------------------*/
119 /*    int WinsockClean(void)                                          */
120 /*                                                                    */
121 /*    Initialise Winsock.                                             */
122 /*--------------------------------------------------------------------*/
123 
WinsockClean(void)124 int WinsockClean(void) {
125     WSACleanup();
126     return 0;
127 }
128