socket.h 5.52 KB
Newer Older
Andrew Innes's avatar
Andrew Innes committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* Copyright (C) 1995 Free Software Foundation, Inc.

This file is part of GNU Emacs.

GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */


Geoff Voelker's avatar
Geoff Voelker committed
21 22 23 24 25 26 27 28 29
/* Workable version of <sys/socket.h> based on winsock.h */

#ifndef _SOCKET_H_
#define _SOCKET_H_

/* defeat the multiple include protection */
#ifdef _WINSOCKAPI_
#undef _WINSOCKAPI_
#endif
30 31 32
#ifdef _WINSOCK_H
#undef _WINSOCK_H
#endif
Geoff Voelker's avatar
Geoff Voelker committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

/* avoid confusion with our version of select */
#ifdef select
#undef select
#define MUST_REDEF_SELECT
#endif

/* avoid clashing with our version of FD_SET if already defined */
#ifdef FD_SET
#undef FD_SET
#undef FD_CLR
#undef FD_ISSET
#undef FD_ZERO
#endif

/* avoid duplicate definition of timeval */
#ifdef HAVE_TIMEVAL
#define timeval ws_timeval
#endif

#include <winsock.h>

/* redefine select to reference our version */
#ifdef MUST_REDEF_SELECT
#define select sys_select
#undef MUST_REDEF_SELECT
#endif

/* revert to our version of FD_SET */
#undef FD_SET
#undef FD_CLR
#undef FD_ISSET
#undef FD_ZERO
66 67 68

/* allow us to provide our own version of fd_set */
#define fd_set ws_fd_set
Geoff Voelker's avatar
Geoff Voelker committed
69
#include "w32.h"
Geoff Voelker's avatar
Geoff Voelker committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83

#ifdef HAVE_TIMEVAL
#undef timeval
#endif

/* shadow functions where we provide our own wrapper */
#define socket         sys_socket
#define bind           sys_bind
#define connect        sys_connect
#define htons          sys_htons
#define ntohs          sys_ntohs
#define inet_addr      sys_inet_addr
#define gethostname    sys_gethostname
#define gethostbyname  sys_gethostbyname
Jason Rumney's avatar
Jason Rumney committed
84
#define getpeername    sys_getpeername
Geoff Voelker's avatar
Geoff Voelker committed
85
#define getservbyname  sys_getservbyname
Geoff Voelker's avatar
Geoff Voelker committed
86
#define shutdown       sys_shutdown
87 88 89 90 91 92
#define setsockopt     sys_setsockopt
#define listen         sys_listen
#define getsockname    sys_getsockname
#define accept         sys_accept
#define recvfrom       sys_recvfrom
#define sendto         sys_sendto
Geoff Voelker's avatar
Geoff Voelker committed
93 94 95 96 97 98 99 100

int sys_socket(int af, int type, int protocol);
int sys_bind (int s, const struct sockaddr *addr, int namelen);
int sys_connect (int s, const struct sockaddr *addr, int namelen);
u_short sys_htons (u_short hostshort);
u_short sys_ntohs (u_short netshort);
unsigned long sys_inet_addr (const char * cp);
int sys_gethostname (char * name, int namelen);
Jason Rumney's avatar
Jason Rumney committed
101 102 103
struct hostent * sys_gethostbyname (const char * name);
struct servent * sys_getservbyname (const char * name, const char * proto);
int sys_getpeername (int s, struct sockaddr *addr, int * namelen);
Geoff Voelker's avatar
Geoff Voelker committed
104
int sys_shutdown (int socket, int how);
105
int sys_setsockopt (int s, int level, int oname, const void * oval, int olen);
106 107 108 109 110 111 112
int sys_listen (int s, int backlog);
int sys_getsockname (int s, struct sockaddr * name, int * namelen);
int sys_accept (int s, struct sockaddr *addr, int *addrlen);
int sys_recvfrom (int s, char *buf, int len, int flags,
		  struct sockaddr *from, int * fromlen);
int sys_sendto (int s, const char * buf, int len, int flags,
		const struct sockaddr *to, int tolen);
Geoff Voelker's avatar
Geoff Voelker committed
113

Jason Rumney's avatar
Jason Rumney committed
114 115 116 117 118 119
/* In addition to wrappers for the winsock functions, we also provide
   an fcntl function, for setting sockets to non-blocking mode.  */
int fcntl (int s, int cmd, int options);
#define F_SETFL   4
#define O_NDELAY  04000

Geoff Voelker's avatar
Geoff Voelker committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
/* we are providing a real h_errno variable */
#undef h_errno
extern int h_errno;

/* map winsock error codes to standard names */
#define EWOULDBLOCK             WSAEWOULDBLOCK
#define EINPROGRESS             WSAEINPROGRESS
#define EALREADY                WSAEALREADY
#define ENOTSOCK                WSAENOTSOCK
#define EDESTADDRREQ            WSAEDESTADDRREQ
#define EMSGSIZE                WSAEMSGSIZE
#define EPROTOTYPE              WSAEPROTOTYPE
#define ENOPROTOOPT             WSAENOPROTOOPT
#define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
#define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
#define EOPNOTSUPP              WSAEOPNOTSUPP
#define EPFNOSUPPORT            WSAEPFNOSUPPORT
#define EAFNOSUPPORT            WSAEAFNOSUPPORT
#define EADDRINUSE              WSAEADDRINUSE
#define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
#define ENETDOWN                WSAENETDOWN
#define ENETUNREACH             WSAENETUNREACH
#define ENETRESET               WSAENETRESET
#define ECONNABORTED            WSAECONNABORTED
#define ECONNRESET              WSAECONNRESET
#define ENOBUFS                 WSAENOBUFS
#define EISCONN                 WSAEISCONN
#define ENOTCONN                WSAENOTCONN
#define ESHUTDOWN               WSAESHUTDOWN
#define ETOOMANYREFS            WSAETOOMANYREFS
#define ETIMEDOUT               WSAETIMEDOUT
#define ECONNREFUSED            WSAECONNREFUSED
#define ELOOP                   WSAELOOP
/* #define ENAMETOOLONG            WSAENAMETOOLONG */
#define EHOSTDOWN               WSAEHOSTDOWN
#define EHOSTUNREACH            WSAEHOSTUNREACH
/* #define ENOTEMPTY               WSAENOTEMPTY */
#define EPROCLIM                WSAEPROCLIM
#define EUSERS                  WSAEUSERS
#define EDQUOT                  WSAEDQUOT
#define ESTALE                  WSAESTALE
#define EREMOTE                 WSAEREMOTE

#endif /* _SOCKET_H_ */

/* end of socket.h */
Miles Bader's avatar
Miles Bader committed
166 167 168

/* arch-tag: e3b8b91c-aaa0-4bc4-be57-a85a1dd247b4
   (do not change this comment) */