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