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