| 1 | /* |
| 2 | * Copyright (C) 1999 Philippe Dubois ([email protected]) |
| 3 | * Copyright (C) 1999,2000,2002 Ross Combs ([email protected]) |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | #ifndef JUST_NEED_TYPES |
| 20 | #ifndef INCLUDED_PSOCK_PROTOS |
| 21 | #define INCLUDED_PSOCK_PROTOS |
| 22 | |
| 23 | /* |
| 24 | * This file is like the other compat header files in that it |
| 25 | * tries to hide differences between systems. It is somewhat |
| 26 | * different in that it doesn't present a "normal" interface |
| 27 | * to the rest of the code, but instead defines its own macros |
| 28 | * and functions. This is done since Win32 uses closesocket() |
| 29 | * instead of close() for sockets, but it can't be remapped |
| 30 | * since it already has a close() for file descriptors. Also, |
| 31 | * this allows us to hide the fact that some systems use |
| 32 | * fcntl() and some use ioctl(). The select() function is |
| 33 | * included here even though it isn't strictly for sockets. |
| 34 | * Just call this version if any of the file descriptors might |
| 35 | * be sockets. |
| 36 | * |
| 37 | * This file must be included _after_ any other socket related |
| 38 | * headers and any other compat socket fixup headers. |
| 39 | */ |
| 40 | |
| 41 | #ifdef WIN32 /* winsock2 */ |
| 42 | |
| 43 | #include <winsock2.h> |
| 44 | |
| 45 | /* protocol families */ |
| 46 | #define PSOCK_PF_INET PF_INET |
| 47 | |
| 48 | /* address families */ |
| 49 | #define PSOCK_AF_INET AF_INET |
| 50 | |
| 51 | /* socket types */ |
| 52 | #define PSOCK_SOCK_STREAM SOCK_STREAM |
| 53 | #define PSOCK_SOCK_DGRAM SOCK_DGRAM |
| 54 | |
| 55 | /* socket protocols */ |
| 56 | #ifdef IPPROTO_TCP |
| 57 | # define PSOCK_IPPROTO_TCP IPPROTO_TCP |
| 58 | #else |
| 59 | # define PSOCK_IPPROTO_TCP 0 |
| 60 | #endif |
| 61 | #ifdef IPPROTO_UDP |
| 62 | # define PSOCK_IPPROTO_UDP IPPROTO_UDP |
| 63 | #else |
| 64 | # define PSOCK_IPPROTO_UDP 0 |
| 65 | #endif |
| 66 | |
| 67 | /* psock_[gs]etsockopt() flags */ |
| 68 | #define PSOCK_SOL_SOCKET SOL_SOCKET |
| 69 | #define PSOCK_SO_REUSEADDR SO_REUSEADDR |
| 70 | #define PSOCK_SO_KEEPALIVE SO_KEEPALIVE |
| 71 | #define PSOCK_SO_ERROR SO_ERROR |
| 72 | |
| 73 | /* psock_ctl() flags */ |
| 74 | #define PSOCK_NONBLOCK FIONBIO |
| 75 | |
| 76 | /* psock_errno() values */ |
| 77 | #ifdef WSAEWOULDBLOCK |
| 78 | # define PSOCK_EWOULDBLOCK WSAEWOULDBLOCK |
| 79 | #endif |
| 80 | #ifdef WSAEINPROGRESS |
| 81 | # define PSOCK_EINPROGRESS WSAEINPROGRESS |
| 82 | #endif |
| 83 | #ifdef WSAEINTR |
| 84 | # define PSOCK_EINTR WSAEINTR |
| 85 | #endif |
| 86 | #ifdef WSAECONNABORTED |
| 87 | # define PSOCK_ECONNABORTED WSAECONNABORTED |
| 88 | #endif |
| 89 | #ifdef WSATRY_AGAIN |
| 90 | # define PSOCK_EAGAIN WSATRY_AGAIN |
| 91 | #endif |
| 92 | #ifdef WSAECONNRESET |
| 93 | # define PSOCK_ECONNRESET WSAECONNRESET |
| 94 | #endif |
| 95 | #ifdef WSAENOTCONN |
| 96 | # define PSOCK_ENOTCONN WSAENOTCONN |
| 97 | #endif |
| 98 | #ifdef WSAEPIPE |
| 99 | # define PSOCK_EPIPE WSAEPIPE |
| 100 | #endif |
| 101 | #ifdef WSAEPROTO |
| 102 | # define PSOCK_EPROTO WSAEPROTO |
| 103 | #endif |
| 104 | #ifdef WSAENOBUFS |
| 105 | # define PSOCK_ENOBUFS WSAENOBUFS |
| 106 | #endif |
| 107 | #ifdef WSAENOMEM |
| 108 | # define PSOCK_ENOMEM WSAENOMEM |
| 109 | #endif |
| 110 | |
| 111 | /* psock_shutdown() flags */ |
| 112 | #define PSOCK_SHUT_RD 0 |
| 113 | #define PSOCK_SHUT_WR 1 |
| 114 | #define PSOCK_SHUT_RDWR 2 |
| 115 | |
| 116 | /* psock types */ |
| 117 | #define psock_t_socklen int |
| 118 | |
| 119 | /* psock_select() macros and types */ |
| 120 | #define t_psock_fd_set fd_set |
| 121 | #define PSOCK_FD_ZERO FD_ZERO |
| 122 | #define PSOCK_FD_CLR FD_CLR |
| 123 | #define PSOCK_FD_SET FD_SET |
| 124 | #define PSOCK_FD_ISSET FD_ISSET |
| 125 | |
| 126 | /* psock functions */ |
| 127 | extern int psock_init(void); /* a real functions in */ |
| 128 | extern int psock_deinit(void); /* compat/psock.c */ |
| 129 | #define psock_errno() WSAGetLastError() |
| 130 | #define psock_socket(pf, t, ps) socket(pf, t, ps) |
| 131 | #define psock_getsockopt(s, l, o, v, size) getsockopt(s, l, o, (char *)(v), size) |
| 132 | #define psock_setsockopt(s, l, o, v, size) setsockopt(s, l, o, (const char *)(v), size) |
| 133 | extern int psock_ctl(int sd, int mode); /* a real function in compat/psock.c */ |
| 134 | #define psock_listen(s, b) listen(s, b) |
| 135 | #define psock_bind(s, a, l) bind(s, a, l) |
| 136 | #define psock_accept(s, a, l) accept(s, a, l) |
| 137 | #define psock_connect(s, a, l) connect(s, a, l) |
| 138 | #define psock_send(s, b, l, f) send(s, (const char *)(b), l, f) |
| 139 | #define psock_sendto(s, b, l, f, a, al) sendto(s, (const char *)(b), l, f, a, al) |
| 140 | #define psock_recv(s, b, l, f) recv(s, (char *)(b), l, f) |
| 141 | #define psock_recvfrom(s, b, l, f, a, al) recvfrom(s, (char *)(b), l, f, a, al) |
| 142 | #define psock_shutdown(s, how) shutdown(s, how) |
| 143 | #define psock_close(s) closesocket(s) |
| 144 | #define psock_select(s, r, w, e, t) select(s, r, w, e ,t) |
| 145 | #define psock_getsockname(s, a, l) getsockname(s, a, l) |
| 146 | |
| 147 | /* PDubois - 991111 */ |
| 148 | /*#define inet_aton(cp, pAdd) (((*pAdd).s_addr = inet_addr(cp)) != INADDR_NONE)*/ |
| 149 | /* (this should be done in compat/inet_aton.h and this isn't a 100% correct implementation anyway -Ross) */ |
| 150 | |
| 151 | #else /* assume POSIX */ |
| 152 | |
| 153 | #ifdef HAVE_SYS_TYPES_H |
| 154 | # include <sys/types.h> |
| 155 | #endif |
| 156 | #ifdef HAVE_SYS_SOCKET_H |
| 157 | # include <sys/socket.h> |
| 158 | #endif |
| 159 | #ifdef HAVE_NETINET_IN_H |
| 160 | # include <netinet/in.h> |
| 161 | #endif |
| 162 | #ifdef HAVE_NETINET_IP_H |
| 163 | # include <netinet/ip.h> |
| 164 | #endif |
| 165 | #ifdef HAVE_SYS_SELECT_H |
| 166 | # include <sys/select.h> |
| 167 | #endif |
| 168 | #ifdef HAVE_SYS_TIME_H |
| 169 | # include <sys/time.h> |
| 170 | #endif |
| 171 | #ifdef HAVE_UNISTD_H |
| 172 | # include <unistd.h> |
| 173 | #endif |
| 174 | #ifdef HAVE_ARPA_INET_H |
| 175 | # include <arpa/inet.h> |
| 176 | #endif |
| 177 | #ifdef HAVE_NETDB_H |
| 178 | # include <netdb.h> |
| 179 | #endif |
| 180 | #ifdef HAVE_FCNTL_H |
| 181 | # include <fcntl.h> |
| 182 | #endif |
| 183 | #include <errno.h> |
| 184 | |
| 185 | /* protocol families */ |
| 186 | #define PSOCK_PF_INET PF_INET |
| 187 | |
| 188 | /* address families */ |
| 189 | #define PSOCK_AF_INET AF_INET |
| 190 | |
| 191 | /* socket types */ |
| 192 | #define PSOCK_SOCK_STREAM SOCK_STREAM |
| 193 | #define PSOCK_SOCK_DGRAM SOCK_DGRAM |
| 194 | |
| 195 | /* socket protocols */ |
| 196 | #ifdef IPPROTO_TCP |
| 197 | # define PSOCK_IPPROTO_TCP IPPROTO_TCP |
| 198 | #else |
| 199 | # define PSOCK_IPPROTO_TCP 0 |
| 200 | #endif |
| 201 | #ifdef IPPROTO_UDP |
| 202 | # define PSOCK_IPPROTO_UDP IPPROTO_UDP |
| 203 | #else |
| 204 | # define PSOCK_IPPROTO_UDP 0 |
| 205 | #endif |
| 206 | |
| 207 | /* psock_[gs]etsockopt() flags */ |
| 208 | #define PSOCK_SOL_SOCKET SOL_SOCKET |
| 209 | #define PSOCK_SO_REUSEADDR SO_REUSEADDR |
| 210 | #define PSOCK_SO_KEEPALIVE SO_KEEPALIVE |
| 211 | #define PSOCK_SO_ERROR SO_ERROR |
| 212 | |
| 213 | /* psock_ctl() flags */ |
| 214 | #define PSOCK_NONBLOCK O_NONBLOCK |
| 215 | |
| 216 | /* psock_errno() values */ |
| 217 | #ifdef EWOULDBLOCK |
| 218 | # define PSOCK_EWOULDBLOCK EWOULDBLOCK |
| 219 | #endif |
| 220 | #ifdef EINPROGRESS |
| 221 | # define PSOCK_EINPROGRESS EINPROGRESS |
| 222 | #endif |
| 223 | #ifdef EINTR |
| 224 | # define PSOCK_EINTR EINTR |
| 225 | #endif |
| 226 | #ifdef ECONNABORTED |
| 227 | # define PSOCK_ECONNABORTED ECONNABORTED |
| 228 | #endif |
| 229 | #ifdef EAGAIN |
| 230 | # define PSOCK_EAGAIN EAGAIN |
| 231 | #endif |
| 232 | #ifdef ECONNRESET |
| 233 | # define PSOCK_ECONNRESET ECONNRESET |
| 234 | #endif |
| 235 | #ifdef ENOTCONN |
| 236 | # define PSOCK_ENOTCONN ENOTCONN |
| 237 | #endif |
| 238 | #ifdef EPIPE |
| 239 | # define PSOCK_EPIPE EPIPE |
| 240 | #endif |
| 241 | #ifdef EPROTO |
| 242 | # define PSOCK_EPROTO EPROTO |
| 243 | #endif |
| 244 | #ifdef ENOBUFS |
| 245 | # define PSOCK_ENOBUFS ENOBUFS |
| 246 | #endif |
| 247 | #ifdef ENOMEM |
| 248 | # define PSOCK_ENOMEM ENOMEM |
| 249 | #endif |
| 250 | |
| 251 | /* psock_shutdown() flags */ |
| 252 | #ifdef SHUT_RD |
| 253 | # define PSOCK_SHUT_RD SHUT_RD |
| 254 | #else |
| 255 | # define PSOCK_SHUT_RD 0 |
| 256 | #endif |
| 257 | #ifdef SHUT_WR |
| 258 | # define PSOCK_SHUT_WR SHUT_WR |
| 259 | #else |
| 260 | # define PSOCK_SHUT_WR 1 |
| 261 | #endif |
| 262 | #ifdef SHUT_RDWR |
| 263 | # define PSOCK_SHUT_RDWR SHUT_RDWR |
| 264 | #else |
| 265 | # define PSOCK_SHUT_RDWR 2 |
| 266 | #endif |
| 267 | |
| 268 | /* psock types */ |
| 269 | /* FIXME: write configure test to check for this type */ |
| 270 | #ifdef HAVE_SOCKLEN_T |
| 271 | # define psock_t_socklen socklen_t |
| 272 | #else |
| 273 | # define psock_t_socklen unsigned int |
| 274 | #endif |
| 275 | |
| 276 | /* psock_select() macros and types */ |
| 277 | #define t_psock_fd_set fd_set |
| 278 | #define PSOCK_FD_ZERO FD_ZERO |
| 279 | #define PSOCK_FD_CLR FD_CLR |
| 280 | #define PSOCK_FD_SET FD_SET |
| 281 | #define PSOCK_FD_ISSET FD_ISSET |
| 282 | |
| 283 | /* psock functions */ |
| 284 | #define psock_init() (0) |
| 285 | #define psock_deinit() (0) |
| 286 | #define psock_errno() (errno) |
| 287 | #define psock_socket(pf, t, ps) socket(pf, t, ps) |
| 288 | #define psock_getsockopt(s, l, o, v, size) getsockopt(s, l, o, (void *)(v), size) |
| 289 | #define psock_setsockopt(s, l, o, v, size) setsockopt(s, l, o, (void *)(v), size) |
| 290 | extern int psock_ctl(int sd, long int mode); /* a real function in compat/psock.c */ |
| 291 | #define psock_listen(s, b) listen(s, b) |
| 292 | #define psock_bind(s, a, l) bind(s, a, l) |
| 293 | #define psock_accept(s, a, l) accept(s, a, l) |
| 294 | #define psock_connect(s, a, l) connect(s, a, l) |
| 295 | #define psock_send(s, b, l, f) send(s, (void *)(b), l, f) |
| 296 | #define psock_sendto(s, b, l, f, a, al) sendto(s, (void *)(b), l, f, a, al) |
| 297 | #define psock_recv(s, b, l, f) recv(s, (void *)(b), l, f) |
| 298 | #define psock_recvfrom(s, b, l, f, a, al) recvfrom(s, (void *)(b), l, f, a, al) |
| 299 | #define psock_shutdown(s, how) shutdown(s, how) |
| 300 | #define psock_close(s) close(s) |
| 301 | #define psock_select(s, r, w, e, t) select(s, r, w, e ,t) |
| 302 | #define psock_getsockname(s, a, l) getsockname(s, a, l) |
| 303 | |
| 304 | #endif |
| 305 | |
| 306 | #endif |
| 307 | #endif |