Commit | Line | Data |
a0d0e21e |
1 | /* sockadapt.h |
2 | * |
3 | * Authors: Charles Bailey bailey@genetics.upenn.edu |
4 | * David Denholm denholm@conmat.phys.soton.ac.uk |
9607fc9c |
5 | * Last Revised: 4-Mar-1997 |
a0d0e21e |
6 | * |
7 | * This file should include any other header files and procide any |
8 | * declarations, typedefs, and prototypes needed by perl for TCP/IP |
9 | * operations. |
10 | * |
748a9306 |
11 | * This version is set up for perl5 with socketshr 0.9D TCP/IP support. |
a0d0e21e |
12 | */ |
13 | |
9607fc9c |
14 | #ifndef __SOCKADAPT_INCLUDED |
15 | #define __SOCKADAPT_INCLUDED 1 |
16 | |
17 | #if defined(DECCRTL_SOCKETS) |
18 | /* Use builtin socket interface in DECCRTL and |
19 | * UCX emulation in whatever TCP/IP stack is present. |
20 | * Provide prototypes for missing routines; stubs are |
21 | * in sockadapt.c. |
22 | */ |
23 | # include <socket.h> |
24 | # include <inet.h> |
25 | # include <in.h> |
26 | # include <netdb.h> |
27 | void sethostent(int); |
28 | void endhostent(void); |
29 | void setnetent(int); |
30 | void endnetent(void); |
31 | void setprotoent(int); |
32 | void endprotoent(void); |
33 | void setservent(int); |
34 | void endservent(void); |
35 | |
36 | #else |
37 | /* Pull in SOCKETSHR's header, and set up structures for |
38 | * gcc, whose basic header file set doesn't include the |
39 | * TCP/IP stuff. |
40 | */ |
4633a7c4 |
41 | |
42 | |
43 | #ifdef __GNU_CC__ |
a0d0e21e |
44 | |
748a9306 |
45 | /* we may not have netdb.h etc, so lets just do this here - div */ |
a0d0e21e |
46 | /* no harm doing this for all .c files - needed only by pp_sys.c */ |
47 | |
748a9306 |
48 | struct hostent { |
49 | char *h_name; /* official name of host */ |
50 | char **h_aliases; /* alias list */ |
51 | int h_addrtype; /* host address type */ |
52 | int h_length; /* length of address */ |
53 | char **h_addr_list; /* address */ |
a0d0e21e |
54 | }; |
748a9306 |
55 | #ifdef h_addr |
56 | # undef h_addr |
57 | #endif |
a0d0e21e |
58 | #define h_addr h_addr_list[0] |
59 | |
748a9306 |
60 | struct protoent { |
61 | char *p_name; /* official protocol name */ |
62 | char **p_aliases; /* alias list */ |
63 | int p_proto; /* protocol # */ |
64 | }; |
65 | |
66 | struct servent { |
67 | char *s_name; /* official service name */ |
68 | char **s_aliases; /* alias list */ |
69 | int s_port; /* port # */ |
70 | char *s_proto; /* protocol to use */ |
71 | }; |
72 | |
73 | struct in_addr { |
74 | unsigned long s_addr; |
75 | }; |
76 | |
77 | struct sockaddr { |
78 | unsigned short sa_family; /* address family */ |
79 | char sa_data[14]; /* up to 14 bytes of direct address */ |
80 | }; |
81 | |
4633a7c4 |
82 | /* |
83 | * Socket address, internet style. |
84 | */ |
85 | struct sockaddr_in { |
86 | short sin_family; |
87 | unsigned short sin_port; |
88 | struct in_addr sin_addr; |
89 | char sin_zero[8]; |
90 | }; |
91 | |
748a9306 |
92 | struct timeval { |
93 | long tv_sec; |
94 | long tv_usec; |
a0d0e21e |
95 | }; |
96 | |
97 | struct netent { |
98 | char *n_name; |
99 | char **n_aliases; |
100 | int n_addrtype; |
101 | long n_net; |
102 | }; |
4633a7c4 |
103 | |
104 | /* Since socketshr.h won't declare function prototypes unless it thinks |
105 | * the system headers have already been included, we convince it that |
106 | * this is the case. |
107 | */ |
108 | |
109 | #ifndef AF_INET |
110 | # define AF_INET 2 |
111 | #endif |
112 | #ifndef IPPROTO_TCP |
113 | # define IPPROTO_TCP 6 |
114 | #endif |
115 | #ifndef __INET_LOADED |
116 | # define __INET_LOADED |
117 | #endif |
118 | #ifndef __NETDB_LOADED |
119 | # define __NETDB_LOADED |
120 | #endif |
121 | |
122 | /* Finally, we provide prototypes for routines not supported by SocketShr, |
123 | * so that the stubs in sockadapt.c won't cause complaints about |
124 | * undeclared routines. |
125 | */ |
126 | |
127 | struct netent *getnetbyaddr( long net, int type); |
128 | struct netent *getnetbyname( char *name); |
129 | struct netent *getnetent(); |
9607fc9c |
130 | void setnetent(int); |
4633a7c4 |
131 | void endnetent(); |
132 | |
133 | #else /* !__GNU_CC__ */ |
134 | |
135 | /* DECC and VAXC have socket headers in the system set; they're for UCX, but |
136 | * we'll assume that the actual calling sequence is identical across the |
137 | * various TCP/IP stacks; these routines are pretty standard. |
138 | */ |
139 | #include <socket.h> |
140 | #include <in.h> |
141 | #include <inet.h> |
142 | #include <netdb.h> |
4633a7c4 |
143 | |
9607fc9c |
144 | /* SocketShr doesn't support these routines, but the DECC RTL contains |
145 | * stubs with these names, designed to be used with the UCX socket |
146 | * library. We avoid linker collisions by substituting new names. |
147 | */ |
148 | #define getnetbyaddr no_getnetbyaddr |
149 | #define getnetbyname no_getnetbyname |
150 | #define getnetent no_getnetent |
151 | #define setnetent no_setnetent |
152 | #define endnetent no_endnetent |
4633a7c4 |
153 | #endif |
154 | |
2ae324a7 |
155 | /* We don't have these two in the system headers. */ |
156 | void setnetent(int); |
157 | void endnetent(); |
158 | |
4633a7c4 |
159 | #include <socketshr.h> |
9607fc9c |
160 | /* socketshr.h from SocketShr 0.9D doesn't alias fileno; its comments say |
4633a7c4 |
161 | * that the CRTL version works OK. This isn't the case, at least with |
162 | * VAXC, so we use the SocketShr version. |
163 | * N.B. This means that sockadapt.h must be included *after* stdio.h. |
164 | * This is presently the case for Perl. |
165 | */ |
166 | #ifdef fileno |
167 | # undef fileno |
168 | #endif |
169 | #define fileno si_fileno |
170 | int si_fileno(FILE *); |
84753aa1 |
171 | |
172 | |
173 | /* Catch erroneous results for UDP sockets -- see sockadapt.c */ |
174 | #ifdef getpeername |
175 | # undef getpeername |
176 | #endif |
177 | #define getpeername my_getpeername |
178 | int my_getpeername _((int, struct sockaddr *, int *)); |
9607fc9c |
179 | |
180 | #endif /* SOCKETSHR stuff */ |
181 | #endif /* include guard */ |