fix fs.t for VMS
[p5sagit/p5-mst-13.2.git] / NetWare / nw5sck.c
1
2 /*
3  * Copyright © 2001 Novell, Inc. All Rights Reserved.
4  *
5  * You may distribute under the terms of either the GNU General Public
6  * License or the Artistic License, as specified in the README file.
7  *
8  */
9
10 /*
11  * FILENAME     :  nw5sck.c
12  * DESCRIPTION  :  Socket related functions.
13  * Author               :  SGP
14  * Date                 :  January 2001.
15  * Date Modified:  June 26th 2001.
16  */
17
18
19
20 #include "EXTERN.h"
21 #include "perl.h"
22
23 #if defined(PERL_OBJECT)
24 #define NO_XSLOCKS
25 #include "XSUB.h"
26 #endif
27
28 #include "nw5iop.h"
29 #include "nw5sck.h"
30 #include <fcntl.h>
31 #include <sys/stat.h>
32
33 u_long
34 nw_htonl(u_long hostlong)
35 {
36     return htonl(hostlong);
37 }
38
39 u_short
40 nw_htons(u_short hostshort)
41 {
42     return htons(hostshort);
43 }
44
45 u_long
46 nw_ntohl(u_long netlong)
47 {
48     return ntohl(netlong);
49 }
50
51 u_short
52 nw_ntohs(u_short netshort)
53 {
54     return ntohs(netshort);
55 }
56
57 SOCKET
58 nw_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
59 {
60         return ((SOCKET)(accept(s, addr, addrlen)));
61 }
62
63 int
64 nw_bind(SOCKET s, const struct sockaddr *addr, int addrlen)
65 {
66         return ((int)bind(s, (struct sockaddr *)addr, addrlen));
67
68 }
69
70 int
71 nw_connect(SOCKET s, const struct sockaddr *addr, int addrlen)
72 {
73         return((int)connect(s, (struct sockaddr *)addr, addrlen));
74 }
75
76 void
77 nw_endhostent() 
78 {
79         endhostent();
80 }
81
82 void
83 nw_endnetent()
84 {
85         endnetent();
86 }
87
88 void
89 nw_endprotoent()
90 {
91         endprotoent();
92 }
93
94 void
95 nw_endservent()
96 {
97         endservent();
98 }
99
100 struct hostent *
101 nw_gethostent()
102 {
103         return(gethostent());
104 }
105
106 struct netent *
107 nw_getnetent(void) 
108 {
109     return ((struct netent *) getnetent());
110 }
111
112 struct protoent *
113 nw_getprotoent(void) 
114 {
115     return ((struct protoent *) getprotoent());
116 }
117
118 struct hostent *
119 nw_gethostbyname(const char *name)
120 {
121         return(gethostbyname((char*)name));
122 }
123
124 int
125 nw_gethostname(char *name, int len)
126 {
127     return(gethostname(name, len));
128 }
129
130 struct hostent *
131 nw_gethostbyaddr(const char *addr, int len, int type)
132 {
133         return(gethostbyaddr((char*)addr, len, type));
134 }
135
136 struct netent *
137 nw_getnetbyaddr(long net, int type) 
138 {
139         return(getnetbyaddr(net,type));
140 }
141
142 struct netent *
143 nw_getnetbyname(char *name) 
144 {
145     return (struct netent *)getnetbyname(name);
146 }
147
148 int
149 nw_getpeername(SOCKET s, struct sockaddr *addr, int *addrlen)
150 {
151         return((int)getpeername(s, addr, addrlen));
152 }
153
154 struct protoent *
155 nw_getprotobyname(const char *name)
156 {
157         return ((struct protoent *)getprotobyname((char*)name));
158 }
159
160 struct protoent *
161 nw_getprotobynumber(int num)
162 {
163         return ((struct protoent *)getprotobynumber(num));
164 }
165
166 struct servent *
167 nw_getservbyname(const char *name, const char *proto)
168 {
169     return (struct servent *)getservbyname((char*)name, (char*)proto);
170 }
171
172
173 struct servent *
174 nw_getservbyport(int port, const char *proto)
175 {
176     return (struct servent *)getservbyport(port, (char*)proto);
177 }
178
179 struct servent *
180 nw_getservent(void) 
181 {
182     return (struct servent *) getservent();
183 }
184
185 void
186 nw_sethostent(int stayopen)
187 {
188         sethostent(stayopen);
189 }
190
191 void
192 nw_setnetent(int stayopen)
193 {
194         setnetent(stayopen);
195 }
196
197 void
198 nw_setprotoent(int stayopen)
199 {
200         setprotoent(stayopen);
201 }
202
203 void
204 nw_setservent(int stayopen)
205 {
206         setservent(stayopen);
207 }
208
209 int
210 nw_setsockopt(SOCKET s, int level, int optname, const char* optval, int optlen)
211 {
212         return setsockopt(s, level, optname, (char*)optval, optlen);
213 }
214
215 int
216 nw_getsockname(SOCKET s, struct sockaddr *addr, int *addrlen)
217 {
218         return getsockname(s, addr, addrlen);
219 }
220
221 int
222 nw_getsockopt(SOCKET s, int level, int optname, char *optval, int *optlen)
223 {
224         return ((int)getsockopt(s, level, optname, optval, optlen));
225 }
226
227 unsigned long
228 nw_inet_addr(const char *cp)
229 {
230     return inet_addr((char*)cp);
231 }
232
233 SOCKET
234 nw_socket(int af, int type, int protocol)
235 {
236     SOCKET s;
237
238 #ifndef USE_SOCKETS_AS_HANDLES
239     s = socket(af, type, protocol);
240 #else
241     if((s = socket(af, type, protocol)) == INVALID_SOCKET)
242         //errno = WSAGetLastError();
243     else
244         s = s;
245 #endif  /* USE_SOCKETS_AS_HANDLES */
246
247     return s;
248 }
249
250 int
251 nw_listen(SOCKET s, int backlog)
252 {
253     return(listen(s, backlog));
254 }
255
256 int
257 nw_send(SOCKET s, const char *buf, int len, int flags)
258 {
259         return(send(s,(char*)buf,len,flags));
260 }
261
262 int
263 nw_recv(SOCKET s, char *buf, int len, int flags)
264 {
265         return (recv(s, buf, len, flags));
266 }
267
268 int
269 nw_sendto(SOCKET s, const char *buf, int len, int flags,
270              const struct sockaddr *to, int tolen)
271 {
272     return(sendto(s, (char*)buf, len, flags, (struct sockaddr *)to, tolen));
273 }
274
275 int
276 nw_recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, int *fromlen)
277 {
278     int r;
279     int frombufsize = *fromlen;
280
281     r = recvfrom(s, buf, len, flags, from, fromlen);
282         //Not sure if the is required - chksgp
283     if (r && frombufsize == *fromlen)
284         (void)nw_getpeername(s, from, fromlen);
285     return r;
286 }
287
288 int
289 nw_select(int nfds, fd_set* rd, fd_set* wr, fd_set* ex, const struct timeval* timeout)
290 {
291         return(select(nfds, rd, wr, ex, (struct timeval*)timeout));
292 }
293
294 int
295 nw_shutdown(SOCKET s, int how)
296 {
297     return (shutdown(s, how));
298 }
299