| 1 | /* $Id: socket.cpp,v 1.12 2002-03-08 11:36:11 sandervl Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * based on Windows Sockets 1.1 specs | 
|---|
| 4 | * (ftp.microsoft.com:/Advsys/winsock/spec11/WINSOCK.TXT) | 
|---|
| 5 | * | 
|---|
| 6 | * (C) 1993,1994,1996,1997 John Brezak, Erik Bos, Alex Korobka. | 
|---|
| 7 | * | 
|---|
| 8 | * NOTE: If you make any changes to fix a particular app, make sure | 
|---|
| 9 | * they don't break something else like Netscape or telnet and ftp | 
|---|
| 10 | * clients and servers (www.winsite.com got a lot of those). | 
|---|
| 11 | * | 
|---|
| 12 | * NOTE 2: Many winsock structs such as servent, hostent, protoent, ... | 
|---|
| 13 | * are used with 1-byte alignment for Win16 programs and 4-byte alignment | 
|---|
| 14 | * for Win32 programs in winsock.h. winsock2.h uses forced 4-byte alignment. | 
|---|
| 15 | * So we have non-forced (just as MSDN) ws_XXXXent (winsock.h), 4-byte forced | 
|---|
| 16 | * ws_XXXXent32 (winsock2.h) and 1-byte forced ws_XXXXent16 (winsock16.h). | 
|---|
| 17 | */ | 
|---|
| 18 |  | 
|---|
| 19 |  | 
|---|
| 20 | /***************************************************************************** | 
|---|
| 21 | * Includes                                                                  * | 
|---|
| 22 | *****************************************************************************/ | 
|---|
| 23 |  | 
|---|
| 24 | #include <odin.h> | 
|---|
| 25 | #include <winsock2.h> | 
|---|
| 26 | #include <debugtools.h> | 
|---|
| 27 | #include <odinwrap.h> | 
|---|
| 28 |  | 
|---|
| 29 |  | 
|---|
| 30 | ODINDEBUGCHANNEL(WS2_32-SOCKET) | 
|---|
| 31 |  | 
|---|
| 32 |  | 
|---|
| 33 | /*********************************************************************** | 
|---|
| 34 | *      WSACreateEvent()          (WS2_32.???) | 
|---|
| 35 | * | 
|---|
| 36 | */ | 
|---|
| 37 | ODINFUNCTION0(WSAEVENT, WSACreateEvent) | 
|---|
| 38 | { | 
|---|
| 39 | /* Create a manual-reset event, with initial state: unsignealed */ | 
|---|
| 40 |  | 
|---|
| 41 | return CreateEventA(NULL, TRUE, FALSE, NULL); | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 | ODINFUNCTION1(BOOL, WSASetEvent, | 
|---|
| 45 | WSAEVENT, hEvent) | 
|---|
| 46 | { | 
|---|
| 47 | return SetEvent(hEvent); | 
|---|
| 48 | } | 
|---|
| 49 |  | 
|---|
| 50 | /*********************************************************************** | 
|---|
| 51 | *      WSACloseEvent()          (WS2_32.???) | 
|---|
| 52 | * | 
|---|
| 53 | */ | 
|---|
| 54 | ODINFUNCTION1(BOOL, WSACloseEvent, | 
|---|
| 55 | WSAEVENT, hEvent) | 
|---|
| 56 | { | 
|---|
| 57 | return CloseHandle(hEvent); | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | /*********************************************************************** | 
|---|
| 61 | *      WSASocketA()          (WS2_32.???) | 
|---|
| 62 | * | 
|---|
| 63 | */ | 
|---|
| 64 | ODINFUNCTION6(SOCKET, WSASocketA, | 
|---|
| 65 | int, af, | 
|---|
| 66 | int, type, | 
|---|
| 67 | int, protocol, | 
|---|
| 68 | LPWSAPROTOCOL_INFOA, lpProtocolInfo, | 
|---|
| 69 | GROUP, g, | 
|---|
| 70 | DWORD, dwFlags) | 
|---|
| 71 | { | 
|---|
| 72 | dprintf(("WSASocketA incorrectly implemented")); | 
|---|
| 73 | /* | 
|---|
| 74 | FIXME: The "advanced" parameters of WSASocketA (lpProtocolInfo, | 
|---|
| 75 | g, dwFlags) are ignored. | 
|---|
| 76 | */ | 
|---|
| 77 |  | 
|---|
| 78 | TRACE("WSASocketA af=%d type=%d protocol=%d protocol_info=%p group=%d flags=0x%lx\n", | 
|---|
| 79 | af, type, protocol, lpProtocolInfo, g, dwFlags ); | 
|---|
| 80 |  | 
|---|
| 81 | return ( socket (af, type, protocol) ); | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 | /*********************************************************************** | 
|---|
| 85 | *      WSASocketA()          (WS2_32.???) | 
|---|
| 86 | * | 
|---|
| 87 | */ | 
|---|
| 88 | ODINFUNCTION6(SOCKET, WSASocketW, | 
|---|
| 89 | int, af, | 
|---|
| 90 | int, type, | 
|---|
| 91 | int, protocol, | 
|---|
| 92 | LPWSAPROTOCOL_INFOW, lpProtocolInfo, | 
|---|
| 93 | GROUP, g, | 
|---|
| 94 | DWORD, dwFlags) | 
|---|
| 95 | { | 
|---|
| 96 | dprintf(("WSASocketW incorrectly implemented")); | 
|---|
| 97 | /* | 
|---|
| 98 | FIXME: The "advanced" parameters of WSASocketA (lpProtocolInfo, | 
|---|
| 99 | g, dwFlags) are ignored. | 
|---|
| 100 | */ | 
|---|
| 101 |  | 
|---|
| 102 | TRACE("WSASocketW af=%d type=%d protocol=%d protocol_info=%p group=%d flags=0x%lx\n", | 
|---|
| 103 | af, type, protocol, lpProtocolInfo, g, dwFlags ); | 
|---|
| 104 |  | 
|---|
| 105 | return ( socket (af, type, protocol) ); | 
|---|
| 106 | } | 
|---|
| 107 | //****************************************************************************** | 
|---|
| 108 | //****************************************************************************** | 
|---|