| 1 | /* $Id: wsock32.cpp,v 1.1 1999-12-07 20:19:57 achimha Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * | 
|---|
| 5 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 6 | * | 
|---|
| 7 | * Win32 SOCK32 for OS/2 | 
|---|
| 8 | * | 
|---|
| 9 | * 1998/08/25 Vince Vielhaber | 
|---|
| 10 | * | 
|---|
| 11 | * @(#) wsock32.c       1.0.0   1998/08/25 VV initial release | 
|---|
| 12 | *                      1.0.1   1999/04/27 VV cleanup and implement select. | 
|---|
| 13 | * | 
|---|
| 14 | */ | 
|---|
| 15 |  | 
|---|
| 16 | /* Remark: | 
|---|
| 17 | * PH 1999/11/10 memory leak as WSOCKTHREADDATA is NOT yet | 
|---|
| 18 | *               freed when thread dies! | 
|---|
| 19 | * PH 1999/11/10 asyncSelect() still left to proper implementation | 
|---|
| 20 | */ | 
|---|
| 21 |  | 
|---|
| 22 |  | 
|---|
| 23 | /***************************************************************************** | 
|---|
| 24 | * Includes                                                                  * | 
|---|
| 25 | *****************************************************************************/ | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | #define INCL_DOSPROCESS     /* Process and thread values */ | 
|---|
| 29 | #define INCL_DOSFILEMGR     /* for DosRead and DosWrite */ | 
|---|
| 30 | #define INCL_DOSQUEUES      /* for unnamed pipes */ | 
|---|
| 31 | #define INCL_DOSERRORS      /* DOS error values          */ | 
|---|
| 32 | #define INCL_WINMESSAGEMGR  /* Window Message Functions     */ | 
|---|
| 33 | #define INCL_WINMENUS       /* Window Menu Functions        */ | 
|---|
| 34 |  | 
|---|
| 35 | /* this is for IBM TCP/IP 5.0 headers as present in the current Warp 4 toolkit */ | 
|---|
| 36 | #define TCPV40HDRS 1 | 
|---|
| 37 |  | 
|---|
| 38 | #define VV_BSD_SELECT       /* undefine this if it interferes with other routines */ | 
|---|
| 39 |  | 
|---|
| 40 | #ifdef VV_BSD_SELECT | 
|---|
| 41 | # define BSD_SELECT | 
|---|
| 42 | #endif | 
|---|
| 43 |  | 
|---|
| 44 | #include <os2wrap.h>                     //Odin32 OS/2 api wrappers | 
|---|
| 45 | #include <stdio.h> | 
|---|
| 46 | #include <stdlib.h> | 
|---|
| 47 | #include <stddef.h> | 
|---|
| 48 | #include <string.h> | 
|---|
| 49 | #include <ctype.h> | 
|---|
| 50 | #include <types.h> | 
|---|
| 51 | #include <odinwrap.h> | 
|---|
| 52 | #include <netdb.h> | 
|---|
| 53 | #include <sys/socket.h> | 
|---|
| 54 | #include <sys/ioctl.h> | 
|---|
| 55 | #include <netinet/in.h> | 
|---|
| 56 |  | 
|---|
| 57 | #ifdef VV_BSD_SELECT | 
|---|
| 58 | # include <sys/select.h> | 
|---|
| 59 | #endif | 
|---|
| 60 |  | 
|---|
| 61 | #include <sys/time.h> | 
|---|
| 62 | #include <win32type.h> | 
|---|
| 63 | #include <wprocess.h> | 
|---|
| 64 | #include <heapstring.h> | 
|---|
| 65 |  | 
|---|
| 66 | #include "wsock32const.h" | 
|---|
| 67 | #include "wsock32.h" | 
|---|
| 68 | #include "misc.h" | 
|---|
| 69 |  | 
|---|
| 70 |  | 
|---|
| 71 | ODINDEBUGCHANNEL(WSOCK32-WSOCK32) | 
|---|
| 72 |  | 
|---|
| 73 |  | 
|---|
| 74 | /***************************************************************************** | 
|---|
| 75 | * Defines                                                                   * | 
|---|
| 76 | *****************************************************************************/ | 
|---|
| 77 |  | 
|---|
| 78 |  | 
|---|
| 79 | #ifdef FD_CLR | 
|---|
| 80 | #undef FD_CLR | 
|---|
| 81 | #define FD_CLR(x,y) WFD_CLR(x,y) | 
|---|
| 82 | #undef FD_SET | 
|---|
| 83 | #define FD_SET(x,y) WFD_SET(x,y) | 
|---|
| 84 | #undef FD_ZERO | 
|---|
| 85 | #define FD_ZERO(x) WFD_ZERO(x) | 
|---|
| 86 | #undef FD_ISSET | 
|---|
| 87 | #define FD_ISSET(x,y) WFD_SET(x,y) | 
|---|
| 88 | #endif | 
|---|
| 89 |  | 
|---|
| 90 | #ifndef ERROR_SUCCESS | 
|---|
| 91 | #define ERROR_SUCCESS 0 | 
|---|
| 92 | #endif | 
|---|
| 93 |  | 
|---|
| 94 |  | 
|---|
| 95 |  | 
|---|
| 96 | /***************************************************************************** | 
|---|
| 97 | * Structures                                                                * | 
|---|
| 98 | *****************************************************************************/ | 
|---|
| 99 |  | 
|---|
| 100 | typedef struct sockaddr* PSOCKADDR; | 
|---|
| 101 |  | 
|---|
| 102 | //typedef struct _TRANSMIT_FILE_BUFFERS { | 
|---|
| 103 | //    PVOID Head; | 
|---|
| 104 | //    DWORD HeadLength; | 
|---|
| 105 | //    PVOID Tail; | 
|---|
| 106 | //    DWORD TailLength; | 
|---|
| 107 | //} TRANSMIT_FILE_BUFFERS, *PTRANSMIT_FILE_BUFFERS, *LPTRANSMIT_FILE_BUFFERS; | 
|---|
| 108 | // | 
|---|
| 109 | //BOOL, OS2TransmitFile, //, IN, SOCKET, hSocket, //, IN, HANDLE, hFile, //, IN, DWORD, nNumberOfBytesToWrite, //, IN DWORD nNumberOfBytesPerSend, | 
|---|
| 110 | //    IN LPOVERLAPPED lpOverlapped, | 
|---|
| 111 | //    IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers, | 
|---|
| 112 | //    IN DWORD dwReserved) | 
|---|
| 113 | //{ | 
|---|
| 114 | //    return FALSE; | 
|---|
| 115 | //} | 
|---|
| 116 |  | 
|---|
| 117 |  | 
|---|
| 118 | /***************************************************************************** | 
|---|
| 119 | * Prototypes                                                                * | 
|---|
| 120 | *****************************************************************************/ | 
|---|
| 121 |  | 
|---|
| 122 |  | 
|---|
| 123 | /***************************************************************************** | 
|---|
| 124 | * Local variables                                                           * | 
|---|
| 125 | *****************************************************************************/ | 
|---|
| 126 |  | 
|---|
| 127 | static WSOCKTHREADDATA wstdFallthru; // for emergency only | 
|---|
| 128 |  | 
|---|
| 129 |  | 
|---|
| 130 | /***************************************************************************** | 
|---|
| 131 | * Name      : | 
|---|
| 132 | * Purpose   : | 
|---|
| 133 | * Parameters: | 
|---|
| 134 | * Variables : | 
|---|
| 135 | * Result    : | 
|---|
| 136 | * Remark    : free memory when thread dies | 
|---|
| 137 | * Status    : UNTESTED STUB | 
|---|
| 138 | * | 
|---|
| 139 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 140 | *****************************************************************************/ | 
|---|
| 141 |  | 
|---|
| 142 | PWSOCKTHREADDATA iQueryWsockThreadData(void) | 
|---|
| 143 | { | 
|---|
| 144 | struct _THDB*     pThreadDB = (struct _THDB*)GetThreadTHDB(); | 
|---|
| 145 | PWSOCKTHREADDATA pwstd; | 
|---|
| 146 |  | 
|---|
| 147 | // check for existing pointer | 
|---|
| 148 | if (pThreadDB != NULL) | 
|---|
| 149 | { | 
|---|
| 150 | if (pThreadDB->pWsockData == NULL) | 
|---|
| 151 | { | 
|---|
| 152 | // allocate on demand + initialize | 
|---|
| 153 | pwstd = (PWSOCKTHREADDATA)HEAP_malloc (sizeof(WSOCKTHREADDATA)); | 
|---|
| 154 | pThreadDB->pWsockData = (LPVOID)pwstd; | 
|---|
| 155 | } | 
|---|
| 156 | else | 
|---|
| 157 | // use already allocated memory | 
|---|
| 158 | pwstd = (PWSOCKTHREADDATA)pThreadDB->pWsockData; | 
|---|
| 159 | } | 
|---|
| 160 |  | 
|---|
| 161 | if (pwstd == NULL) | 
|---|
| 162 | pwstd = &wstdFallthru; // no memory and not allocated already | 
|---|
| 163 |  | 
|---|
| 164 | return pwstd; | 
|---|
| 165 | } | 
|---|
| 166 |  | 
|---|
| 167 |  | 
|---|
| 168 | /***************************************************************************** | 
|---|
| 169 | * Name      : | 
|---|
| 170 | * Purpose   : | 
|---|
| 171 | * Parameters: | 
|---|
| 172 | * Variables : | 
|---|
| 173 | * Result    : | 
|---|
| 174 | * Remark    : | 
|---|
| 175 | * Status    : UNTESTED STUB | 
|---|
| 176 | * | 
|---|
| 177 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 178 | *****************************************************************************/ | 
|---|
| 179 |  | 
|---|
| 180 | #define CASEERR2(a) case SOC##a: case a: return WSA##a; | 
|---|
| 181 | #define CASEERR1(a) case SOC##a: return WSA##a; | 
|---|
| 182 |  | 
|---|
| 183 | int iTranslateSockErrToWSock(int iError) | 
|---|
| 184 | { | 
|---|
| 185 | switch(iError) | 
|---|
| 186 | { | 
|---|
| 187 | CASEERR2(EINTR) | 
|---|
| 188 | CASEERR2(EBADF) | 
|---|
| 189 | CASEERR2(EACCES) | 
|---|
| 190 | CASEERR2(EINVAL) | 
|---|
| 191 | CASEERR2(EMFILE) | 
|---|
| 192 |  | 
|---|
| 193 | CASEERR1(EWOULDBLOCK) | 
|---|
| 194 | CASEERR1(EINPROGRESS) | 
|---|
| 195 | CASEERR1(EALREADY) | 
|---|
| 196 | CASEERR1(ENOTSOCK) | 
|---|
| 197 | //  CASEERR1(EDESTADRREQ) | 
|---|
| 198 | CASEERR1(EMSGSIZE) | 
|---|
| 199 | CASEERR1(EPROTOTYPE) | 
|---|
| 200 | CASEERR1(ENOPROTOOPT) | 
|---|
| 201 | CASEERR1(EPROTONOSUPPORT) | 
|---|
| 202 | CASEERR1(ESOCKTNOSUPPORT) | 
|---|
| 203 | CASEERR1(EOPNOTSUPP) | 
|---|
| 204 | CASEERR1(EPFNOSUPPORT) | 
|---|
| 205 | CASEERR1(EAFNOSUPPORT) | 
|---|
| 206 | CASEERR1(EADDRINUSE) | 
|---|
| 207 | CASEERR1(EADDRNOTAVAIL) | 
|---|
| 208 | CASEERR1(ENETDOWN) | 
|---|
| 209 | CASEERR1(ENETUNREACH) | 
|---|
| 210 | CASEERR1(ENETRESET) | 
|---|
| 211 | CASEERR1(ECONNABORTED) | 
|---|
| 212 | CASEERR1(ECONNRESET) | 
|---|
| 213 | CASEERR1(ENOBUFS) | 
|---|
| 214 | CASEERR1(EISCONN) | 
|---|
| 215 | CASEERR1(ENOTCONN) | 
|---|
| 216 | CASEERR1(ESHUTDOWN) | 
|---|
| 217 | CASEERR1(ETOOMANYREFS) | 
|---|
| 218 | CASEERR1(ETIMEDOUT) | 
|---|
| 219 | CASEERR1(ECONNREFUSED) | 
|---|
| 220 | CASEERR1(ELOOP) | 
|---|
| 221 | CASEERR1(ENAMETOOLONG) | 
|---|
| 222 | CASEERR1(EHOSTDOWN) | 
|---|
| 223 | CASEERR1(EHOSTUNREACH) | 
|---|
| 224 |  | 
|---|
| 225 | CASEERR1(ENOTEMPTY) | 
|---|
| 226 | //    CASEERR(EPROCLIM) | 
|---|
| 227 | //    CASEERR(EUSERS) | 
|---|
| 228 | //    CASEERR(EDQUOT) | 
|---|
| 229 | //    CASEERR(ESTALE) | 
|---|
| 230 | //    CASEERR(EREMOTE) | 
|---|
| 231 | //    CASEERR(EDISCON) | 
|---|
| 232 |  | 
|---|
| 233 |  | 
|---|
| 234 | default: | 
|---|
| 235 | dprintf(("WSOCK32: Unknown error condition: %d\n", | 
|---|
| 236 | iError)); | 
|---|
| 237 | return iError; | 
|---|
| 238 | } | 
|---|
| 239 | } | 
|---|
| 240 |  | 
|---|
| 241 |  | 
|---|
| 242 | /***************************************************************************** | 
|---|
| 243 | * Name      : | 
|---|
| 244 | * Purpose   : | 
|---|
| 245 | * Parameters: | 
|---|
| 246 | * Variables : | 
|---|
| 247 | * Result    : | 
|---|
| 248 | * Remark    : | 
|---|
| 249 | * Status    : UNTESTED STUB | 
|---|
| 250 | * | 
|---|
| 251 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 252 | *****************************************************************************/ | 
|---|
| 253 |  | 
|---|
| 254 | ODINFUNCTION2(int, OS2__WSAFDIsSet, SOCKET,       fd, | 
|---|
| 255 | Wfd_set FAR*, set) | 
|---|
| 256 | { | 
|---|
| 257 | int i = set->fd_count; | 
|---|
| 258 |  | 
|---|
| 259 | while (i--) | 
|---|
| 260 | if (set->fd_array[i] == fd) | 
|---|
| 261 | return 1; | 
|---|
| 262 |  | 
|---|
| 263 | return 0; | 
|---|
| 264 | } | 
|---|
| 265 |  | 
|---|
| 266 |  | 
|---|
| 267 | /***************************************************************************** | 
|---|
| 268 | * Name      : | 
|---|
| 269 | * Purpose   : | 
|---|
| 270 | * Parameters: | 
|---|
| 271 | * Variables : | 
|---|
| 272 | * Result    : | 
|---|
| 273 | * Remark    : | 
|---|
| 274 | * Status    : UNTESTED STUB | 
|---|
| 275 | * | 
|---|
| 276 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 277 | *****************************************************************************/ | 
|---|
| 278 |  | 
|---|
| 279 | ODINFUNCTION3(SOCKET,OS2accept,SOCKET,    s, | 
|---|
| 280 | PSOCKADDR, addr, | 
|---|
| 281 | int*,      addrlen) | 
|---|
| 282 | { | 
|---|
| 283 | SOCKET rc = accept(s,addr,addrlen); | 
|---|
| 284 |  | 
|---|
| 285 | if (rc == INVALID_SOCKET) | 
|---|
| 286 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 287 | else | 
|---|
| 288 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 289 |  | 
|---|
| 290 | return rc; | 
|---|
| 291 | } | 
|---|
| 292 |  | 
|---|
| 293 |  | 
|---|
| 294 | /***************************************************************************** | 
|---|
| 295 | * Name      : | 
|---|
| 296 | * Purpose   : | 
|---|
| 297 | * Parameters: | 
|---|
| 298 | * Variables : | 
|---|
| 299 | * Result    : | 
|---|
| 300 | * Remark    : | 
|---|
| 301 | * Status    : UNTESTED STUB | 
|---|
| 302 | * | 
|---|
| 303 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 304 | *****************************************************************************/ | 
|---|
| 305 |  | 
|---|
| 306 | ODINFUNCTION3(int,OS2bind,SOCKET,          s, | 
|---|
| 307 | const struct sockaddr *, addr, | 
|---|
| 308 | int,             namelen) | 
|---|
| 309 | { | 
|---|
| 310 | int rc = bind(s,(PSOCKADDR)addr,namelen); | 
|---|
| 311 |  | 
|---|
| 312 | if (rc < 0) | 
|---|
| 313 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 314 | else | 
|---|
| 315 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 316 | return rc; | 
|---|
| 317 | } | 
|---|
| 318 |  | 
|---|
| 319 |  | 
|---|
| 320 | /***************************************************************************** | 
|---|
| 321 | * Name      : | 
|---|
| 322 | * Purpose   : | 
|---|
| 323 | * Parameters: | 
|---|
| 324 | * Variables : | 
|---|
| 325 | * Result    : | 
|---|
| 326 | * Remark    : | 
|---|
| 327 | * Status    : UNTESTED STUB | 
|---|
| 328 | * | 
|---|
| 329 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 330 | *****************************************************************************/ | 
|---|
| 331 |  | 
|---|
| 332 | ODINFUNCTION1(int,OS2closesocket,SOCKET,s) | 
|---|
| 333 | { | 
|---|
| 334 | int rc = soclose((int)s); | 
|---|
| 335 |  | 
|---|
| 336 | if (rc < 0) | 
|---|
| 337 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 338 | else | 
|---|
| 339 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 340 |  | 
|---|
| 341 | return rc; | 
|---|
| 342 | } | 
|---|
| 343 |  | 
|---|
| 344 |  | 
|---|
| 345 | /***************************************************************************** | 
|---|
| 346 | * Name      : | 
|---|
| 347 | * Purpose   : | 
|---|
| 348 | * Parameters: | 
|---|
| 349 | * Variables : | 
|---|
| 350 | * Result    : | 
|---|
| 351 | * Remark    : | 
|---|
| 352 | * Status    : UNTESTED STUB | 
|---|
| 353 | * | 
|---|
| 354 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 355 | *****************************************************************************/ | 
|---|
| 356 |  | 
|---|
| 357 | ODINFUNCTION3(int,OS2connect,SOCKET,          s, | 
|---|
| 358 | const struct sockaddr*, name, | 
|---|
| 359 | int,             namelen) | 
|---|
| 360 | { | 
|---|
| 361 | int rc = connect(s, | 
|---|
| 362 | (PSOCKADDR)name, | 
|---|
| 363 | namelen); | 
|---|
| 364 |  | 
|---|
| 365 | if (rc < 0) | 
|---|
| 366 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 367 | else | 
|---|
| 368 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 369 |  | 
|---|
| 370 | return rc; | 
|---|
| 371 | } | 
|---|
| 372 |  | 
|---|
| 373 |  | 
|---|
| 374 | /***************************************************************************** | 
|---|
| 375 | * Name      : | 
|---|
| 376 | * Purpose   : | 
|---|
| 377 | * Parameters: | 
|---|
| 378 | * Variables : | 
|---|
| 379 | * Result    : | 
|---|
| 380 | * Remark    : | 
|---|
| 381 | * Status    : UNTESTED STUB | 
|---|
| 382 | * | 
|---|
| 383 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 384 | *****************************************************************************/ | 
|---|
| 385 |  | 
|---|
| 386 | ODINFUNCTION3(int,OS2ioctlsocket,SOCKET,  s, | 
|---|
| 387 | long,    cmd, | 
|---|
| 388 | u_long*, argp) | 
|---|
| 389 | { | 
|---|
| 390 | int rc = ioctl(s, cmd, (char *)argp, 4); | 
|---|
| 391 |  | 
|---|
| 392 | if (rc < 0) | 
|---|
| 393 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 394 | else | 
|---|
| 395 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 396 |  | 
|---|
| 397 | return rc; | 
|---|
| 398 | } | 
|---|
| 399 |  | 
|---|
| 400 |  | 
|---|
| 401 | /***************************************************************************** | 
|---|
| 402 | * Name      : | 
|---|
| 403 | * Purpose   : | 
|---|
| 404 | * Parameters: | 
|---|
| 405 | * Variables : | 
|---|
| 406 | * Result    : | 
|---|
| 407 | * Remark    : | 
|---|
| 408 | * Status    : UNTESTED STUB | 
|---|
| 409 | * | 
|---|
| 410 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 411 | *****************************************************************************/ | 
|---|
| 412 |  | 
|---|
| 413 | ODINFUNCTION3(int,OS2getpeername,SOCKET,   s, | 
|---|
| 414 | PSOCKADDR,name, | 
|---|
| 415 | int*,     namelen) | 
|---|
| 416 | { | 
|---|
| 417 | SOCKET rc = getpeername(s,name,namelen); | 
|---|
| 418 |  | 
|---|
| 419 | if (rc == SOCKET_ERROR) | 
|---|
| 420 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 421 | else | 
|---|
| 422 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 423 |  | 
|---|
| 424 | return rc; | 
|---|
| 425 | } | 
|---|
| 426 |  | 
|---|
| 427 |  | 
|---|
| 428 | /***************************************************************************** | 
|---|
| 429 | * Name      : | 
|---|
| 430 | * Purpose   : | 
|---|
| 431 | * Parameters: | 
|---|
| 432 | * Variables : | 
|---|
| 433 | * Result    : | 
|---|
| 434 | * Remark    : | 
|---|
| 435 | * Status    : UNTESTED STUB | 
|---|
| 436 | * | 
|---|
| 437 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 438 | *****************************************************************************/ | 
|---|
| 439 |  | 
|---|
| 440 | ODINFUNCTION3(int,OS2getsockname,SOCKET,   s, | 
|---|
| 441 | PSOCKADDR,name, | 
|---|
| 442 | int*,     namelen) | 
|---|
| 443 | { | 
|---|
| 444 | SOCKET rc = getsockname(s,name,namelen); | 
|---|
| 445 |  | 
|---|
| 446 | if (rc == SOCKET_ERROR) | 
|---|
| 447 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 448 | else | 
|---|
| 449 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 450 |  | 
|---|
| 451 | return rc; | 
|---|
| 452 | } | 
|---|
| 453 |  | 
|---|
| 454 |  | 
|---|
| 455 | /***************************************************************************** | 
|---|
| 456 | * Name      : | 
|---|
| 457 | * Purpose   : | 
|---|
| 458 | * Parameters: | 
|---|
| 459 | * Variables : | 
|---|
| 460 | * Result    : | 
|---|
| 461 | * Remark    : | 
|---|
| 462 | * Status    : UNTESTED STUB | 
|---|
| 463 | * | 
|---|
| 464 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 465 | *****************************************************************************/ | 
|---|
| 466 |  | 
|---|
| 467 | ODINFUNCTION5(int,OS2getsockopt,SOCKET,s, | 
|---|
| 468 | int,   level, | 
|---|
| 469 | int,   optname, | 
|---|
| 470 | char*, optval, | 
|---|
| 471 | int*,  optlen) | 
|---|
| 472 | { | 
|---|
| 473 | int rc = getsockopt(s,level,optname,optval,optlen); | 
|---|
| 474 |  | 
|---|
| 475 | if (rc == SOCKET_ERROR) | 
|---|
| 476 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 477 | else | 
|---|
| 478 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 479 |  | 
|---|
| 480 | return rc; | 
|---|
| 481 | } | 
|---|
| 482 |  | 
|---|
| 483 |  | 
|---|
| 484 | /***************************************************************************** | 
|---|
| 485 | * Name      : | 
|---|
| 486 | * Purpose   : | 
|---|
| 487 | * Parameters: | 
|---|
| 488 | * Variables : | 
|---|
| 489 | * Result    : | 
|---|
| 490 | * Remark    : | 
|---|
| 491 | * Status    : UNTESTED STUB | 
|---|
| 492 | * | 
|---|
| 493 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 494 | *****************************************************************************/ | 
|---|
| 495 |  | 
|---|
| 496 | ODINFUNCTION1(u_long,OS2htonl,u_long,hostlong) | 
|---|
| 497 | { | 
|---|
| 498 | return htonl(hostlong); | 
|---|
| 499 | } | 
|---|
| 500 |  | 
|---|
| 501 |  | 
|---|
| 502 | /***************************************************************************** | 
|---|
| 503 | * Name      : | 
|---|
| 504 | * Purpose   : | 
|---|
| 505 | * Parameters: | 
|---|
| 506 | * Variables : | 
|---|
| 507 | * Result    : | 
|---|
| 508 | * Remark    : | 
|---|
| 509 | * Status    : UNTESTED STUB | 
|---|
| 510 | * | 
|---|
| 511 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 512 | *****************************************************************************/ | 
|---|
| 513 |  | 
|---|
| 514 | ODINFUNCTION1(u_short,OS2htons,u_short,hostshort) | 
|---|
| 515 | { | 
|---|
| 516 | return htons(hostshort); | 
|---|
| 517 | } | 
|---|
| 518 |  | 
|---|
| 519 |  | 
|---|
| 520 | /***************************************************************************** | 
|---|
| 521 | * Name      : | 
|---|
| 522 | * Purpose   : | 
|---|
| 523 | * Parameters: | 
|---|
| 524 | * Variables : | 
|---|
| 525 | * Result    : | 
|---|
| 526 | * Remark    : | 
|---|
| 527 | * Status    : UNTESTED STUB | 
|---|
| 528 | * | 
|---|
| 529 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 530 | *****************************************************************************/ | 
|---|
| 531 |  | 
|---|
| 532 | ODINFUNCTION1(u_long,OS2inet_addr,const char*, cp) | 
|---|
| 533 | { | 
|---|
| 534 | return inet_addr((char *)cp); | 
|---|
| 535 | } | 
|---|
| 536 |  | 
|---|
| 537 |  | 
|---|
| 538 | /***************************************************************************** | 
|---|
| 539 | * Name      : | 
|---|
| 540 | * Purpose   : | 
|---|
| 541 | * Parameters: | 
|---|
| 542 | * Variables : | 
|---|
| 543 | * Result    : | 
|---|
| 544 | * Remark    : | 
|---|
| 545 | * Status    : UNTESTED STUB | 
|---|
| 546 | * | 
|---|
| 547 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 548 | *****************************************************************************/ | 
|---|
| 549 |  | 
|---|
| 550 | ODINFUNCTION1(char*,OS2inet_ntoa,struct in_addr,in) | 
|---|
| 551 | { | 
|---|
| 552 | return inet_ntoa(in); | 
|---|
| 553 | } | 
|---|
| 554 |  | 
|---|
| 555 |  | 
|---|
| 556 | /***************************************************************************** | 
|---|
| 557 | * Name      : | 
|---|
| 558 | * Purpose   : | 
|---|
| 559 | * Parameters: | 
|---|
| 560 | * Variables : | 
|---|
| 561 | * Result    : | 
|---|
| 562 | * Remark    : | 
|---|
| 563 | * Status    : UNTESTED STUB | 
|---|
| 564 | * | 
|---|
| 565 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 566 | *****************************************************************************/ | 
|---|
| 567 |  | 
|---|
| 568 | ODINFUNCTION2(int,OS2listen,SOCKET,s, | 
|---|
| 569 | int,   backlog) | 
|---|
| 570 | { | 
|---|
| 571 | int rc = listen(s,backlog); | 
|---|
| 572 |  | 
|---|
| 573 | if (rc < 0) | 
|---|
| 574 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 575 | else | 
|---|
| 576 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 577 |  | 
|---|
| 578 | return rc; | 
|---|
| 579 | } | 
|---|
| 580 |  | 
|---|
| 581 |  | 
|---|
| 582 | /***************************************************************************** | 
|---|
| 583 | * Name      : | 
|---|
| 584 | * Purpose   : | 
|---|
| 585 | * Parameters: | 
|---|
| 586 | * Variables : | 
|---|
| 587 | * Result    : | 
|---|
| 588 | * Remark    : | 
|---|
| 589 | * Status    : UNTESTED STUB | 
|---|
| 590 | * | 
|---|
| 591 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 592 | *****************************************************************************/ | 
|---|
| 593 |  | 
|---|
| 594 | ODINFUNCTION1(u_long,OS2ntohl,u_long,netlong) | 
|---|
| 595 | { | 
|---|
| 596 | return ntohl(netlong); | 
|---|
| 597 | } | 
|---|
| 598 |  | 
|---|
| 599 |  | 
|---|
| 600 | /***************************************************************************** | 
|---|
| 601 | * Name      : | 
|---|
| 602 | * Purpose   : | 
|---|
| 603 | * Parameters: | 
|---|
| 604 | * Variables : | 
|---|
| 605 | * Result    : | 
|---|
| 606 | * Remark    : | 
|---|
| 607 | * Status    : UNTESTED STUB | 
|---|
| 608 | * | 
|---|
| 609 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 610 | *****************************************************************************/ | 
|---|
| 611 |  | 
|---|
| 612 | ODINFUNCTION1(u_short,OS2ntohs,u_short,netshort) | 
|---|
| 613 | { | 
|---|
| 614 | return ntohs(netshort); | 
|---|
| 615 | } | 
|---|
| 616 |  | 
|---|
| 617 |  | 
|---|
| 618 | /***************************************************************************** | 
|---|
| 619 | * Name      : | 
|---|
| 620 | * Purpose   : | 
|---|
| 621 | * Parameters: | 
|---|
| 622 | * Variables : | 
|---|
| 623 | * Result    : | 
|---|
| 624 | * Remark    : | 
|---|
| 625 | * Status    : UNTESTED STUB | 
|---|
| 626 | * | 
|---|
| 627 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 628 | *****************************************************************************/ | 
|---|
| 629 |  | 
|---|
| 630 | ODINFUNCTION4(int,OS2recv,SOCKET,s, | 
|---|
| 631 | char*, buf, | 
|---|
| 632 | int,   len, | 
|---|
| 633 | int,   flags) | 
|---|
| 634 | { | 
|---|
| 635 | int rc = recv(s,buf,len,flags); | 
|---|
| 636 |  | 
|---|
| 637 | if (rc < 0) | 
|---|
| 638 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 639 | else | 
|---|
| 640 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 641 |  | 
|---|
| 642 | return rc; | 
|---|
| 643 | } | 
|---|
| 644 |  | 
|---|
| 645 |  | 
|---|
| 646 | /***************************************************************************** | 
|---|
| 647 | * Name      : | 
|---|
| 648 | * Purpose   : | 
|---|
| 649 | * Parameters: | 
|---|
| 650 | * Variables : | 
|---|
| 651 | * Result    : | 
|---|
| 652 | * Remark    : | 
|---|
| 653 | * Status    : UNTESTED STUB | 
|---|
| 654 | * | 
|---|
| 655 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 656 | *****************************************************************************/ | 
|---|
| 657 |  | 
|---|
| 658 | ODINFUNCTION6(int,OS2recvfrom,SOCKET,    s, | 
|---|
| 659 | char*,     buf, | 
|---|
| 660 | int,       len, | 
|---|
| 661 | int,       flags, | 
|---|
| 662 | PSOCKADDR, from, | 
|---|
| 663 | int*,      fromlen) | 
|---|
| 664 | { | 
|---|
| 665 | int rc = recvfrom(s,buf,len,flags,from,fromlen); | 
|---|
| 666 |  | 
|---|
| 667 | if (rc < 0) | 
|---|
| 668 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 669 | else | 
|---|
| 670 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 671 |  | 
|---|
| 672 | return rc; | 
|---|
| 673 | } | 
|---|
| 674 |  | 
|---|
| 675 |  | 
|---|
| 676 | /***************************************************************************** | 
|---|
| 677 | * Name      : | 
|---|
| 678 | * Purpose   : | 
|---|
| 679 | * Parameters: | 
|---|
| 680 | * Variables : | 
|---|
| 681 | * Result    : | 
|---|
| 682 | * Remark    : | 
|---|
| 683 | * Status    : UNTESTED STUB | 
|---|
| 684 | * | 
|---|
| 685 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 686 | *****************************************************************************/ | 
|---|
| 687 |  | 
|---|
| 688 | #ifdef VV_BSD_SELECT | 
|---|
| 689 |  | 
|---|
| 690 | ODINFUNCTION5(int,OS2select,int,      nfds, | 
|---|
| 691 | Wfd_set*, readfds, | 
|---|
| 692 | Wfd_set*, writefds, | 
|---|
| 693 | Wfd_set*, exceptfds, | 
|---|
| 694 | const struct Wtimeval*, timeout) | 
|---|
| 695 | { | 
|---|
| 696 | int rc = select(nfds, | 
|---|
| 697 | (fd_set *)readfds, | 
|---|
| 698 | (fd_set *)writefds, | 
|---|
| 699 | (fd_set *)exceptfds, | 
|---|
| 700 | (timeval *)timeout); | 
|---|
| 701 |  | 
|---|
| 702 | if (rc == SOCKET_ERROR) | 
|---|
| 703 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 704 | else | 
|---|
| 705 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 706 |  | 
|---|
| 707 | return rc; | 
|---|
| 708 | } | 
|---|
| 709 |  | 
|---|
| 710 | #else | 
|---|
| 711 | #  error OS/2-style select not implemented! | 
|---|
| 712 | #endif | 
|---|
| 713 |  | 
|---|
| 714 |  | 
|---|
| 715 | /***************************************************************************** | 
|---|
| 716 | * Name      : | 
|---|
| 717 | * Purpose   : | 
|---|
| 718 | * Parameters: | 
|---|
| 719 | * Variables : | 
|---|
| 720 | * Result    : | 
|---|
| 721 | * Remark    : | 
|---|
| 722 | * Status    : UNTESTED STUB | 
|---|
| 723 | * | 
|---|
| 724 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 725 | *****************************************************************************/ | 
|---|
| 726 |  | 
|---|
| 727 | ODINFUNCTION4(int,OS2send,SOCKET,      s, | 
|---|
| 728 | const char*, buf, | 
|---|
| 729 | int,         len, | 
|---|
| 730 | int,         flags) | 
|---|
| 731 | { | 
|---|
| 732 | int rc = send(s,(char *)buf,len,flags); | 
|---|
| 733 |  | 
|---|
| 734 | if (rc < 0) | 
|---|
| 735 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 736 | else | 
|---|
| 737 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 738 |  | 
|---|
| 739 | return rc; | 
|---|
| 740 | } | 
|---|
| 741 |  | 
|---|
| 742 |  | 
|---|
| 743 | /***************************************************************************** | 
|---|
| 744 | * Name      : | 
|---|
| 745 | * Purpose   : | 
|---|
| 746 | * Parameters: | 
|---|
| 747 | * Variables : | 
|---|
| 748 | * Result    : | 
|---|
| 749 | * Remark    : | 
|---|
| 750 | * Status    : UNTESTED STUB | 
|---|
| 751 | * | 
|---|
| 752 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 753 | *****************************************************************************/ | 
|---|
| 754 |  | 
|---|
| 755 | ODINFUNCTION6(int,OS2sendto,SOCKET,          s, | 
|---|
| 756 | const char*,     buf, | 
|---|
| 757 | int,             len, | 
|---|
| 758 | int,             flags, | 
|---|
| 759 | const struct sockaddr*, to, | 
|---|
| 760 | int,             tolen) | 
|---|
| 761 | { | 
|---|
| 762 | int rc = sendto(s,(char *)buf,len,flags,(PSOCKADDR)to,tolen); | 
|---|
| 763 |  | 
|---|
| 764 | if (rc < 0) | 
|---|
| 765 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 766 | else | 
|---|
| 767 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 768 |  | 
|---|
| 769 | return rc; | 
|---|
| 770 | } | 
|---|
| 771 |  | 
|---|
| 772 |  | 
|---|
| 773 | /***************************************************************************** | 
|---|
| 774 | * Name      : | 
|---|
| 775 | * Purpose   : | 
|---|
| 776 | * Parameters: | 
|---|
| 777 | * Variables : | 
|---|
| 778 | * Result    : | 
|---|
| 779 | * Remark    : | 
|---|
| 780 | * Status    : UNTESTED STUB | 
|---|
| 781 | * | 
|---|
| 782 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 783 | *****************************************************************************/ | 
|---|
| 784 |  | 
|---|
| 785 | ODINFUNCTION5(int,OS2setsockopt,SOCKET,      s, | 
|---|
| 786 | int,         level, | 
|---|
| 787 | int,         optname, | 
|---|
| 788 | const char*, optval, | 
|---|
| 789 | int,         optlen) | 
|---|
| 790 | { | 
|---|
| 791 | struct Wlinger *yy; | 
|---|
| 792 | struct linger xx; | 
|---|
| 793 | int    rc; | 
|---|
| 794 |  | 
|---|
| 795 | if(level   == SOL_SOCKET && | 
|---|
| 796 | optname == SO_LINGER) | 
|---|
| 797 | { | 
|---|
| 798 | yy = (struct Wlinger *)optval; | 
|---|
| 799 | xx.l_onoff = (int)yy->l_onoff; | 
|---|
| 800 | xx.l_linger = (int)yy->l_linger; | 
|---|
| 801 |  | 
|---|
| 802 | rc = setsockopt(s,level,optname,(char *)&xx,optlen); | 
|---|
| 803 | } | 
|---|
| 804 | else | 
|---|
| 805 | rc = setsockopt(s,level,optname,(char *)optval,optlen); | 
|---|
| 806 |  | 
|---|
| 807 | if (rc == SOCKET_ERROR) | 
|---|
| 808 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 809 | else | 
|---|
| 810 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 811 |  | 
|---|
| 812 | return rc; | 
|---|
| 813 | } | 
|---|
| 814 |  | 
|---|
| 815 |  | 
|---|
| 816 | /***************************************************************************** | 
|---|
| 817 | * Name      : | 
|---|
| 818 | * Purpose   : | 
|---|
| 819 | * Parameters: | 
|---|
| 820 | * Variables : | 
|---|
| 821 | * Result    : | 
|---|
| 822 | * Remark    : | 
|---|
| 823 | * Status    : UNTESTED STUB | 
|---|
| 824 | * | 
|---|
| 825 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 826 | *****************************************************************************/ | 
|---|
| 827 |  | 
|---|
| 828 | ODINFUNCTION2(int,OS2shutdown,SOCKET,s, | 
|---|
| 829 | int,   how) | 
|---|
| 830 | { | 
|---|
| 831 | int rc = shutdown(s,how); | 
|---|
| 832 |  | 
|---|
| 833 | if (rc == SOCKET_ERROR) | 
|---|
| 834 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 835 | else | 
|---|
| 836 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 837 |  | 
|---|
| 838 | return rc; | 
|---|
| 839 | } | 
|---|
| 840 |  | 
|---|
| 841 |  | 
|---|
| 842 | /***************************************************************************** | 
|---|
| 843 | * Name      : | 
|---|
| 844 | * Purpose   : | 
|---|
| 845 | * Parameters: | 
|---|
| 846 | * Variables : | 
|---|
| 847 | * Result    : | 
|---|
| 848 | * Remark    : | 
|---|
| 849 | * Status    : UNTESTED STUB | 
|---|
| 850 | * | 
|---|
| 851 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 852 | *****************************************************************************/ | 
|---|
| 853 |  | 
|---|
| 854 | ODINFUNCTION3(SOCKET,OS2socket,int,af, | 
|---|
| 855 | int,type, | 
|---|
| 856 | int,protocol) | 
|---|
| 857 | { | 
|---|
| 858 | SOCKET rc = socket(af,type,protocol); | 
|---|
| 859 |  | 
|---|
| 860 | if (rc == INVALID_SOCKET) | 
|---|
| 861 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 862 | else | 
|---|
| 863 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 864 |  | 
|---|
| 865 | return rc; | 
|---|
| 866 | } | 
|---|
| 867 |  | 
|---|
| 868 |  | 
|---|
| 869 | /***************************************************************************** | 
|---|
| 870 | * Name      : | 
|---|
| 871 | * Purpose   : | 
|---|
| 872 | * Parameters: | 
|---|
| 873 | * Variables : | 
|---|
| 874 | * Result    : | 
|---|
| 875 | * Remark    : | 
|---|
| 876 | * Status    : UNTESTED STUB | 
|---|
| 877 | * | 
|---|
| 878 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 879 | *****************************************************************************/ | 
|---|
| 880 |  | 
|---|
| 881 | ODINFUNCTION3(WHOSTENT*,OS2gethostbyaddr,const char*, addr, | 
|---|
| 882 | int,         len, | 
|---|
| 883 | int,         type) | 
|---|
| 884 | { | 
|---|
| 885 | WHOSTENT         *yy; | 
|---|
| 886 | struct hostent   *xx; | 
|---|
| 887 | PWSOCKTHREADDATA pwstd; | 
|---|
| 888 |  | 
|---|
| 889 | xx = gethostbyaddr((char *)addr,len,type); | 
|---|
| 890 |  | 
|---|
| 891 | if(xx == NULL) | 
|---|
| 892 | { | 
|---|
| 893 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 894 | return (WHOSTENT *)NULL; | 
|---|
| 895 | } | 
|---|
| 896 | else | 
|---|
| 897 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 898 |  | 
|---|
| 899 | // access current thread wsock data block | 
|---|
| 900 | pwstd = iQueryWsockThreadData(); | 
|---|
| 901 |  | 
|---|
| 902 | pwstd->whsnt.h_name      = xx->h_name; | 
|---|
| 903 | pwstd->whsnt.h_aliases   = xx->h_aliases; | 
|---|
| 904 | pwstd->whsnt.h_addrtype  = (short)xx->h_addrtype; | 
|---|
| 905 | pwstd->whsnt.h_length    = (short)xx->h_length; | 
|---|
| 906 | pwstd->whsnt.h_addr_list = xx->h_addr_list; | 
|---|
| 907 |  | 
|---|
| 908 | return &pwstd->whsnt; | 
|---|
| 909 | } | 
|---|
| 910 |  | 
|---|
| 911 |  | 
|---|
| 912 | /***************************************************************************** | 
|---|
| 913 | * Name      : | 
|---|
| 914 | * Purpose   : | 
|---|
| 915 | * Parameters: | 
|---|
| 916 | * Variables : | 
|---|
| 917 | * Result    : | 
|---|
| 918 | * Remark    : | 
|---|
| 919 | * Status    : UNTESTED STUB | 
|---|
| 920 | * | 
|---|
| 921 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 922 | *****************************************************************************/ | 
|---|
| 923 |  | 
|---|
| 924 | ODINFUNCTION1(WHOSTENT*,OS2gethostbyname,const char*,name) | 
|---|
| 925 | { | 
|---|
| 926 | WHOSTENT         *yy; | 
|---|
| 927 | struct hostent   *xx; | 
|---|
| 928 | PWSOCKTHREADDATA pwstd; | 
|---|
| 929 |  | 
|---|
| 930 |  | 
|---|
| 931 | xx = gethostbyname((char *)name); | 
|---|
| 932 | if(xx == NULL) | 
|---|
| 933 | { | 
|---|
| 934 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 935 | return (WHOSTENT *)NULL; | 
|---|
| 936 | } | 
|---|
| 937 | else | 
|---|
| 938 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 939 |  | 
|---|
| 940 | // access current thread wsock data block | 
|---|
| 941 | pwstd = iQueryWsockThreadData(); | 
|---|
| 942 |  | 
|---|
| 943 | pwstd->whsnt.h_name      = xx->h_name; | 
|---|
| 944 | pwstd->whsnt.h_aliases   = xx->h_aliases; | 
|---|
| 945 | pwstd->whsnt.h_addrtype  = (short)xx->h_addrtype; | 
|---|
| 946 | pwstd->whsnt.h_length    = (short)xx->h_length; | 
|---|
| 947 | pwstd->whsnt.h_addr_list = xx->h_addr_list; | 
|---|
| 948 |  | 
|---|
| 949 | return &pwstd->whsnt; | 
|---|
| 950 | } | 
|---|
| 951 |  | 
|---|
| 952 |  | 
|---|
| 953 | /***************************************************************************** | 
|---|
| 954 | * Name      : | 
|---|
| 955 | * Purpose   : | 
|---|
| 956 | * Parameters: | 
|---|
| 957 | * Variables : | 
|---|
| 958 | * Result    : | 
|---|
| 959 | * Remark    : | 
|---|
| 960 | * Status    : UNTESTED STUB | 
|---|
| 961 | * | 
|---|
| 962 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 963 | *****************************************************************************/ | 
|---|
| 964 |  | 
|---|
| 965 | ODINFUNCTION2(int,OS2gethostname,char *,name, | 
|---|
| 966 | int,   namelen) | 
|---|
| 967 | { | 
|---|
| 968 | int rc = gethostname(name,namelen); | 
|---|
| 969 |  | 
|---|
| 970 | if (rc == SOCKET_ERROR) | 
|---|
| 971 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 972 | else | 
|---|
| 973 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 974 |  | 
|---|
| 975 | return (rc); | 
|---|
| 976 | } | 
|---|
| 977 |  | 
|---|
| 978 |  | 
|---|
| 979 | /***************************************************************************** | 
|---|
| 980 | * Name      : | 
|---|
| 981 | * Purpose   : | 
|---|
| 982 | * Parameters: | 
|---|
| 983 | * Variables : | 
|---|
| 984 | * Result    : | 
|---|
| 985 | * Remark    : | 
|---|
| 986 | * Status    : UNTESTED STUB | 
|---|
| 987 | * | 
|---|
| 988 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 989 | *****************************************************************************/ | 
|---|
| 990 |  | 
|---|
| 991 | ODINFUNCTION2(WSERVENT*,OS2getservbyport, int,         port, | 
|---|
| 992 | const char*, proto) | 
|---|
| 993 | { | 
|---|
| 994 | struct servent   *xx; | 
|---|
| 995 | PWSOCKTHREADDATA pwstd; | 
|---|
| 996 |  | 
|---|
| 997 | xx = getservbyport(port,(char *)proto); | 
|---|
| 998 |  | 
|---|
| 999 | if(xx == NULL) | 
|---|
| 1000 | { // this call doesn't generate an error message | 
|---|
| 1001 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 1002 | return (WSERVENT *)NULL; | 
|---|
| 1003 | } | 
|---|
| 1004 | else | 
|---|
| 1005 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 1006 |  | 
|---|
| 1007 | // access current thread wsock data block | 
|---|
| 1008 | pwstd = iQueryWsockThreadData(); | 
|---|
| 1009 |  | 
|---|
| 1010 | pwstd->wsvnt.s_name    = xx->s_name; | 
|---|
| 1011 | pwstd->wsvnt.s_aliases = xx->s_aliases; | 
|---|
| 1012 | pwstd->wsvnt.s_port    = (short)xx->s_port; | 
|---|
| 1013 | pwstd->wsvnt.s_proto   = xx->s_proto; | 
|---|
| 1014 |  | 
|---|
| 1015 | return &pwstd->wsvnt; | 
|---|
| 1016 | } | 
|---|
| 1017 |  | 
|---|
| 1018 |  | 
|---|
| 1019 | /***************************************************************************** | 
|---|
| 1020 | * Name      : | 
|---|
| 1021 | * Purpose   : | 
|---|
| 1022 | * Parameters: | 
|---|
| 1023 | * Variables : | 
|---|
| 1024 | * Result    : | 
|---|
| 1025 | * Remark    : | 
|---|
| 1026 | * Status    : UNTESTED STUB | 
|---|
| 1027 | * | 
|---|
| 1028 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 1029 | *****************************************************************************/ | 
|---|
| 1030 |  | 
|---|
| 1031 | ODINFUNCTION2(WSERVENT*,OS2getservbyname,const char*,name, | 
|---|
| 1032 | const char*,proto) | 
|---|
| 1033 | { | 
|---|
| 1034 | WSERVENT         *yy; | 
|---|
| 1035 | struct servent   *xx; | 
|---|
| 1036 | PWSOCKTHREADDATA pwstd; | 
|---|
| 1037 |  | 
|---|
| 1038 |  | 
|---|
| 1039 | xx = getservbyname((char *)name,(char *)proto); | 
|---|
| 1040 |  | 
|---|
| 1041 | if(xx == NULL) | 
|---|
| 1042 | { // this call doesn't generate an error message | 
|---|
| 1043 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 1044 | return (WSERVENT *)NULL; | 
|---|
| 1045 | } | 
|---|
| 1046 | else | 
|---|
| 1047 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 1048 |  | 
|---|
| 1049 | // access current thread wsock data block | 
|---|
| 1050 | pwstd = iQueryWsockThreadData(); | 
|---|
| 1051 |  | 
|---|
| 1052 | pwstd->wsvnt.s_name    = xx->s_name; | 
|---|
| 1053 | pwstd->wsvnt.s_aliases = xx->s_aliases; | 
|---|
| 1054 | pwstd->wsvnt.s_port    = (short)xx->s_port; | 
|---|
| 1055 | pwstd->wsvnt.s_proto   = xx->s_proto; | 
|---|
| 1056 |  | 
|---|
| 1057 | return &pwstd->wsvnt; | 
|---|
| 1058 | } | 
|---|
| 1059 |  | 
|---|
| 1060 |  | 
|---|
| 1061 | /***************************************************************************** | 
|---|
| 1062 | * Name      : | 
|---|
| 1063 | * Purpose   : | 
|---|
| 1064 | * Parameters: | 
|---|
| 1065 | * Variables : | 
|---|
| 1066 | * Result    : | 
|---|
| 1067 | * Remark    : | 
|---|
| 1068 | * Status    : UNTESTED STUB | 
|---|
| 1069 | * | 
|---|
| 1070 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 1071 | *****************************************************************************/ | 
|---|
| 1072 |  | 
|---|
| 1073 | ODINFUNCTION1(WPROTOENT*,OS2getprotobynumber,int,proto) | 
|---|
| 1074 | { | 
|---|
| 1075 | struct protoent  *xx; | 
|---|
| 1076 | PWSOCKTHREADDATA pwstd; | 
|---|
| 1077 |  | 
|---|
| 1078 | xx = getprotobynumber(proto); | 
|---|
| 1079 |  | 
|---|
| 1080 | if(xx == NULL) | 
|---|
| 1081 | { | 
|---|
| 1082 | // this call doesn't generate an error message | 
|---|
| 1083 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 1084 | return (WPROTOENT *)NULL; | 
|---|
| 1085 | } | 
|---|
| 1086 | else | 
|---|
| 1087 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 1088 |  | 
|---|
| 1089 | // access current thread wsock data block | 
|---|
| 1090 | pwstd = iQueryWsockThreadData(); | 
|---|
| 1091 |  | 
|---|
| 1092 | pwstd->wptnt.p_name    = xx->p_name; | 
|---|
| 1093 | pwstd->wptnt.p_aliases = xx->p_aliases; | 
|---|
| 1094 | pwstd->wptnt.p_proto   = (short)xx->p_proto; | 
|---|
| 1095 |  | 
|---|
| 1096 | return &pwstd->wptnt; | 
|---|
| 1097 | } | 
|---|
| 1098 |  | 
|---|
| 1099 |  | 
|---|
| 1100 | /***************************************************************************** | 
|---|
| 1101 | * Name      : | 
|---|
| 1102 | * Purpose   : | 
|---|
| 1103 | * Parameters: | 
|---|
| 1104 | * Variables : | 
|---|
| 1105 | * Result    : | 
|---|
| 1106 | * Remark    : | 
|---|
| 1107 | * Status    : UNTESTED STUB | 
|---|
| 1108 | * | 
|---|
| 1109 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 1110 | *****************************************************************************/ | 
|---|
| 1111 |  | 
|---|
| 1112 | ODINFUNCTION1(WPROTOENT*,OS2getprotobyname,const char*,name) | 
|---|
| 1113 | { | 
|---|
| 1114 | struct protoent  *xx; | 
|---|
| 1115 | PWSOCKTHREADDATA pwstd; | 
|---|
| 1116 |  | 
|---|
| 1117 | xx = getprotobyname((char *)name); | 
|---|
| 1118 |  | 
|---|
| 1119 | if(xx == NULL) | 
|---|
| 1120 | { // this call doesn't generate an error message | 
|---|
| 1121 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 1122 | return (WPROTOENT *)NULL; | 
|---|
| 1123 | } | 
|---|
| 1124 | else | 
|---|
| 1125 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 1126 |  | 
|---|
| 1127 | // access current thread wsock data block | 
|---|
| 1128 | pwstd = iQueryWsockThreadData(); | 
|---|
| 1129 |  | 
|---|
| 1130 | pwstd->wptnt.p_name    = xx->p_name; | 
|---|
| 1131 | pwstd->wptnt.p_aliases = xx->p_aliases; | 
|---|
| 1132 | pwstd->wptnt.p_proto   = (short)xx->p_proto; | 
|---|
| 1133 |  | 
|---|
| 1134 | return &pwstd->wptnt; | 
|---|
| 1135 | } | 
|---|
| 1136 |  | 
|---|
| 1137 |  | 
|---|
| 1138 | /***************************************************************************** | 
|---|
| 1139 | * Name      : | 
|---|
| 1140 | * Purpose   : | 
|---|
| 1141 | * Parameters: | 
|---|
| 1142 | * Variables : | 
|---|
| 1143 | * Result    : | 
|---|
| 1144 | * Remark    : | 
|---|
| 1145 | * Status    : UNTESTED STUB | 
|---|
| 1146 | * | 
|---|
| 1147 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 1148 | *****************************************************************************/ | 
|---|
| 1149 |  | 
|---|
| 1150 | ODINFUNCTION2(int,OS2WSAStartup,USHORT,   wVersionRequired, | 
|---|
| 1151 | LPWSADATA,lpWsaData) | 
|---|
| 1152 | { | 
|---|
| 1153 | APIRET rc; | 
|---|
| 1154 |  | 
|---|
| 1155 | /* Make sure that the version requested is >= 1.1.   */ | 
|---|
| 1156 | /* The low byte is the major version and the high    */ | 
|---|
| 1157 | /* byte is the minor version.                        */ | 
|---|
| 1158 |  | 
|---|
| 1159 | if ( LOBYTE( wVersionRequired ) < 1 || | 
|---|
| 1160 | ( LOBYTE( wVersionRequired ) == 1 && | 
|---|
| 1161 | HIBYTE( wVersionRequired ) < 1 )) { | 
|---|
| 1162 | return WSAVERNOTSUPPORTED; | 
|---|
| 1163 | } | 
|---|
| 1164 |  | 
|---|
| 1165 | /* Since we only support 1.1, set both wVersion and  */ | 
|---|
| 1166 | /* wHighVersion to 1.1.                              */ | 
|---|
| 1167 |  | 
|---|
| 1168 | lpWsaData->wVersion = MAKEWORD( 1, 1 ); | 
|---|
| 1169 | lpWsaData->wHighVersion = MAKEWORD( 1, 1 ); | 
|---|
| 1170 | strcpy(lpWsaData->szDescription,"Win32OS2 WSOCK32.DLL Ver. 1.1"); | 
|---|
| 1171 | lpWsaData->iMaxUdpDg = 32767; | 
|---|
| 1172 | lpWsaData->iMaxSockets = 2048; | 
|---|
| 1173 | strcpy(lpWsaData->szSystemStatus,"No Status"); | 
|---|
| 1174 |  | 
|---|
| 1175 | if(sock_init() == 0) | 
|---|
| 1176 | { | 
|---|
| 1177 | #ifdef DEBUG | 
|---|
| 1178 | WriteLog("WSOCK32: WSAStartup sock_init returned 0\n"); | 
|---|
| 1179 | #endif | 
|---|
| 1180 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 1181 | return 0; | 
|---|
| 1182 | } | 
|---|
| 1183 | else | 
|---|
| 1184 | { | 
|---|
| 1185 | WSASetLastError(iTranslateSockErrToWSock(sock_errno())); | 
|---|
| 1186 | return(WSASYSNOTREADY); | 
|---|
| 1187 | } | 
|---|
| 1188 | } | 
|---|
| 1189 |  | 
|---|
| 1190 |  | 
|---|
| 1191 | /***************************************************************************** | 
|---|
| 1192 | * Name      : | 
|---|
| 1193 | * Purpose   : | 
|---|
| 1194 | * Parameters: | 
|---|
| 1195 | * Variables : | 
|---|
| 1196 | * Result    : | 
|---|
| 1197 | * Remark    : | 
|---|
| 1198 | * Status    : UNTESTED STUB | 
|---|
| 1199 | * | 
|---|
| 1200 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 1201 | *****************************************************************************/ | 
|---|
| 1202 |  | 
|---|
| 1203 | ODINFUNCTION0(int,OS2WSACleanup) | 
|---|
| 1204 | { | 
|---|
| 1205 | WSASetLastError(ERROR_SUCCESS); | 
|---|
| 1206 | return 0; | 
|---|
| 1207 | } | 
|---|
| 1208 |  | 
|---|
| 1209 |  | 
|---|
| 1210 | /***************************************************************************** | 
|---|
| 1211 | * Name      : | 
|---|
| 1212 | * Purpose   : | 
|---|
| 1213 | * Parameters: | 
|---|
| 1214 | * Variables : | 
|---|
| 1215 | * Result    : | 
|---|
| 1216 | * Remark    : | 
|---|
| 1217 | * Status    : UNTESTED STUB | 
|---|
| 1218 | * | 
|---|
| 1219 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 1220 | *****************************************************************************/ | 
|---|
| 1221 |  | 
|---|
| 1222 | ODINPROCEDURE1(WSASetLastError,int,iError) | 
|---|
| 1223 | { | 
|---|
| 1224 | PWSOCKTHREADDATA pwstd = iQueryWsockThreadData(); | 
|---|
| 1225 | pwstd->dwLastError = iError; | 
|---|
| 1226 | } | 
|---|
| 1227 |  | 
|---|
| 1228 |  | 
|---|
| 1229 | /***************************************************************************** | 
|---|
| 1230 | * Name      : | 
|---|
| 1231 | * Purpose   : | 
|---|
| 1232 | * Parameters: | 
|---|
| 1233 | * Variables : | 
|---|
| 1234 | * Result    : | 
|---|
| 1235 | * Remark    : | 
|---|
| 1236 | * Status    : UNTESTED STUB | 
|---|
| 1237 | * | 
|---|
| 1238 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 1239 | *****************************************************************************/ | 
|---|
| 1240 |  | 
|---|
| 1241 | ODINFUNCTION0(int,WSAGetLastError) | 
|---|
| 1242 | { | 
|---|
| 1243 | PWSOCKTHREADDATA pwstd = iQueryWsockThreadData(); | 
|---|
| 1244 | return(pwstd->dwLastError); | 
|---|
| 1245 | } | 
|---|
| 1246 |  | 
|---|
| 1247 |  | 
|---|
| 1248 | /***************************************************************************** | 
|---|
| 1249 | * Name      : | 
|---|
| 1250 | * Purpose   : | 
|---|
| 1251 | * Parameters: | 
|---|
| 1252 | * Variables : | 
|---|
| 1253 | * Result    : | 
|---|
| 1254 | * Remark    : | 
|---|
| 1255 | * Status    : UNTESTED STUB | 
|---|
| 1256 | * | 
|---|
| 1257 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 1258 | *****************************************************************************/ | 
|---|
| 1259 |  | 
|---|
| 1260 | ODINFUNCTION0(int,OS2WSAUnhookBlockingHook) | 
|---|
| 1261 | { | 
|---|
| 1262 | dprintf(("WSOCK32: WSAUnhookBlockingHook unimplemented\n")); | 
|---|
| 1263 |  | 
|---|
| 1264 | return -5000; //WSAUnhookBlockingHook(); | 
|---|
| 1265 | } | 
|---|
| 1266 |  | 
|---|
| 1267 |  | 
|---|
| 1268 | /***************************************************************************** | 
|---|
| 1269 | * Name      : | 
|---|
| 1270 | * Purpose   : | 
|---|
| 1271 | * Parameters: | 
|---|
| 1272 | * Variables : | 
|---|
| 1273 | * Result    : | 
|---|
| 1274 | * Remark    : | 
|---|
| 1275 | * Status    : UNTESTED STUB | 
|---|
| 1276 | * | 
|---|
| 1277 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 1278 | *****************************************************************************/ | 
|---|
| 1279 |  | 
|---|
| 1280 | ODINFUNCTION1(PROC,OS2WSASetBlockingHook,PROC,lpBlockFund) | 
|---|
| 1281 | { | 
|---|
| 1282 | dprintf(("WSOCK32: WSASetBlockingHook Unimplemented\n")); | 
|---|
| 1283 | return (PROC)NULL; | 
|---|
| 1284 | } | 
|---|
| 1285 |  | 
|---|
| 1286 |  | 
|---|
| 1287 | /***************************************************************************** | 
|---|
| 1288 | * Name      : | 
|---|
| 1289 | * Purpose   : | 
|---|
| 1290 | * Parameters: | 
|---|
| 1291 | * Variables : | 
|---|
| 1292 | * Result    : | 
|---|
| 1293 | * Remark    : | 
|---|
| 1294 | * Status    : UNTESTED STUB | 
|---|
| 1295 | * | 
|---|
| 1296 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 1297 | *****************************************************************************/ | 
|---|
| 1298 |  | 
|---|
| 1299 | ODINFUNCTION0(int,OS2WSACancelBlockingCall) | 
|---|
| 1300 | { | 
|---|
| 1301 | dprintf(("WSOCK32: WSACancelBlockingCall unimplemented\n")); | 
|---|
| 1302 |  | 
|---|
| 1303 | return -5000; //WSACancelBlockingCall(); | 
|---|
| 1304 | } | 
|---|
| 1305 |  | 
|---|
| 1306 |  | 
|---|
| 1307 | /***************************************************************************** | 
|---|
| 1308 | * Name      : | 
|---|
| 1309 | * Purpose   : | 
|---|
| 1310 | * Parameters: | 
|---|
| 1311 | * Variables : | 
|---|
| 1312 | * Result    : | 
|---|
| 1313 | * Remark    : | 
|---|
| 1314 | * Status    : UNTESTED STUB | 
|---|
| 1315 | * | 
|---|
| 1316 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 1317 | *****************************************************************************/ | 
|---|
| 1318 |  | 
|---|
| 1319 | ODINFUNCTION4(int, OS2WSARecvEx, SOCKET,    s, | 
|---|
| 1320 | char FAR*, buf, | 
|---|
| 1321 | int,       len, | 
|---|
| 1322 | int FAR *,flags) | 
|---|
| 1323 | { | 
|---|
| 1324 | dprintf(("WSOCK32: WSARecvEx not implemented.\n")); | 
|---|
| 1325 |  | 
|---|
| 1326 | //    return WSARecvEx(s,buf,len,flags); | 
|---|
| 1327 | return 0; | 
|---|
| 1328 | } | 
|---|
| 1329 |  | 
|---|
| 1330 |  | 
|---|
| 1331 | /***************************************************************************** | 
|---|
| 1332 | * Name      : | 
|---|
| 1333 | * Purpose   : | 
|---|
| 1334 | * Parameters: | 
|---|
| 1335 | * Variables : | 
|---|
| 1336 | * Result    : | 
|---|
| 1337 | * Remark    : | 
|---|
| 1338 | * Status    : UNTESTED STUB | 
|---|
| 1339 | * | 
|---|
| 1340 | * Author    : Patrick Haller [Tue, 1998/06/16 23:00] | 
|---|
| 1341 | *****************************************************************************/ | 
|---|
| 1342 |  | 
|---|
| 1343 | ODINPROCEDURE2(OS2s_perror, char*, pszMessage, | 
|---|
| 1344 | void*, pUnknown) | 
|---|
| 1345 | { | 
|---|
| 1346 | perror(pszMessage); | 
|---|
| 1347 | } | 
|---|
| 1348 |  | 
|---|
| 1349 |  | 
|---|