/[LeafOK_CVS]/pvpgn-1.7.4/src/compat/psock.h
ViewVC logotype

Annotation of /pvpgn-1.7.4/src/compat/psock.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue Jun 6 03:41:38 2006 UTC (19 years, 9 months ago) by sysadm
CVS Tags: pvpgn_1-7-4-0_MIL
Branch point for: GNU, MAIN
Content type: text/x-chdr
Initial revision

1 sysadm 1.1 /*
2     * Copyright (C) 1999 Philippe Dubois (pdubois1@hotmail.com)
3     * Copyright (C) 1999,2000,2002 Ross Combs (rocombs@cs.nmsu.edu)
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, (void *)(v), size)
132     #define psock_setsockopt(s, l, o, v, size) setsockopt(s, l, o, (void *)(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, (void *)(b), l, f)
139     #define psock_sendto(s, b, l, f, a, al) sendto(s, (void *)(b), l, f, a, al)
140     #define psock_recv(s, b, l, f) recv(s, (void *)(b), l, f)
141     #define psock_recvfrom(s, b, l, f, a, al) recvfrom(s, (void *)(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     /* protocol families */
154     #define PSOCK_PF_INET PF_INET
155    
156     /* address families */
157     #define PSOCK_AF_INET AF_INET
158    
159     /* socket types */
160     #define PSOCK_SOCK_STREAM SOCK_STREAM
161     #define PSOCK_SOCK_DGRAM SOCK_DGRAM
162    
163     /* socket protocols */
164     #ifdef IPPROTO_TCP
165     # define PSOCK_IPPROTO_TCP IPPROTO_TCP
166     #else
167     # define PSOCK_IPPROTO_TCP 0
168     #endif
169     #ifdef IPPROTO_UDP
170     # define PSOCK_IPPROTO_UDP IPPROTO_UDP
171     #else
172     # define PSOCK_IPPROTO_UDP 0
173     #endif
174    
175     /* psock_[gs]etsockopt() flags */
176     #define PSOCK_SOL_SOCKET SOL_SOCKET
177     #define PSOCK_SO_REUSEADDR SO_REUSEADDR
178     #define PSOCK_SO_KEEPALIVE SO_KEEPALIVE
179     #define PSOCK_SO_ERROR SO_ERROR
180    
181     /* psock_ctl() flags */
182     #define PSOCK_NONBLOCK O_NONBLOCK
183    
184     /* psock_errno() values */
185     #ifdef EWOULDBLOCK
186     # define PSOCK_EWOULDBLOCK EWOULDBLOCK
187     #endif
188     #ifdef EINPROGRESS
189     # define PSOCK_EINPROGRESS EINPROGRESS
190     #endif
191     #ifdef EINTR
192     # define PSOCK_EINTR EINTR
193     #endif
194     #ifdef ECONNABORTED
195     # define PSOCK_ECONNABORTED ECONNABORTED
196     #endif
197     #ifdef EAGAIN
198     # define PSOCK_EAGAIN EAGAIN
199     #endif
200     #ifdef ECONNRESET
201     # define PSOCK_ECONNRESET ECONNRESET
202     #endif
203     #ifdef ENOTCONN
204     # define PSOCK_ENOTCONN ENOTCONN
205     #endif
206     #ifdef EPIPE
207     # define PSOCK_EPIPE EPIPE
208     #endif
209     #ifdef EPROTO
210     # define PSOCK_EPROTO EPROTO
211     #endif
212     #ifdef ENOBUFS
213     # define PSOCK_ENOBUFS ENOBUFS
214     #endif
215     #ifdef ENOMEM
216     # define PSOCK_ENOMEM ENOMEM
217     #endif
218    
219     /* psock_shutdown() flags */
220     #ifdef SHUT_RD
221     # define PSOCK_SHUT_RD SHUT_RD
222     #else
223     # define PSOCK_SHUT_RD 0
224     #endif
225     #ifdef SHUT_WR
226     # define PSOCK_SHUT_WR SHUT_WR
227     #else
228     # define PSOCK_SHUT_WR 1
229     #endif
230     #ifdef SHUT_RDWR
231     # define PSOCK_SHUT_RDWR SHUT_RDWR
232     #else
233     # define PSOCK_SHUT_RDWR 2
234     #endif
235    
236     /* psock types */
237     /* FIXME: write configure test to check for this type */
238     #ifdef HAVE_SOCKLEN_T
239     # define psock_t_socklen socklen_t
240     #else
241     # define psock_t_socklen unsigned int
242     #endif
243    
244     /* psock_select() macros and types */
245     #define t_psock_fd_set fd_set
246     #define PSOCK_FD_ZERO FD_ZERO
247     #define PSOCK_FD_CLR FD_CLR
248     #define PSOCK_FD_SET FD_SET
249     #define PSOCK_FD_ISSET FD_ISSET
250    
251     /* psock functions */
252     #define psock_init() (0)
253     #define psock_deinit() (0)
254     #define psock_errno() (errno)
255     #define psock_socket(pf, t, ps) socket(pf, t, ps)
256     #define psock_getsockopt(s, l, o, v, size) getsockopt(s, l, o, (void *)(v), size)
257     #define psock_setsockopt(s, l, o, v, size) setsockopt(s, l, o, (void *)(v), size)
258     extern int psock_ctl(int sd, long int mode); /* a real function in compat/psock.c */
259     #define psock_listen(s, b) listen(s, b)
260     #define psock_bind(s, a, l) bind(s, a, l)
261     #define psock_accept(s, a, l) accept(s, a, l)
262     #define psock_connect(s, a, l) connect(s, a, l)
263     #define psock_send(s, b, l, f) send(s, (void *)(b), l, f)
264     #define psock_sendto(s, b, l, f, a, al) sendto(s, (void *)(b), l, f, a, al)
265     #define psock_recv(s, b, l, f) recv(s, (void *)(b), l, f)
266     #define psock_recvfrom(s, b, l, f, a, al) recvfrom(s, (void *)(b), l, f, a, al)
267     #define psock_shutdown(s, how) shutdown(s, how)
268     #define psock_close(s) close(s)
269     #define psock_select(s, r, w, e, t) select(s, r, w, e ,t)
270     #define psock_getsockname(s, a, l) getsockname(s, a, l)
271    
272     #endif
273    
274     #endif
275     #endif

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1