This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[inseparable changes from patch from perl5.003_25 to perl5.003_26]
[perl5.git] / vms / sockadapt.c
1 /*  sockadapt.c
2  *
3  *  Author: Charles Bailey  bailey@genetics.upenn.edu
4  *  Last Revised: 29-Jan-1996
5  *
6  *  This file should contain stubs for any of the TCP/IP functions perl5
7  *  requires which are not supported by your TCP/IP stack.  These stubs
8  *  can attempt to emulate the routine in question, or can just return
9  *  an error status or cause perl to die.
10  *
11  *  This version is set up for perl5 with socketshr 0.9D TCP/IP support.
12  */
13
14 #include "EXTERN.h"
15 #include "perl.h"
16 #if defined(__DECC) && defined(__DECC_VER) && (__DECC_VER >= 50200000)
17 #  define __sockadapt_my_netent_t __struct_netent_ptr32
18 #  define __sockadapt_my_addr_t   __in_addr_t
19 #  define __sockadapt_my_name_t   const char *
20 #else
21 #  define __sockadapt_my_netent_t struct netent *
22 #  define __sockadapt_my_addr_t   long
23 #  define __sockadapt_my_name_t   char *
24 #endif
25
26 __sockadapt_my_netent_t getnetbyaddr( __sockadapt_my_addr_t net, int type) {
27   croak("Function \"getnetbyaddr\" not implemented in this version of perl");
28   return (struct netent *)NULL; /* Avoid MISSINGRETURN warning, not reached */
29 }
30 __sockadapt_my_netent_t getnetbyname( __sockadapt_my_name_t name) {
31   croak("Function \"getnetbyname\" not implemented in this version of perl");
32   return (struct netent *)NULL; /* Avoid MISSINGRETURN warning, not reached */
33 }
34 __sockadapt_my_netent_t getnetent() {
35   croak("Function \"getnetent\" not implemented in this version of perl");
36   return (struct netent *)NULL; /* Avoid MISSINGRETURN warning, not reached */
37 }
38 void setnetent() {
39   croak("Function \"setnetent\" not implemented in this version of perl");
40 }
41 void endnetent() {
42   croak("Function \"endnetent\" not implemented in this version of perl");
43 }
44
45 /* Some TCP/IP implementations seem to return success, when getpeername()
46  * is called on a UDP socket, but the port and in_addr are all zeroes.
47  */
48
49 int my_getpeername(int sock, struct sockaddr *addr, int *addrlen) {
50   static char nowhere[] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
51   int rslt;
52
53   rslt = si_getpeername(sock, addr, addrlen);
54
55   /* Just pass an error back up the line */
56   if (rslt) return rslt;
57
58   /* If the call succeeded, make sure we don't have a zeroed port/addr */
59   if (addr->sa_family == AF_INET &&
60       !memcmp((char *)addr + sizeof(u_short), nowhere,
61               sizeof(u_short) + sizeof(struct in_addr))) {
62     rslt = -1;
63     SETERRNO(ENOTCONN,SS$_CLEARED);
64   }
65   return rslt;
66 }