This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Another small clean-up following changes #23190 and #23198
[perl5.git] / win32 / win32sck.c
CommitLineData
326b05e3 1/* win32sck.c
68dc0745
PP
2 *
3 * (c) 1995 Microsoft Corporation. All rights reserved.
4 * Developed by hip communications inc., http://info.hip.com/info/
5 * Portions (c) 1993 Intergraph Corporation. All rights reserved.
6 *
7 * You may distribute under the terms of either the GNU General Public
8 * License or the Artistic License, as specified in the README file.
9 */
0a753a76 10
390b85e7 11#define WIN32IO_IS_STDIO
55d25626 12#define WIN32SCK_IS_STDSCK
0a753a76 13#define WIN32_LEAN_AND_MEAN
8fada4f6 14#define PERLIO_NOT_STDIO 0
a835ef8a
NIS
15#ifdef __GNUC__
16#define Win32_Winsock
17#endif
390b85e7 18#include <windows.h>
0a753a76
PP
19#include "EXTERN.h"
20#include "perl.h"
c69f6586 21
58a50f62 22#include "Win32iop.h"
0a753a76
PP
23#include <sys/socket.h>
24#include <fcntl.h>
25#include <sys/stat.h>
26#include <assert.h>
390b85e7 27#include <io.h>
0a753a76 28
68dc0745 29/* thanks to Beverly Brown (beverly@datacube.com) */
326b05e3 30#ifdef USE_SOCKETS_AS_HANDLES
58a50f62 31# define OPEN_SOCKET(x) win32_open_osfhandle(x,O_RDWR|O_BINARY)
326b05e3 32# define TO_SOCKET(x) _get_osfhandle(x)
0a753a76 33#else
0a753a76
PP
34# define OPEN_SOCKET(x) (x)
35# define TO_SOCKET(x) (x)
68dc0745 36#endif /* USE_SOCKETS_AS_HANDLES */
0a753a76 37
3db8f154 38#if defined(USE_ITHREADS)
326b05e3
GS
39#define StartSockets() \
40 STMT_START { \
41 if (!wsock_started) \
42 start_sockets(); \
0401f841 43 set_socktype(); \
326b05e3 44 } STMT_END
401ef382
SN
45#else
46#define StartSockets() \
47 STMT_START { \
48 if (!wsock_started) { \
49 start_sockets(); \
50 set_socktype(); \
51 } \
52 } STMT_END
53#endif
326b05e3 54
326b05e3
GS
55#define SOCKET_TEST(x, y) \
56 STMT_START { \
57 StartSockets(); \
58 if((x) == (y)) \
59 errno = WSAGetLastError(); \
60 } STMT_END
61
62#define SOCKET_TEST_ERROR(x) SOCKET_TEST(x, SOCKET_ERROR)
63
137443ea
PP
64static struct servent* win32_savecopyservent(struct servent*d,
65 struct servent*s,
66 const char *proto);
0a753a76 67
326b05e3 68static int wsock_started = 0;
68dc0745 69
b73db59c
GS
70EXTERN_C void
71EndSockets(void)
72{
73 if (wsock_started)
74 WSACleanup();
75}
76
68dc0745 77void
326b05e3 78start_sockets(void)
68dc0745 79{
acfe0abc 80 dTHX;
68dc0745
PP
81 unsigned short version;
82 WSADATA retdata;
83 int ret;
68dc0745 84
68dc0745
PP
85 /*
86 * initalize the winsock interface and insure that it is
87 * cleaned up at exit.
88 */
89 version = 0x101;
326b05e3 90 if(ret = WSAStartup(version, &retdata))
4f63d024 91 Perl_croak_nocontext("Unable to locate winsock library!\n");
68dc0745 92 if(retdata.wVersion != version)
4f63d024 93 Perl_croak_nocontext("Could not find version 1.1 of winsock dll\n");
68dc0745
PP
94
95 /* atexit((void (*)(void)) EndSockets); */
401ef382
SN
96 wsock_started = 1;
97}
0a753a76 98
401ef382
SN
99void
100set_socktype(void)
101{
0a753a76 102#ifdef USE_SOCKETS_AS_HANDLES
3db8f154 103#if defined(USE_ITHREADS)
acfe0abc 104 dTHX;
3352bfcb 105 if (!w32_init_socktype) {
401ef382 106#endif
3352bfcb
GS
107 int iSockOpt = SO_SYNCHRONOUS_NONALERT;
108 /*
109 * Enable the use of sockets as filehandles
110 */
111 setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
112 (char *)&iSockOpt, sizeof(iSockOpt));
3db8f154 113#if defined(USE_ITHREADS)
3352bfcb 114 w32_init_socktype = 1;
401ef382
SN
115 }
116#endif
68dc0745 117#endif /* USE_SOCKETS_AS_HANDLES */
0a753a76
PP
118}
119
120
121#ifndef USE_SOCKETS_AS_HANDLES
f3986ebb 122#undef fdopen
68dc0745 123FILE *
f3986ebb 124my_fdopen(int fd, char *mode)
0a753a76 125{
68dc0745
PP
126 FILE *fp;
127 char sockbuf[256];
128 int optlen = sizeof(sockbuf);
129 int retval;
0a753a76 130
326b05e3 131 if (!wsock_started)
fb73857a 132 return(fdopen(fd, mode));
0a753a76 133
326b05e3
GS
134 retval = getsockopt((SOCKET)fd, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
135 if(retval == SOCKET_ERROR && WSAGetLastError() == WSAENOTSOCK) {
fb73857a 136 return(fdopen(fd, mode));
68dc0745 137 }
0a753a76 138
68dc0745
PP
139 /*
140 * If we get here, then fd is actually a socket.
141 */
4e945249 142 Newz(1310, fp, 1, FILE); /* XXX leak, good thing this code isn't used */
68dc0745
PP
143 if(fp == NULL) {
144 errno = ENOMEM;
145 return NULL;
146 }
0a753a76 147
68dc0745
PP
148 fp->_file = fd;
149 if(*mode == 'r')
150 fp->_flag = _IOREAD;
151 else
152 fp->_flag = _IOWRT;
153
154 return fp;
0a753a76 155}
68dc0745 156#endif /* USE_SOCKETS_AS_HANDLES */
0a753a76
PP
157
158
68dc0745
PP
159u_long
160win32_htonl(u_long hostlong)
0a753a76 161{
326b05e3
GS
162 StartSockets();
163 return htonl(hostlong);
0a753a76
PP
164}
165
68dc0745
PP
166u_short
167win32_htons(u_short hostshort)
0a753a76 168{
326b05e3
GS
169 StartSockets();
170 return htons(hostshort);
0a753a76
PP
171}
172
68dc0745
PP
173u_long
174win32_ntohl(u_long netlong)
0a753a76 175{
326b05e3
GS
176 StartSockets();
177 return ntohl(netlong);
0a753a76
PP
178}
179
68dc0745
PP
180u_short
181win32_ntohs(u_short netshort)
0a753a76 182{
326b05e3
GS
183 StartSockets();
184 return ntohs(netshort);
0a753a76
PP
185}
186
187
0a753a76 188
68dc0745
PP
189SOCKET
190win32_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
0a753a76 191{
68dc0745 192 SOCKET r;
0a753a76 193
326b05e3 194 SOCKET_TEST((r = accept(TO_SOCKET(s), addr, addrlen)), INVALID_SOCKET);
68dc0745 195 return OPEN_SOCKET(r);
0a753a76
PP
196}
197
68dc0745
PP
198int
199win32_bind(SOCKET s, const struct sockaddr *addr, int addrlen)
0a753a76 200{
68dc0745 201 int r;
0a753a76 202
326b05e3 203 SOCKET_TEST_ERROR(r = bind(TO_SOCKET(s), addr, addrlen));
68dc0745 204 return r;
0a753a76
PP
205}
206
68dc0745
PP
207int
208win32_connect(SOCKET s, const struct sockaddr *addr, int addrlen)
0a753a76 209{
68dc0745 210 int r;
0a753a76 211
326b05e3 212 SOCKET_TEST_ERROR(r = connect(TO_SOCKET(s), addr, addrlen));
68dc0745 213 return r;
0a753a76
PP
214}
215
216
68dc0745
PP
217int
218win32_getpeername(SOCKET s, struct sockaddr *addr, int *addrlen)
0a753a76 219{
68dc0745 220 int r;
0a753a76 221
326b05e3 222 SOCKET_TEST_ERROR(r = getpeername(TO_SOCKET(s), addr, addrlen));
68dc0745 223 return r;
0a753a76
PP
224}
225
68dc0745
PP
226int
227win32_getsockname(SOCKET s, struct sockaddr *addr, int *addrlen)
0a753a76 228{
68dc0745 229 int r;
0a753a76 230
326b05e3 231 SOCKET_TEST_ERROR(r = getsockname(TO_SOCKET(s), addr, addrlen));
68dc0745 232 return r;
0a753a76
PP
233}
234
68dc0745
PP
235int
236win32_getsockopt(SOCKET s, int level, int optname, char *optval, int *optlen)
0a753a76 237{
68dc0745 238 int r;
0a753a76 239
326b05e3 240 SOCKET_TEST_ERROR(r = getsockopt(TO_SOCKET(s), level, optname, optval, optlen));
68dc0745 241 return r;
0a753a76
PP
242}
243
2d7a9237 244int
68dc0745 245win32_ioctlsocket(SOCKET s, long cmd, u_long *argp)
0a753a76 246{
68dc0745 247 int r;
0a753a76 248
326b05e3 249 SOCKET_TEST_ERROR(r = ioctlsocket(TO_SOCKET(s), cmd, argp));
68dc0745 250 return r;
0a753a76
PP
251}
252
68dc0745
PP
253int
254win32_listen(SOCKET s, int backlog)
0a753a76 255{
68dc0745 256 int r;
0a753a76 257
326b05e3 258 SOCKET_TEST_ERROR(r = listen(TO_SOCKET(s), backlog));
68dc0745 259 return r;
0a753a76
PP
260}
261
68dc0745
PP
262int
263win32_recv(SOCKET s, char *buf, int len, int flags)
0a753a76 264{
68dc0745 265 int r;
0a753a76 266
326b05e3 267 SOCKET_TEST_ERROR(r = recv(TO_SOCKET(s), buf, len, flags));
68dc0745 268 return r;
0a753a76
PP
269}
270
68dc0745
PP
271int
272win32_recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, int *fromlen)
0a753a76 273{
68dc0745 274 int r;
e4449fe1 275 int frombufsize = *fromlen;
0a753a76 276
326b05e3 277 SOCKET_TEST_ERROR(r = recvfrom(TO_SOCKET(s), buf, len, flags, from, fromlen));
e4449fe1
GS
278 /* Winsock's recvfrom() only returns a valid 'from' when the socket
279 * is connectionless. Perl expects a valid 'from' for all types
280 * of sockets, so go the extra mile.
281 */
282 if (r != SOCKET_ERROR && frombufsize == *fromlen)
283 (void)win32_getpeername(s, from, fromlen);
68dc0745 284 return r;
0a753a76
PP
285}
286
68dc0745
PP
287/* select contributed by Vincent R. Slyngstad (vrs@ibeam.intel.com) */
288int
55d25626 289win32_select(int nfds, Perl_fd_set* rd, Perl_fd_set* wr, Perl_fd_set* ex, const struct timeval* timeout)
0a753a76 290{
55d25626
GS
291 int r;
292#ifdef USE_SOCKETS_AS_HANDLES
293 Perl_fd_set dummy;
3ead22cb 294 int i, fd, save_errno = errno;
55d25626 295 FD_SET nrd, nwr, nex, *prd, *pwr, *pex;
0a753a76 296
7e3be867
GS
297 /* winsock seems incapable of dealing with all three null fd_sets,
298 * so do the (millisecond) sleep as a special case
299 */
300 if (!(rd || wr || ex)) {
87c2f9c4
BZ
301 if (timeout)
302 Sleep(timeout->tv_sec * 1000 +
303 timeout->tv_usec / 1000); /* do the best we can */
304 else
305 Sleep(UINT_MAX);
7e3be867
GS
306 return 0;
307 }
f2bb5751 308 StartSockets();
55d25626 309 PERL_FD_ZERO(&dummy);
68dc0745
PP
310 if (!rd)
311 rd = &dummy, prd = NULL;
312 else
313 prd = &nrd;
314 if (!wr)
315 wr = &dummy, pwr = NULL;
316 else
317 pwr = &nwr;
318 if (!ex)
319 ex = &dummy, pex = NULL;
320 else
321 pex = &nex;
0a753a76 322
68dc0745
PP
323 FD_ZERO(&nrd);
324 FD_ZERO(&nwr);
325 FD_ZERO(&nex);
326 for (i = 0; i < nfds; i++) {
327 fd = TO_SOCKET(i);
55d25626 328 if (PERL_FD_ISSET(i,rd))
68dc0745 329 FD_SET(fd, &nrd);
55d25626 330 if (PERL_FD_ISSET(i,wr))
68dc0745 331 FD_SET(fd, &nwr);
55d25626 332 if (PERL_FD_ISSET(i,ex))
68dc0745
PP
333 FD_SET(fd, &nex);
334 }
335
1c878075 336 errno = save_errno;
326b05e3 337 SOCKET_TEST_ERROR(r = select(nfds, prd, pwr, pex, timeout));
1c878075 338 save_errno = errno;
0a753a76 339
68dc0745
PP
340 for (i = 0; i < nfds; i++) {
341 fd = TO_SOCKET(i);
55d25626
GS
342 if (PERL_FD_ISSET(i,rd) && !FD_ISSET(fd, &nrd))
343 PERL_FD_CLR(i,rd);
344 if (PERL_FD_ISSET(i,wr) && !FD_ISSET(fd, &nwr))
345 PERL_FD_CLR(i,wr);
346 if (PERL_FD_ISSET(i,ex) && !FD_ISSET(fd, &nex))
347 PERL_FD_CLR(i,ex);
68dc0745 348 }
1c878075 349 errno = save_errno;
55d25626
GS
350#else
351 SOCKET_TEST_ERROR(r = select(nfds, rd, wr, ex, timeout));
352#endif
68dc0745 353 return r;
0a753a76
PP
354}
355
68dc0745
PP
356int
357win32_send(SOCKET s, const char *buf, int len, int flags)
0a753a76 358{
68dc0745 359 int r;
0a753a76 360
326b05e3 361 SOCKET_TEST_ERROR(r = send(TO_SOCKET(s), buf, len, flags));
68dc0745 362 return r;
0a753a76
PP
363}
364
68dc0745
PP
365int
366win32_sendto(SOCKET s, const char *buf, int len, int flags,
367 const struct sockaddr *to, int tolen)
0a753a76 368{
68dc0745 369 int r;
0a753a76 370
326b05e3 371 SOCKET_TEST_ERROR(r = sendto(TO_SOCKET(s), buf, len, flags, to, tolen));
68dc0745 372 return r;
0a753a76
PP
373}
374
68dc0745
PP
375int
376win32_setsockopt(SOCKET s, int level, int optname, const char *optval, int optlen)
0a753a76 377{
68dc0745 378 int r;
0a753a76 379
326b05e3 380 SOCKET_TEST_ERROR(r = setsockopt(TO_SOCKET(s), level, optname, optval, optlen));
68dc0745 381 return r;
0a753a76
PP
382}
383
68dc0745
PP
384int
385win32_shutdown(SOCKET s, int how)
0a753a76 386{
68dc0745 387 int r;
0a753a76 388
326b05e3 389 SOCKET_TEST_ERROR(r = shutdown(TO_SOCKET(s), how));
68dc0745 390 return r;
0a753a76
PP
391}
392
3a25acb4
GS
393int
394win32_closesocket(SOCKET s)
395{
396 int r;
397
398 SOCKET_TEST_ERROR(r = closesocket(TO_SOCKET(s)));
399 return r;
400}
401
68dc0745
PP
402SOCKET
403win32_socket(int af, int type, int protocol)
0a753a76 404{
68dc0745 405 SOCKET s;
0a753a76
PP
406
407#ifndef USE_SOCKETS_AS_HANDLES
326b05e3 408 SOCKET_TEST(s = socket(af, type, protocol), INVALID_SOCKET);
0a753a76 409#else
3a25acb4 410 StartSockets();
326b05e3
GS
411 if((s = socket(af, type, protocol)) == INVALID_SOCKET)
412 errno = WSAGetLastError();
68dc0745
PP
413 else
414 s = OPEN_SOCKET(s);
415#endif /* USE_SOCKETS_AS_HANDLES */
0a753a76 416
68dc0745 417 return s;
0a753a76
PP
418}
419
00b02797
JH
420/*
421 * close RTL fd while respecting sockets
422 * added as temporary measure until PerlIO has real
423 * Win32 native layer
424 * -- BKS, 11-11-2000
425*/
426
427int my_close(int fd)
428{
429 int osf;
430 if (!wsock_started) /* No WinSock? */
431 return(close(fd)); /* Then not a socket. */
432 osf = TO_SOCKET(fd);/* Get it now before it's gone! */
433 if (osf != -1) {
434 int err;
435 err = closesocket(osf);
436 if (err == 0) {
437#if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
438 _set_osfhnd(fd, INVALID_HANDLE_VALUE);
439#endif
440 (void)close(fd); /* handle already closed, ignore error */
441 return 0;
442 }
443 else if (err == SOCKET_ERROR) {
444 err = WSAGetLastError();
445 if (err != WSAENOTSOCK) {
446 (void)close(fd);
447 errno = err;
448 return EOF;
449 }
450 }
451 }
452 return close(fd);
453}
454
fb73857a
PP
455#undef fclose
456int
457my_fclose (FILE *pf)
458{
4e945249 459 int osf;
326b05e3
GS
460 if (!wsock_started) /* No WinSock? */
461 return(fclose(pf)); /* Then not a socket. */
00b02797 462 osf = TO_SOCKET(win32_fileno(pf));/* Get it now before it's gone! */
d3d49e29
GS
463 if (osf != -1) {
464 int err;
465 win32_fflush(pf);
466 err = closesocket(osf);
467 if (err == 0) {
9114b071 468#if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
00b02797 469 _set_osfhnd(win32_fileno(pf), INVALID_HANDLE_VALUE);
9114b071 470#endif
d3d49e29
GS
471 (void)fclose(pf); /* handle already closed, ignore error */
472 return 0;
473 }
474 else if (err == SOCKET_ERROR) {
475 err = WSAGetLastError();
476 if (err != WSAENOTSOCK) {
477 (void)fclose(pf);
478 errno = err;
479 return EOF;
480 }
481 }
326b05e3 482 }
d3d49e29 483 return fclose(pf);
fb73857a
PP
484}
485
ed59ec62
GS
486#undef fstat
487int
c623ac67 488my_fstat(int fd, Stat_t *sbufptr)
ed59ec62
GS
489{
490 /* This fixes a bug in fstat() on Windows 9x. fstat() uses the
491 * GetFileType() win32 syscall, which will fail on Windows 9x.
492 * So if we recognize a socket on Windows 9x, we return the
493 * same results as on Windows NT/2000.
494 * XXX this should be extended further to set S_IFSOCK on
495 * sbufptr->st_mode.
496 */
497 int osf;
c623ac67
GS
498 if (!wsock_started || IsWinNT()) {
499#if defined(WIN64) || defined(USE_LARGE_FILES)
a810272a
NS
500#if defined(__BORLANDC__) /* buk */
501 return win32_fstat(fd, sbufptr );
502#else
c623ac67 503 return _fstati64(fd, sbufptr);
a810272a 504#endif
c623ac67 505#else
ed59ec62 506 return fstat(fd, sbufptr);
c623ac67
GS
507#endif
508 }
ed59ec62
GS
509
510 osf = TO_SOCKET(fd);
511 if (osf != -1) {
512 char sockbuf[256];
513 int optlen = sizeof(sockbuf);
514 int retval;
515
516 retval = getsockopt((SOCKET)osf, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
517 if (retval != SOCKET_ERROR || WSAGetLastError() != WSAENOTSOCK) {
24c02676
VK
518#if defined(__BORLANDC__)&&(__BORLANDC__<=0x520)
519 sbufptr->st_mode = S_IFIFO;
520#else
ed59ec62 521 sbufptr->st_mode = _S_IFIFO;
24c02676 522#endif
ed59ec62
GS
523 sbufptr->st_rdev = sbufptr->st_dev = (dev_t)fd;
524 sbufptr->st_nlink = 1;
525 sbufptr->st_uid = sbufptr->st_gid = sbufptr->st_ino = 0;
526 sbufptr->st_atime = sbufptr->st_mtime = sbufptr->st_ctime = 0;
c623ac67 527 sbufptr->st_size = (Off_t)0;
ed59ec62
GS
528 return 0;
529 }
530 }
c623ac67 531#if defined(WIN64) || defined(USE_LARGE_FILES)
a810272a
NS
532#if defined(__BORLANDC__) /* buk */
533 return win32_fstat(fd, sbufptr );
534#else
c623ac67 535 return _fstati64(fd, sbufptr);
a810272a 536#endif
c623ac67 537#else
ed59ec62 538 return fstat(fd, sbufptr);
c623ac67 539#endif
ed59ec62
GS
540}
541
68dc0745
PP
542struct hostent *
543win32_gethostbyaddr(const char *addr, int len, int type)
0a753a76 544{
68dc0745 545 struct hostent *r;
0a753a76 546
326b05e3 547 SOCKET_TEST(r = gethostbyaddr(addr, len, type), NULL);
68dc0745 548 return r;
0a753a76
PP
549}
550
68dc0745
PP
551struct hostent *
552win32_gethostbyname(const char *name)
0a753a76 553{
68dc0745 554 struct hostent *r;
0a753a76 555
326b05e3 556 SOCKET_TEST(r = gethostbyname(name), NULL);
68dc0745 557 return r;
0a753a76
PP
558}
559
68dc0745
PP
560int
561win32_gethostname(char *name, int len)
0a753a76 562{
68dc0745 563 int r;
0a753a76 564
326b05e3 565 SOCKET_TEST_ERROR(r = gethostname(name, len));
68dc0745 566 return r;
0a753a76
PP
567}
568
68dc0745
PP
569struct protoent *
570win32_getprotobyname(const char *name)
0a753a76 571{
68dc0745 572 struct protoent *r;
0a753a76 573
326b05e3 574 SOCKET_TEST(r = getprotobyname(name), NULL);
68dc0745 575 return r;
0a753a76
PP
576}
577
68dc0745
PP
578struct protoent *
579win32_getprotobynumber(int num)
0a753a76 580{
68dc0745 581 struct protoent *r;
0a753a76 582
326b05e3 583 SOCKET_TEST(r = getprotobynumber(num), NULL);
68dc0745 584 return r;
0a753a76
PP
585}
586
68dc0745
PP
587struct servent *
588win32_getservbyname(const char *name, const char *proto)
0a753a76 589{
acfe0abc 590 dTHX;
68dc0745 591 struct servent *r;
c53bd28a 592
326b05e3 593 SOCKET_TEST(r = getservbyname(name, proto), NULL);
68dc0745 594 if (r) {
3352bfcb 595 r = win32_savecopyservent(&w32_servent, r, proto);
68dc0745
PP
596 }
597 return r;
0a753a76
PP
598}
599
68dc0745
PP
600struct servent *
601win32_getservbyport(int port, const char *proto)
0a753a76 602{
acfe0abc 603 dTHX;
68dc0745 604 struct servent *r;
0a753a76 605
326b05e3 606 SOCKET_TEST(r = getservbyport(port, proto), NULL);
68dc0745 607 if (r) {
3352bfcb 608 r = win32_savecopyservent(&w32_servent, r, proto);
68dc0745
PP
609 }
610 return r;
0a753a76
PP
611}
612
f998180f
GS
613int
614win32_ioctl(int i, unsigned int u, char *data)
615{
acfe0abc 616 dTHX;
f998180f
GS
617 u_long argp = (u_long)data;
618 int retval;
619
620 if (!wsock_started) {
4f63d024 621 Perl_croak_nocontext("ioctl implemented only on sockets");
f998180f
GS
622 /* NOTREACHED */
623 }
624
625 retval = ioctlsocket(TO_SOCKET(i), (long)u, &argp);
626 if (retval == SOCKET_ERROR) {
627 if (WSAGetLastError() == WSAENOTSOCK) {
4f63d024 628 Perl_croak_nocontext("ioctl implemented only on sockets");
f998180f
GS
629 /* NOTREACHED */
630 }
631 errno = WSAGetLastError();
632 }
633 return retval;
634}
635
68dc0745
PP
636char FAR *
637win32_inet_ntoa(struct in_addr in)
0a753a76 638{
326b05e3
GS
639 StartSockets();
640 return inet_ntoa(in);
0a753a76
PP
641}
642
68dc0745
PP
643unsigned long
644win32_inet_addr(const char FAR *cp)
0a753a76 645{
326b05e3
GS
646 StartSockets();
647 return inet_addr(cp);
0a753a76 648}
68dc0745
PP
649
650/*
651 * Networking stubs
652 */
0a753a76 653
68dc0745
PP
654void
655win32_endhostent()
0a753a76 656{
acfe0abc 657 dTHX;
4f63d024 658 Perl_croak_nocontext("endhostent not implemented!\n");
0a753a76
PP
659}
660
68dc0745
PP
661void
662win32_endnetent()
0a753a76 663{
acfe0abc 664 dTHX;
4f63d024 665 Perl_croak_nocontext("endnetent not implemented!\n");
0a753a76
PP
666}
667
68dc0745
PP
668void
669win32_endprotoent()
0a753a76 670{
acfe0abc 671 dTHX;
4f63d024 672 Perl_croak_nocontext("endprotoent not implemented!\n");
0a753a76
PP
673}
674
68dc0745
PP
675void
676win32_endservent()
0a753a76 677{
acfe0abc 678 dTHX;
4f63d024 679 Perl_croak_nocontext("endservent not implemented!\n");
0a753a76
PP
680}
681
682
68dc0745
PP
683struct netent *
684win32_getnetent(void)
0a753a76 685{
acfe0abc 686 dTHX;
4f63d024 687 Perl_croak_nocontext("getnetent not implemented!\n");
68dc0745 688 return (struct netent *) NULL;
0a753a76
PP
689}
690
68dc0745
PP
691struct netent *
692win32_getnetbyname(char *name)
0a753a76 693{
acfe0abc 694 dTHX;
4f63d024 695 Perl_croak_nocontext("getnetbyname not implemented!\n");
68dc0745 696 return (struct netent *)NULL;
0a753a76
PP
697}
698
68dc0745
PP
699struct netent *
700win32_getnetbyaddr(long net, int type)
0a753a76 701{
acfe0abc 702 dTHX;
4f63d024 703 Perl_croak_nocontext("getnetbyaddr not implemented!\n");
68dc0745 704 return (struct netent *)NULL;
0a753a76
PP
705}
706
68dc0745
PP
707struct protoent *
708win32_getprotoent(void)
0a753a76 709{
acfe0abc 710 dTHX;
4f63d024 711 Perl_croak_nocontext("getprotoent not implemented!\n");
68dc0745 712 return (struct protoent *) NULL;
0a753a76
PP
713}
714
68dc0745
PP
715struct servent *
716win32_getservent(void)
0a753a76 717{
acfe0abc 718 dTHX;
4f63d024 719 Perl_croak_nocontext("getservent not implemented!\n");
68dc0745 720 return (struct servent *) NULL;
0a753a76
PP
721}
722
68dc0745
PP
723void
724win32_sethostent(int stayopen)
0a753a76 725{
acfe0abc 726 dTHX;
4f63d024 727 Perl_croak_nocontext("sethostent not implemented!\n");
0a753a76
PP
728}
729
730
68dc0745
PP
731void
732win32_setnetent(int stayopen)
0a753a76 733{
acfe0abc 734 dTHX;
4f63d024 735 Perl_croak_nocontext("setnetent not implemented!\n");
0a753a76
PP
736}
737
738
68dc0745
PP
739void
740win32_setprotoent(int stayopen)
0a753a76 741{
acfe0abc 742 dTHX;
4f63d024 743 Perl_croak_nocontext("setprotoent not implemented!\n");
0a753a76
PP
744}
745
746
68dc0745
PP
747void
748win32_setservent(int stayopen)
0a753a76 749{
acfe0abc 750 dTHX;
4f63d024 751 Perl_croak_nocontext("setservent not implemented!\n");
0a753a76
PP
752}
753
137443ea
PP
754static struct servent*
755win32_savecopyservent(struct servent*d, struct servent*s, const char *proto)
756{
757 d->s_name = s->s_name;
758 d->s_aliases = s->s_aliases;
759 d->s_port = s->s_port;
0af56dfe 760#ifndef __BORLANDC__ /* Buggy on Win95 and WinNT-with-Borland-WSOCK */
137443ea
PP
761 if (!IsWin95() && s->s_proto && strlen(s->s_proto))
762 d->s_proto = s->s_proto;
0af56dfe
GS
763 else
764#endif
c69f6586 765 if (proto && strlen(proto))
137443ea
PP
766 d->s_proto = (char *)proto;
767 else
768 d->s_proto = "tcp";
769
770 return d;
771}
772
0a753a76 773