| 1 | /* sim_sock.h: OS-dependent socket routines header file\r |
| 2 | \r |
| 3 | Copyright (c) 2001-2009, Robert M Supnik\r |
| 4 | \r |
| 5 | Permission is hereby granted, free of charge, to any person obtaining a\r |
| 6 | copy of this software and associated documentation files (the "Software"),\r |
| 7 | to deal in the Software without restriction, including without limitation\r |
| 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense,\r |
| 9 | and/or sell copies of the Software, and to permit persons to whom the\r |
| 10 | Software is furnished to do so, subject to the following conditions:\r |
| 11 | \r |
| 12 | The above copyright notice and this permission notice shall be included in\r |
| 13 | all copies or substantial portions of the Software.\r |
| 14 | \r |
| 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r |
| 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r |
| 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r |
| 18 | ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r |
| 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r |
| 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r |
| 21 | \r |
| 22 | Except as contained in this notice, the name of Robert M Supnik shall not be\r |
| 23 | used in advertising or otherwise to promote the sale, use or other dealings\r |
| 24 | in this Software without prior written authorization from Robert M Supnik.\r |
| 25 | \r |
| 26 | 04-Jun-08 RMS Addes sim_create_sock, for IBM 1130\r |
| 27 | 14-Apr-05 RMS Added WSAEINPROGRESS (from Tim Riker)\r |
| 28 | 20-Aug-04 HV Added missing definition for OS/2 (from Holger Veit)\r |
| 29 | 22-Oct-03 MP Changed WIN32 winsock include to use winsock2.h to\r |
| 30 | avoid a conflict if sim_sock.h and sim_ether.h get\r |
| 31 | included by the same module.\r |
| 32 | 20-Mar-03 RMS Added missing timerclear definition for VMS (from\r |
| 33 | Robert Alan Byer)\r |
| 34 | 15-Feb-03 RMS Added time.h for EMX (from Holger Veit)\r |
| 35 | 17-Dec-02 RMS Added sim_connect_sock\r |
| 36 | 08-Oct-02 RMS Revised for .NET compatibility\r |
| 37 | 20-Aug-02 RMS Changed calling sequence for sim_accept_conn\r |
| 38 | 30-Apr-02 RMS Changed VMS stropts include to ioctl\r |
| 39 | 06-Feb-02 RMS Added VMS support from Robert Alan Byer\r |
| 40 | 16-Sep-01 RMS Added Macintosh support from Peter Schorn\r |
| 41 | */\r |
| 42 | \r |
| 43 | #ifndef _SIM_SOCK_H_\r |
| 44 | #define _SIM_SOCK_H_ 0\r |
| 45 | \r |
| 46 | #if defined (_WIN32) /* Windows */\r |
| 47 | #undef INT_PTR /* hack, hack */\r |
| 48 | #include <winsock2.h>\r |
| 49 | \r |
| 50 | #elif !defined (__OS2__) || defined (__EMX__) /* VMS, Mac, Unix, OS/2 EMX */\r |
| 51 | #define WSAGetLastError() errno /* Windows macros */\r |
| 52 | #define SOCKET int32\r |
| 53 | #define WSAEWOULDBLOCK EWOULDBLOCK\r |
| 54 | #define WSAEINPROGRESS EINPROGRESS\r |
| 55 | #define INVALID_SOCKET -1 \r |
| 56 | #define SOCKET_ERROR -1\r |
| 57 | #include <sys/types.h> /* for fcntl, getpid */\r |
| 58 | #include <sys/socket.h> /* for sockets */\r |
| 59 | #include <fcntl.h>\r |
| 60 | #include <unistd.h>\r |
| 61 | #include <netinet/in.h> /* for sockaddr_in */\r |
| 62 | #include <netdb.h>\r |
| 63 | #include <sys/time.h> /* for EMX */\r |
| 64 | #endif\r |
| 65 | \r |
| 66 | #if defined (VMS) /* VMS unique */\r |
| 67 | #include <ioctl.h> /* for ioctl */\r |
| 68 | #if !defined (timerclear)\r |
| 69 | #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0\r |
| 70 | #endif\r |
| 71 | #endif\r |
| 72 | #if defined(__EMX__) /* OS/2 unique */\r |
| 73 | #if !defined (timerclear)\r |
| 74 | #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0\r |
| 75 | #endif\r |
| 76 | #endif\r |
| 77 | \r |
| 78 | SOCKET sim_master_sock (int32 port);\r |
| 79 | SOCKET sim_connect_sock (int32 ip, int32 port);\r |
| 80 | SOCKET sim_create_sock (void);\r |
| 81 | SOCKET sim_accept_conn (SOCKET master, uint32 *ipaddr);\r |
| 82 | int32 sim_check_conn (SOCKET sock, t_bool rd);\r |
| 83 | int32 sim_read_sock (SOCKET sock, char *buf, int32 nbytes);\r |
| 84 | int32 sim_write_sock (SOCKET sock, char *msg, int32 nbytes);\r |
| 85 | void sim_close_sock (SOCKET sock, t_bool master);\r |
| 86 | SOCKET sim_setnonblock (SOCKET sock);\r |
| 87 | \r |
| 88 | #endif\r |