Commit | Line | Data |
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. |
30 | char nwinet_scratch[18] = {'\0'}; |
31 | |
32 | |
2986a63f |
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 |
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 |
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 | { |
011f1a1a |
188 | #ifdef HAS_SETHOSTENT |
2986a63f |
189 | sethostent(stayopen); |
011f1a1a |
190 | #endif |
2986a63f |
191 | } |
192 | |
193 | void |
194 | nw_setnetent(int stayopen) |
195 | { |
011f1a1a |
196 | #ifdef HAS_SETNETENT |
2986a63f |
197 | setnetent(stayopen); |
011f1a1a |
198 | #endif |
2986a63f |
199 | } |
200 | |
201 | void |
202 | nw_setprotoent(int stayopen) |
203 | { |
011f1a1a |
204 | #ifdef HAS_SETPROTENT |
2986a63f |
205 | setprotoent(stayopen); |
011f1a1a |
206 | #endif |
2986a63f |
207 | } |
208 | |
209 | void |
210 | nw_setservent(int stayopen) |
211 | { |
011f1a1a |
212 | #ifdef HAS_SETSERVENT |
2986a63f |
213 | setservent(stayopen); |
011f1a1a |
214 | #endif |
2986a63f |
215 | } |
216 | |
217 | int |
225a5dca |
218 | nw_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 | |
223 | int |
2986a63f |
224 | nw_getsockname(SOCKET s, struct sockaddr *addr, int *addrlen) |
225 | { |
226 | return getsockname(s, addr, addrlen); |
227 | } |
228 | |
229 | int |
230 | nw_getsockopt(SOCKET s, int level, int optname, char *optval, int *optlen) |
231 | { |
232 | return ((int)getsockopt(s, level, optname, optval, optlen)); |
233 | } |
234 | |
235 | unsigned long |
236 | nw_inet_addr(const char *cp) |
237 | { |
238 | return inet_addr((char*)cp); |
239 | } |
240 | |
4d76e4b4 |
241 | char * |
242 | nw_inet_ntoa(struct in_addr in) |
243 | { |
244 | return inet_ntoa(in); |
245 | } |
246 | |
2986a63f |
247 | SOCKET |
248 | nw_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 | |
264 | int |
265 | nw_listen(SOCKET s, int backlog) |
266 | { |
267 | return(listen(s, backlog)); |
268 | } |
269 | |
270 | int |
271 | nw_send(SOCKET s, const char *buf, int len, int flags) |
272 | { |
273 | return(send(s,(char*)buf,len,flags)); |
274 | } |
275 | |
276 | int |
277 | nw_recv(SOCKET s, char *buf, int len, int flags) |
278 | { |
279 | return (recv(s, buf, len, flags)); |
280 | } |
281 | |
282 | int |
283 | nw_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 | |
289 | int |
290 | nw_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 | |
302 | int |
303 | nw_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 | |
308 | int |
309 | nw_shutdown(SOCKET s, int how) |
310 | { |
311 | return (shutdown(s, how)); |
312 | } |
313 | |