This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: ebcdic <-> ascii tables interjected in uv <-> utf8 considered harmful
[perl5.git] / win32 / win32sck.c
CommitLineData
326b05e3 1/* win32sck.c
68dc0745 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 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 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 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 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 86 unsigned short version;
87 WSADATA retdata;
88 int ret;
68dc0745 89
68dc0745 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 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 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 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 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 148 if(fp == NULL) {
149 errno = ENOMEM;
150 return NULL;
151 }
0a753a76 152
68dc0745 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 162
163
68dc0745 164u_long
165win32_htonl(u_long hostlong)
0a753a76 166{
326b05e3
GS
167 StartSockets();
168 return htonl(hostlong);
0a753a76 169}
170
68dc0745 171u_short
172win32_htons(u_short hostshort)
0a753a76 173{
326b05e3
GS
174 StartSockets();
175 return htons(hostshort);
0a753a76 176}
177
68dc0745 178u_long
179win32_ntohl(u_long netlong)
0a753a76 180{
326b05e3
GS
181 StartSockets();
182 return ntohl(netlong);
0a753a76 183}
184
68dc0745 185u_short
186win32_ntohs(u_short netshort)
0a753a76 187{
326b05e3
GS
188 StartSockets();
189 return ntohs(netshort);
0a753a76 190}
191
192
0a753a76 193
68dc0745 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 201}
202
68dc0745 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 210}
211
68dc0745 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 219}
220
221
68dc0745 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 229}
230
68dc0745 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 238}
239
68dc0745 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 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 256}
257
68dc0745 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 265}
266
68dc0745 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 274}
275
68dc0745 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 290}
291
68dc0745 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 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 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 338 FD_SET(fd, &nex);
339 }
340
326b05e3 341 SOCKET_TEST_ERROR(r = select(nfds, prd, pwr, pex, timeout));
0a753a76 342
68dc0745 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 356}
357
68dc0745 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 365}
366
68dc0745 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 375}
376
68dc0745 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 384}
385
68dc0745 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 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 404SOCKET
405win32_socket(int af, int type, int protocol)
0a753a76 406{
68dc0745 407 SOCKET s;
0a753a76 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 415 else
416 s = OPEN_SOCKET(s);
417#endif /* USE_SOCKETS_AS_HANDLES */
0a753a76 418
68dc0745 419 return s;
0a753a76 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 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 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) {
511 sbufptr->st_mode = _S_IFIFO;
512 sbufptr->st_rdev = sbufptr->st_dev = (dev_t)fd;
513 sbufptr->st_nlink = 1;
514 sbufptr->st_uid = sbufptr->st_gid = sbufptr->st_ino = 0;
515 sbufptr->st_atime = sbufptr->st_mtime = sbufptr->st_ctime = 0;
516 sbufptr->st_size = (off_t)0;
517 return 0;
518 }
519 }
520 return fstat(fd, sbufptr);
521}
522
68dc0745 523struct hostent *
524win32_gethostbyaddr(const char *addr, int len, int type)
0a753a76 525{
68dc0745 526 struct hostent *r;
0a753a76 527
326b05e3 528 SOCKET_TEST(r = gethostbyaddr(addr, len, type), NULL);
68dc0745 529 return r;
0a753a76 530}
531
68dc0745 532struct hostent *
533win32_gethostbyname(const char *name)
0a753a76 534{
68dc0745 535 struct hostent *r;
0a753a76 536
326b05e3 537 SOCKET_TEST(r = gethostbyname(name), NULL);
68dc0745 538 return r;
0a753a76 539}
540
68dc0745 541int
542win32_gethostname(char *name, int len)
0a753a76 543{
68dc0745 544 int r;
0a753a76 545
326b05e3 546 SOCKET_TEST_ERROR(r = gethostname(name, len));
68dc0745 547 return r;
0a753a76 548}
549
68dc0745 550struct protoent *
551win32_getprotobyname(const char *name)
0a753a76 552{
68dc0745 553 struct protoent *r;
0a753a76 554
326b05e3 555 SOCKET_TEST(r = getprotobyname(name), NULL);
68dc0745 556 return r;
0a753a76 557}
558
68dc0745 559struct protoent *
560win32_getprotobynumber(int num)
0a753a76 561{
68dc0745 562 struct protoent *r;
0a753a76 563
326b05e3 564 SOCKET_TEST(r = getprotobynumber(num), NULL);
68dc0745 565 return r;
0a753a76 566}
567
68dc0745 568struct servent *
569win32_getservbyname(const char *name, const char *proto)
0a753a76 570{
c5be433b 571 dTHXo;
68dc0745 572 struct servent *r;
c53bd28a 573
326b05e3 574 SOCKET_TEST(r = getservbyname(name, proto), NULL);
68dc0745 575 if (r) {
3352bfcb 576 r = win32_savecopyservent(&w32_servent, r, proto);
68dc0745 577 }
578 return r;
0a753a76 579}
580
68dc0745 581struct servent *
582win32_getservbyport(int port, const char *proto)
0a753a76 583{
c5be433b 584 dTHXo;
68dc0745 585 struct servent *r;
0a753a76 586
326b05e3 587 SOCKET_TEST(r = getservbyport(port, proto), NULL);
68dc0745 588 if (r) {
3352bfcb 589 r = win32_savecopyservent(&w32_servent, r, proto);
68dc0745 590 }
591 return r;
0a753a76 592}
593
f998180f
GS
594int
595win32_ioctl(int i, unsigned int u, char *data)
596{
c5be433b 597 dTHXo;
f998180f
GS
598 u_long argp = (u_long)data;
599 int retval;
600
601 if (!wsock_started) {
4f63d024 602 Perl_croak_nocontext("ioctl implemented only on sockets");
f998180f
GS
603 /* NOTREACHED */
604 }
605
606 retval = ioctlsocket(TO_SOCKET(i), (long)u, &argp);
607 if (retval == SOCKET_ERROR) {
608 if (WSAGetLastError() == WSAENOTSOCK) {
4f63d024 609 Perl_croak_nocontext("ioctl implemented only on sockets");
f998180f
GS
610 /* NOTREACHED */
611 }
612 errno = WSAGetLastError();
613 }
614 return retval;
615}
616
68dc0745 617char FAR *
618win32_inet_ntoa(struct in_addr in)
0a753a76 619{
326b05e3
GS
620 StartSockets();
621 return inet_ntoa(in);
0a753a76 622}
623
68dc0745 624unsigned long
625win32_inet_addr(const char FAR *cp)
0a753a76 626{
326b05e3
GS
627 StartSockets();
628 return inet_addr(cp);
0a753a76 629}
68dc0745 630
631/*
632 * Networking stubs
633 */
0a753a76 634
68dc0745 635void
636win32_endhostent()
0a753a76 637{
c5be433b 638 dTHXo;
4f63d024 639 Perl_croak_nocontext("endhostent not implemented!\n");
0a753a76 640}
641
68dc0745 642void
643win32_endnetent()
0a753a76 644{
c5be433b 645 dTHXo;
4f63d024 646 Perl_croak_nocontext("endnetent not implemented!\n");
0a753a76 647}
648
68dc0745 649void
650win32_endprotoent()
0a753a76 651{
c5be433b 652 dTHXo;
4f63d024 653 Perl_croak_nocontext("endprotoent not implemented!\n");
0a753a76 654}
655
68dc0745 656void
657win32_endservent()
0a753a76 658{
c5be433b 659 dTHXo;
4f63d024 660 Perl_croak_nocontext("endservent not implemented!\n");
0a753a76 661}
662
663
68dc0745 664struct netent *
665win32_getnetent(void)
0a753a76 666{
c5be433b 667 dTHXo;
4f63d024 668 Perl_croak_nocontext("getnetent not implemented!\n");
68dc0745 669 return (struct netent *) NULL;
0a753a76 670}
671
68dc0745 672struct netent *
673win32_getnetbyname(char *name)
0a753a76 674{
c5be433b 675 dTHXo;
4f63d024 676 Perl_croak_nocontext("getnetbyname not implemented!\n");
68dc0745 677 return (struct netent *)NULL;
0a753a76 678}
679
68dc0745 680struct netent *
681win32_getnetbyaddr(long net, int type)
0a753a76 682{
c5be433b 683 dTHXo;
4f63d024 684 Perl_croak_nocontext("getnetbyaddr not implemented!\n");
68dc0745 685 return (struct netent *)NULL;
0a753a76 686}
687
68dc0745 688struct protoent *
689win32_getprotoent(void)
0a753a76 690{
c5be433b 691 dTHXo;
4f63d024 692 Perl_croak_nocontext("getprotoent not implemented!\n");
68dc0745 693 return (struct protoent *) NULL;
0a753a76 694}
695
68dc0745 696struct servent *
697win32_getservent(void)
0a753a76 698{
c5be433b 699 dTHXo;
4f63d024 700 Perl_croak_nocontext("getservent not implemented!\n");
68dc0745 701 return (struct servent *) NULL;
0a753a76 702}
703
68dc0745 704void
705win32_sethostent(int stayopen)
0a753a76 706{
c5be433b 707 dTHXo;
4f63d024 708 Perl_croak_nocontext("sethostent not implemented!\n");
0a753a76 709}
710
711
68dc0745 712void
713win32_setnetent(int stayopen)
0a753a76 714{
c5be433b 715 dTHXo;
4f63d024 716 Perl_croak_nocontext("setnetent not implemented!\n");
0a753a76 717}
718
719
68dc0745 720void
721win32_setprotoent(int stayopen)
0a753a76 722{
c5be433b 723 dTHXo;
4f63d024 724 Perl_croak_nocontext("setprotoent not implemented!\n");
0a753a76 725}
726
727
68dc0745 728void
729win32_setservent(int stayopen)
0a753a76 730{
c5be433b 731 dTHXo;
4f63d024 732 Perl_croak_nocontext("setservent not implemented!\n");
0a753a76 733}
734
137443ea 735static struct servent*
736win32_savecopyservent(struct servent*d, struct servent*s, const char *proto)
737{
738 d->s_name = s->s_name;
739 d->s_aliases = s->s_aliases;
740 d->s_port = s->s_port;
0af56dfe 741#ifndef __BORLANDC__ /* Buggy on Win95 and WinNT-with-Borland-WSOCK */
137443ea 742 if (!IsWin95() && s->s_proto && strlen(s->s_proto))
743 d->s_proto = s->s_proto;
0af56dfe
GS
744 else
745#endif
c69f6586 746 if (proto && strlen(proto))
137443ea 747 d->s_proto = (char *)proto;
748 else
749 d->s_proto = "tcp";
750
751 return d;
752}
753
0a753a76 754