root/src/simh/sim_sock.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * sim_sock.h: OS-dependent socket routines header file
   3  *
   4  * vim: filetype=c:tabstop=4:ai:expandtab
   5  * SPDX-License-Identifier: MIT
   6  * scspell-id: cffbcfb4-f62a-11ec-b6c0-80ee73e9b8e7
   7  *
   8  * ---------------------------------------------------------------------------
   9  *
  10  * Copyright (c) 2001-2008 Robert M. Supnik
  11  * Copyright (c) 2021-2024 The DPS8M Development Team
  12  *
  13  * Permission is hereby granted, free of charge, to any person obtaining a
  14  * copy of this software and associated documentation files (the "Software"),
  15  * to deal in the Software without restriction, including without limitation
  16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17  * and/or sell copies of the Software, and to permit persons to whom the
  18  * Software is furnished to do so, subject to the following conditions:
  19  *
  20  * The above copyright notice and this permission notice shall be included
  21  * in all copies or substantial portions of the Software.
  22  *
  23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  24  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  26  * IN NO EVENT SHALL ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR
  27  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  28  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  29  * OTHER DEALINGS IN THE SOFTWARE.
  30  *
  31  * Except as contained in this notice, the name of Robert M. Supnik shall
  32  * not be used in advertising or otherwise to promote the sale, use or other
  33  * dealings in this Software without prior written authorization from
  34  * Robert M. Supnik.
  35  *
  36  * ---------------------------------------------------------------------------
  37  */
  38 
  39 #if !defined(SIM_SOCK_H_)
  40 # define SIM_SOCK_H_    0
  41 
  42 # if defined (_WIN32)                                    /* Windows */
  43 #  include <winsock2.h>
  44 
  45 # elif !defined (_WIN32)                                 /* Not Windows */
  46 #  include <sys/types.h>                                  /* for fcntl, getpid */
  47 #  include <sys/socket.h>                                 /* for sockets */
  48 #  include <string.h>
  49 #  include <errno.h>
  50 #  include <fcntl.h>
  51 #  include <unistd.h>
  52 #  include <netinet/in.h>                                 /* for sockaddr_in */
  53 #  include <netinet/tcp.h>                                /* for TCP_NODELAY */
  54 #  include <arpa/inet.h>                                  /* for inet_addr and inet_ntoa */
  55 #  include <netdb.h>
  56 #  include <sys/time.h>
  57 
  58 #  define WSAGetLastError()       errno                   /* Windows macros */
  59 #  define WSASetLastError(err)    errno = err
  60 #  define closesocket             close
  61 #  define SOCKET                  int
  62 #  define WSAEWOULDBLOCK          EWOULDBLOCK
  63 #  define WSAENAMETOOLONG         ENAMETOOLONG
  64 #  define WSAEINPROGRESS          EINPROGRESS
  65 #  define WSAETIMEDOUT            ETIMEDOUT
  66 #  define WSAEISCONN              EISCONN
  67 #  define WSAECONNRESET           ECONNRESET
  68 #  define WSAECONNREFUSED         ECONNREFUSED
  69 #  define WSAECONNABORTED         ECONNABORTED
  70 #  define WSAEHOSTUNREACH         EHOSTUNREACH
  71 #  define WSAEADDRINUSE           EADDRINUSE
  72 #  if defined(EAFNOSUPPORT)
  73 #   define WSAEAFNOSUPPORT        EAFNOSUPPORT
  74 #  endif
  75 #  define WSAEACCES               EACCES
  76 #  define WSAEINTR                EINTR
  77 #  define INVALID_SOCKET          ((SOCKET)-1)
  78 #  define SOCKET_ERROR            -1
  79 # endif
  80 
  81 # if !defined(CBUFSIZE)
  82 #  define CBUFSIZE 1024
  83 #  define sim_printf printf
  84 # endif
  85 
  86 int sim_parse_addr \
  87         (const char *cptr, char *host, size_t hostlen, const char *default_host,
  88          char *port, size_t port_len, const char *default_port, const char *validate_addr);
  89 # if defined(UNUSED)
  90 int sim_parse_addr_ex \
  91         (const char *cptr, char *host, size_t hostlen, const char *default_host,
  92          char *port, size_t port_len, char *localport, size_t local_port_len, const char *default_port);
  93 # endif /* if defined(UNUSED) */
  94 # define SIM_SOCK_OPT_REUSEADDR      0x0001
  95 # define SIM_SOCK_OPT_DATAGRAM       0x0002
  96 # define SIM_SOCK_OPT_NODELAY        0x0004
  97 # define SIM_SOCK_OPT_BLOCKING       0x0008
  98 SOCKET sim_master_sock_ex \
  99            (const char *hostport, int *parse_status, int opt_flags);
 100 # define sim_master_sock(hostport, parse_status) \
 101     sim_master_sock_ex(hostport, parse_status, ((sim_switches & SWMASK ('U')) ? SIM_SOCK_OPT_REUSEADDR : 0))
 102 SOCKET sim_connect_sock_ex \
 103            (const char *sourcehostport, const char *hostport, const char *default_host, const char *default_port, int opt_flags);
 104 # define sim_connect_sock(hostport, default_host, default_port) \
 105     sim_connect_sock_ex(NULL, hostport, default_host, default_port, SIM_SOCK_OPT_NONBLOCK)
 106 SOCKET sim_accept_conn_ex \
 107            (SOCKET master, char **connectaddr, int opt_flags);
 108 # define sim_accept_conn(master, connectaddr) \
 109     sim_accept_conn_ex(master, connectaddr, 0)
 110 int sim_check_conn (SOCKET sock, int rd);
 111 int sim_read_sock (SOCKET sock, char *buf, int nbytes);
 112 int sim_write_sock (SOCKET sock, const char *msg, int nbytes);
 113 void sim_close_sock (SOCKET sock);
 114 const char *sim_get_err_sock (const char *emsg);
 115 SOCKET sim_err_sock (SOCKET sock, const char *emsg);
 116 int sim_getnames_sock (SOCKET sock, char **socknamebuf, char **peernamebuf);
 117 void sim_init_sock (void);
 118 void sim_cleanup_sock (void);
 119 extern const char *xstrerror_l(int errnum);
 120 
 121 #endif

/* [previous][next][first][last][top][bottom][index][help] */