Re: perl@10722: Bogus warnings on REs
[p5sagit/p5-mst-13.2.git] / NetWare / nw5sck.c
CommitLineData
2986a63f 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 *
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
33static struct servent* nw_savecopyservent(struct servent*d,
34 struct servent*s,
35 const char *proto);
36
37
38u_long
39nw_htonl(u_long hostlong)
40{
41 return htonl(hostlong);
42}
43
44u_short
45nw_htons(u_short hostshort)
46{
47 return htons(hostshort);
48}
49
50u_long
51nw_ntohl(u_long netlong)
52{
53 return ntohl(netlong);
54}
55
56u_short
57nw_ntohs(u_short netshort)
58{
59 return ntohs(netshort);
60}
61
62SOCKET
63nw_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
64{
65 return ((SOCKET)(accept(s, addr, addrlen)));
66}
67
68int
69nw_bind(SOCKET s, const struct sockaddr *addr, int addrlen)
70{
71 return ((int)bind(s, (struct sockaddr *)addr, addrlen));
72
73}
74
75int
76nw_connect(SOCKET s, const struct sockaddr *addr, int addrlen)
77{
78 return((int)connect(s, (struct sockaddr *)addr, addrlen));
79}
80
81void
82nw_endhostent()
83{
84 endhostent();
85}
86
87void
88nw_endnetent()
89{
90 endnetent();
91}
92
93void
94nw_endprotoent()
95{
96 endprotoent();
97}
98
99void
100nw_endservent()
101{
102 endservent();
103}
104
105struct hostent *
106nw_gethostent()
107{
108 return(gethostent());
109}
110
111struct netent *
112nw_getnetent(void)
113{
114 return ((struct netent *) getnetent());
115}
116
117struct protoent *
118nw_getprotoent(void)
119{
120 return ((struct protoent *) getprotoent());
121}
122
123struct hostent *
124nw_gethostbyname(const char *name)
125{
126 return(gethostbyname((char*)name));
127}
128
129int
130nw_gethostname(char *name, int len)
131{
132 return(gethostname(name, len));
133}
134
135struct hostent *
136nw_gethostbyaddr(const char *addr, int len, int type)
137{
138 return(gethostbyaddr((char*)addr, len, type));
139}
140
141struct netent *
142nw_getnetbyaddr(long net, int type)
143{
144 return(getnetbyaddr(net,type));
145}
146
147struct netent *
148nw_getnetbyname(char *name)
149{
150 return (struct netent *)getnetbyname(name);
151}
152
153int
154nw_getpeername(SOCKET s, struct sockaddr *addr, int *addrlen)
155{
156 return((int)getpeername(s, addr, addrlen));
157}
158
159struct protoent *
160nw_getprotobyname(const char *name)
161{
162 return ((struct protoent *)getprotobyname((char*)name));
163}
164
165struct protoent *
166nw_getprotobynumber(int num)
167{
168 return ((struct protoent *)getprotobynumber(num));
169}
170
171struct servent *
172nw_getservbyname(const char *name, const char *proto)
173{
174 dTHXo;
175 struct servent *r;
176
177 r = getservbyname((char*)name, (char*)proto);
178 if (r) {
179 /*r = nw_savecopyservent(&nw_servent, r, proto);*/
180 }
181 return r;
182}
183
184
185struct servent *
186nw_getservbyport(int port, const char *proto)
187{
188 dTHXo;
189 struct servent *r;
190
191 r = getservbyport(port, (char*)proto);
192 if (r) {
193 //r = nw_savecopyservent(&nw_servent, r, proto);
194 }
195 return r;
196}
197
198struct servent *
199nw_getservent(void)
200{
201 return (struct servent *) getservent();
202}
203
204void
205nw_sethostent(int stayopen)
206{
207 sethostent(stayopen);
208}
209
210void
211nw_setnetent(int stayopen)
212{
213 setnetent(stayopen);
214}
215
216void
217nw_setprotoent(int stayopen)
218{
219 setprotoent(stayopen);
220}
221
222void
223nw_setservent(int stayopen)
224{
225 setservent(stayopen);
226}
227
228int
229nw_getsockname(SOCKET s, struct sockaddr *addr, int *addrlen)
230{
231 return getsockname(s, addr, addrlen);
232}
233
234int
235nw_getsockopt(SOCKET s, int level, int optname, char *optval, int *optlen)
236{
237 return ((int)getsockopt(s, level, optname, optval, optlen));
238}
239
240unsigned long
241nw_inet_addr(const char *cp)
242{
243 return inet_addr((char*)cp);
244}
245
246static struct servent*
247nw_savecopyservent(struct servent*d, struct servent*s, const char *proto)
248{
249 d->s_name = s->s_name;
250 d->s_aliases = s->s_aliases;
251 d->s_port = s->s_port;
252#ifndef __BORLANDC__ /* Buggy on Win95 and WinNT-with-Borland-WSOCK */
253 if (/*!IsWin95() && */s->s_proto && strlen(s->s_proto))
254 d->s_proto = s->s_proto;
255 else
256#endif
257 if (proto && strlen(proto))
258 d->s_proto = (char *)proto;
259 else
260 d->s_proto = "tcp";
261
262 return d;
263}
264
265SOCKET
266nw_socket(int af, int type, int protocol)
267{
268 SOCKET s;
269
270#ifndef USE_SOCKETS_AS_HANDLES
271 s = socket(af, type, protocol);
272#else
273 //StartSockets();
274 if((s = socket(af, type, protocol)) == INVALID_SOCKET)
275 //errno = WSAGetLastError();
276 else
277 s = s;
278#endif /* USE_SOCKETS_AS_HANDLES */
279
280 return s;
281}
282
283int
284nw_listen(SOCKET s, int backlog)
285{
286 return(listen(s, backlog));
287}
288
289int
290nw_send(SOCKET s, const char *buf, int len, int flags)
291{
292 return(send(s,(char*)buf,len,flags));
293}
294
295int
296nw_recv(SOCKET s, char *buf, int len, int flags)
297{
298 return (recv(s, buf, len, flags));
299}
300
301int
302nw_sendto(SOCKET s, const char *buf, int len, int flags,
303 const struct sockaddr *to, int tolen)
304{
305 return(sendto(s, (char*)buf, len, flags, (struct sockaddr *)to, tolen));
306}
307
308int
309nw_recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, int *fromlen)
310{
311 int r;
312 int frombufsize = *fromlen;
313
314 r = recvfrom(s, buf, len, flags, from, fromlen);
315 //Not sure if the is required - chksgp
316 if (r && frombufsize == *fromlen)
317 (void)nw_getpeername(s, from, fromlen);
318 return r;
319}
320
321int
322nw_select(int nfds, fd_set* rd, fd_set* wr, fd_set* ex, const struct timeval* timeout)
323{
324 return(select(nfds, rd, wr, ex, (struct timeval*)timeout));
325}
326
327int
328nw_shutdown(SOCKET s, int how)
329{
330 return (shutdown(s, how));
331}
332