Commit | Line | Data |
---|---|---|
2986a63f JH |
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 JH |
11 | * FILENAME : nw5sck.c |
12 | * DESCRIPTION : Socket related functions. | |
13 | * Author : SGP | |
14 | * Date : January 2001. | |
15 | * Date Modified: June 26th 2001. | |
2986a63f JH |
16 | */ |
17 | ||
18 | ||
19 | ||
20 | #include "EXTERN.h" | |
21 | #include "perl.h" | |
22 | ||
2986a63f JH |
23 | #include "nw5iop.h" |
24 | #include "nw5sck.h" | |
25 | #include <fcntl.h> | |
26 | #include <sys/stat.h> | |
27 | ||
4d76e4b4 JH |
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. | |
30 | char nwinet_scratch[18] = {'\0'}; | |
31 | ||
32 | ||
2986a63f JH |
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 | { | |
8dbfbba0 | 169 | return (struct servent *)getservbyname((char*)name, (char*)proto); |
2986a63f JH |
170 | } |
171 | ||
172 | ||
173 | struct servent * | |
174 | nw_getservbyport(int port, const char *proto) | |
175 | { | |
8dbfbba0 | 176 | return (struct servent *)getservbyport(port, (char*)proto); |
2986a63f JH |
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 | |
225a5dca JH |
210 | nw_setsockopt(SOCKET s, int level, int optname, const char* optval, int optlen) |
211 | { | |
8dbfbba0 | 212 | return setsockopt(s, level, optname, (char*)optval, optlen); |
225a5dca JH |
213 | } |
214 | ||
215 | int | |
2986a63f JH |
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 | ||
4d76e4b4 JH |
233 | char * |
234 | nw_inet_ntoa(struct in_addr in) | |
235 | { | |
236 | return inet_ntoa(in); | |
237 | } | |
238 | ||
2986a63f JH |
239 | SOCKET |
240 | nw_socket(int af, int type, int protocol) | |
241 | { | |
242 | SOCKET s; | |
243 | ||
244 | #ifndef USE_SOCKETS_AS_HANDLES | |
245 | s = socket(af, type, protocol); | |
246 | #else | |
2986a63f JH |
247 | if((s = socket(af, type, protocol)) == INVALID_SOCKET) |
248 | //errno = WSAGetLastError(); | |
249 | else | |
250 | s = s; | |
251 | #endif /* USE_SOCKETS_AS_HANDLES */ | |
252 | ||
253 | return s; | |
254 | } | |
255 | ||
256 | int | |
257 | nw_listen(SOCKET s, int backlog) | |
258 | { | |
259 | return(listen(s, backlog)); | |
260 | } | |
261 | ||
262 | int | |
263 | nw_send(SOCKET s, const char *buf, int len, int flags) | |
264 | { | |
265 | return(send(s,(char*)buf,len,flags)); | |
266 | } | |
267 | ||
268 | int | |
269 | nw_recv(SOCKET s, char *buf, int len, int flags) | |
270 | { | |
271 | return (recv(s, buf, len, flags)); | |
272 | } | |
273 | ||
274 | int | |
275 | nw_sendto(SOCKET s, const char *buf, int len, int flags, | |
276 | const struct sockaddr *to, int tolen) | |
277 | { | |
278 | return(sendto(s, (char*)buf, len, flags, (struct sockaddr *)to, tolen)); | |
279 | } | |
280 | ||
281 | int | |
282 | nw_recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, int *fromlen) | |
283 | { | |
284 | int r; | |
285 | int frombufsize = *fromlen; | |
286 | ||
287 | r = recvfrom(s, buf, len, flags, from, fromlen); | |
288 | //Not sure if the is required - chksgp | |
289 | if (r && frombufsize == *fromlen) | |
290 | (void)nw_getpeername(s, from, fromlen); | |
291 | return r; | |
292 | } | |
293 | ||
294 | int | |
295 | nw_select(int nfds, fd_set* rd, fd_set* wr, fd_set* ex, const struct timeval* timeout) | |
296 | { | |
297 | return(select(nfds, rd, wr, ex, (struct timeval*)timeout)); | |
298 | } | |
299 | ||
300 | int | |
301 | nw_shutdown(SOCKET s, int how) | |
302 | { | |
303 | return (shutdown(s, how)); | |
304 | } | |
305 |