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