This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Nicholas Clark's podulator. The win32 makefile
[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 21
58a50f62 22#include "Win32iop.h"
0a753a76 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 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 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 81 unsigned short version;
82 WSADATA retdata;
83 int ret;
68dc0745 84
68dc0745 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 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 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 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 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 143 if(fp == NULL) {
144 errno = ENOMEM;
145 return NULL;
146 }
0a753a76 147
68dc0745 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 157
158
68dc0745 159u_long
160win32_htonl(u_long hostlong)
0a753a76 161{
326b05e3
GS
162 StartSockets();
163 return htonl(hostlong);
0a753a76 164}
165
68dc0745 166u_short
167win32_htons(u_short hostshort)
0a753a76 168{
326b05e3
GS
169 StartSockets();
170 return htons(hostshort);
0a753a76 171}
172
68dc0745 173u_long
174win32_ntohl(u_long netlong)
0a753a76 175{
326b05e3
GS
176 StartSockets();
177 return ntohl(netlong);
0a753a76 178}
179
68dc0745 180u_short
181win32_ntohs(u_short netshort)
0a753a76 182{
326b05e3
GS
183 StartSockets();
184 return ntohs(netshort);
0a753a76 185}
186
187
0a753a76 188
68dc0745 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 196}
197
68dc0745 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 205}
206
68dc0745 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 214}
215
216
68dc0745 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 224}
225
68dc0745 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 233}
234
68dc0745 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 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 251}
252
68dc0745 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 260}
261
68dc0745 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 269}
270
68dc0745 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 285}
286
68dc0745 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 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 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 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 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 354}
355
68dc0745 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 363}
364
68dc0745 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 373}
374
68dc0745 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 382}
383
68dc0745 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 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 402SOCKET
403win32_socket(int af, int type, int protocol)
0a753a76 404{
68dc0745 405 SOCKET s;
0a753a76 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 413 else
414 s = OPEN_SOCKET(s);
415#endif /* USE_SOCKETS_AS_HANDLES */
0a753a76 416
68dc0745 417 return s;
0a753a76 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 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 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)
500 return _fstati64(fd, sbufptr);
501#else
ed59ec62 502 return fstat(fd, sbufptr);
c623ac67
GS
503#endif
504 }
ed59ec62
GS
505
506 osf = TO_SOCKET(fd);
507 if (osf != -1) {
508 char sockbuf[256];
509 int optlen = sizeof(sockbuf);
510 int retval;
511
512 retval = getsockopt((SOCKET)osf, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
513 if (retval != SOCKET_ERROR || WSAGetLastError() != WSAENOTSOCK) {
24c02676
VK
514#if defined(__BORLANDC__)&&(__BORLANDC__<=0x520)
515 sbufptr->st_mode = S_IFIFO;
516#else
ed59ec62 517 sbufptr->st_mode = _S_IFIFO;
24c02676 518#endif
ed59ec62
GS
519 sbufptr->st_rdev = sbufptr->st_dev = (dev_t)fd;
520 sbufptr->st_nlink = 1;
521 sbufptr->st_uid = sbufptr->st_gid = sbufptr->st_ino = 0;
522 sbufptr->st_atime = sbufptr->st_mtime = sbufptr->st_ctime = 0;
c623ac67 523 sbufptr->st_size = (Off_t)0;
ed59ec62
GS
524 return 0;
525 }
526 }
c623ac67
GS
527#if defined(WIN64) || defined(USE_LARGE_FILES)
528 return _fstati64(fd, sbufptr);
529#else
ed59ec62 530 return fstat(fd, sbufptr);
c623ac67 531#endif
ed59ec62
GS
532}
533
68dc0745 534struct hostent *
535win32_gethostbyaddr(const char *addr, int len, int type)
0a753a76 536{
68dc0745 537 struct hostent *r;
0a753a76 538
326b05e3 539 SOCKET_TEST(r = gethostbyaddr(addr, len, type), NULL);
68dc0745 540 return r;
0a753a76 541}
542
68dc0745 543struct hostent *
544win32_gethostbyname(const char *name)
0a753a76 545{
68dc0745 546 struct hostent *r;
0a753a76 547
326b05e3 548 SOCKET_TEST(r = gethostbyname(name), NULL);
68dc0745 549 return r;
0a753a76 550}
551
68dc0745 552int
553win32_gethostname(char *name, int len)
0a753a76 554{
68dc0745 555 int r;
0a753a76 556
326b05e3 557 SOCKET_TEST_ERROR(r = gethostname(name, len));
68dc0745 558 return r;
0a753a76 559}
560
68dc0745 561struct protoent *
562win32_getprotobyname(const char *name)
0a753a76 563{
68dc0745 564 struct protoent *r;
0a753a76 565
326b05e3 566 SOCKET_TEST(r = getprotobyname(name), NULL);
68dc0745 567 return r;
0a753a76 568}
569
68dc0745 570struct protoent *
571win32_getprotobynumber(int num)
0a753a76 572{
68dc0745 573 struct protoent *r;
0a753a76 574
326b05e3 575 SOCKET_TEST(r = getprotobynumber(num), NULL);
68dc0745 576 return r;
0a753a76 577}
578
68dc0745 579struct servent *
580win32_getservbyname(const char *name, const char *proto)
0a753a76 581{
acfe0abc 582 dTHX;
68dc0745 583 struct servent *r;
c53bd28a 584
326b05e3 585 SOCKET_TEST(r = getservbyname(name, proto), NULL);
68dc0745 586 if (r) {
3352bfcb 587 r = win32_savecopyservent(&w32_servent, r, proto);
68dc0745 588 }
589 return r;
0a753a76 590}
591
68dc0745 592struct servent *
593win32_getservbyport(int port, const char *proto)
0a753a76 594{
acfe0abc 595 dTHX;
68dc0745 596 struct servent *r;
0a753a76 597
326b05e3 598 SOCKET_TEST(r = getservbyport(port, proto), NULL);
68dc0745 599 if (r) {
3352bfcb 600 r = win32_savecopyservent(&w32_servent, r, proto);
68dc0745 601 }
602 return r;
0a753a76 603}
604
f998180f
GS
605int
606win32_ioctl(int i, unsigned int u, char *data)
607{
acfe0abc 608 dTHX;
f998180f
GS
609 u_long argp = (u_long)data;
610 int retval;
611
612 if (!wsock_started) {
4f63d024 613 Perl_croak_nocontext("ioctl implemented only on sockets");
f998180f
GS
614 /* NOTREACHED */
615 }
616
617 retval = ioctlsocket(TO_SOCKET(i), (long)u, &argp);
618 if (retval == SOCKET_ERROR) {
619 if (WSAGetLastError() == WSAENOTSOCK) {
4f63d024 620 Perl_croak_nocontext("ioctl implemented only on sockets");
f998180f
GS
621 /* NOTREACHED */
622 }
623 errno = WSAGetLastError();
624 }
625 return retval;
626}
627
68dc0745 628char FAR *
629win32_inet_ntoa(struct in_addr in)
0a753a76 630{
326b05e3
GS
631 StartSockets();
632 return inet_ntoa(in);
0a753a76 633}
634
68dc0745 635unsigned long
636win32_inet_addr(const char FAR *cp)
0a753a76 637{
326b05e3
GS
638 StartSockets();
639 return inet_addr(cp);
0a753a76 640}
68dc0745 641
642/*
643 * Networking stubs
644 */
0a753a76 645
68dc0745 646void
647win32_endhostent()
0a753a76 648{
acfe0abc 649 dTHX;
4f63d024 650 Perl_croak_nocontext("endhostent not implemented!\n");
0a753a76 651}
652
68dc0745 653void
654win32_endnetent()
0a753a76 655{
acfe0abc 656 dTHX;
4f63d024 657 Perl_croak_nocontext("endnetent not implemented!\n");
0a753a76 658}
659
68dc0745 660void
661win32_endprotoent()
0a753a76 662{
acfe0abc 663 dTHX;
4f63d024 664 Perl_croak_nocontext("endprotoent not implemented!\n");
0a753a76 665}
666
68dc0745 667void
668win32_endservent()
0a753a76 669{
acfe0abc 670 dTHX;
4f63d024 671 Perl_croak_nocontext("endservent not implemented!\n");
0a753a76 672}
673
674
68dc0745 675struct netent *
676win32_getnetent(void)
0a753a76 677{
acfe0abc 678 dTHX;
4f63d024 679 Perl_croak_nocontext("getnetent not implemented!\n");
68dc0745 680 return (struct netent *) NULL;
0a753a76 681}
682
68dc0745 683struct netent *
684win32_getnetbyname(char *name)
0a753a76 685{
acfe0abc 686 dTHX;
4f63d024 687 Perl_croak_nocontext("getnetbyname not implemented!\n");
68dc0745 688 return (struct netent *)NULL;
0a753a76 689}
690
68dc0745 691struct netent *
692win32_getnetbyaddr(long net, int type)
0a753a76 693{
acfe0abc 694 dTHX;
4f63d024 695 Perl_croak_nocontext("getnetbyaddr not implemented!\n");
68dc0745 696 return (struct netent *)NULL;
0a753a76 697}
698
68dc0745 699struct protoent *
700win32_getprotoent(void)
0a753a76 701{
acfe0abc 702 dTHX;
4f63d024 703 Perl_croak_nocontext("getprotoent not implemented!\n");
68dc0745 704 return (struct protoent *) NULL;
0a753a76 705}
706
68dc0745 707struct servent *
708win32_getservent(void)
0a753a76 709{
acfe0abc 710 dTHX;
4f63d024 711 Perl_croak_nocontext("getservent not implemented!\n");
68dc0745 712 return (struct servent *) NULL;
0a753a76 713}
714
68dc0745 715void
716win32_sethostent(int stayopen)
0a753a76 717{
acfe0abc 718 dTHX;
4f63d024 719 Perl_croak_nocontext("sethostent not implemented!\n");
0a753a76 720}
721
722
68dc0745 723void
724win32_setnetent(int stayopen)
0a753a76 725{
acfe0abc 726 dTHX;
4f63d024 727 Perl_croak_nocontext("setnetent not implemented!\n");
0a753a76 728}
729
730
68dc0745 731void
732win32_setprotoent(int stayopen)
0a753a76 733{
acfe0abc 734 dTHX;
4f63d024 735 Perl_croak_nocontext("setprotoent not implemented!\n");
0a753a76 736}
737
738
68dc0745 739void
740win32_setservent(int stayopen)
0a753a76 741{
acfe0abc 742 dTHX;
4f63d024 743 Perl_croak_nocontext("setservent not implemented!\n");
0a753a76 744}
745
137443ea 746static struct servent*
747win32_savecopyservent(struct servent*d, struct servent*s, const char *proto)
748{
749 d->s_name = s->s_name;
750 d->s_aliases = s->s_aliases;
751 d->s_port = s->s_port;
0af56dfe 752#ifndef __BORLANDC__ /* Buggy on Win95 and WinNT-with-Borland-WSOCK */
137443ea 753 if (!IsWin95() && s->s_proto && strlen(s->s_proto))
754 d->s_proto = s->s_proto;
0af56dfe
GS
755 else
756#endif
c69f6586 757 if (proto && strlen(proto))
137443ea 758 d->s_proto = (char *)proto;
759 else
760 d->s_proto = "tcp";
761
762 return d;
763}
764
0a753a76 765