Works a bit more
[erwise] / Cl / WWWLibrary / tcp.h
1 /*      System-system differences for TCP include files and macros     tcp.h
2 **      ===========================================================
3 **
4 **
5 **      This file includes for each system, the files necessary for
6 **      network and file I/O
7 **
8 ** Authors
9 **      TBL     Tim Berners-Lee, W3 project, CERN, <timbl@info.cern.ch>
10 **      EvA     Eelco van Asperen <evas@cs.few.eur.nl>
11 **
12 **  History:
13 **      22 Feb 91       Written (TBL) as part of the WWW project.
14 **      16 Jan 92       PC code from EvA
15 */
16 #ifndef TCP_H
17 #define TCP_H
18
19 #define NETCLOSE close      /* Routine to close a TCP-IP socket         */
20 #define NETREAD  read       /* Routine to read from a TCP-IP socket     */
21 #define NETWRITE write      /* Routine to write to a TCP-IP socket      */
22
23
24 /*      Macintosh - Think-C
25 **      -------------------
26 **
27 **      Think-C is one development environment on the Mac.
28 **
29 **      We recommend that you compile with 4-byte ints to be compatible
30 **      with MPW C.  We used Tom Milligan's s_socket library which was
31 **      written for 4 byte int, and the MacTCP library assumes 4-byte int.
32 */
33 #ifdef THINK_C
34 #define DEBUG                   /* Can't put it on the CC command line  */
35 #define NO_UNIX_IO              /* getuid() missing                     */
36 #define NO_GETPID               /* getpid() does not exist              */
37 #define NO_GETWD                /* getwd() does not exist               */
38
39 #undef NETCLOSE             /* Routine to close a TCP-IP socket         */
40 #undef NETREAD              /* Routine to read from a TCP-IP socket     */
41 #undef NETWRITE             /* Routine to write to a TCP-IP socket      */
42 #define NETCLOSE s_close    /* Routine to close a TCP-IP socket         */
43 #define NETREAD  s_read     /* Routine to read from a TCP-IP socket     */
44 #define NETWRITE s_write    /* Routine to write to a TCP-IP socket      */
45
46 #define bind s_bind         /* Funny names presumably to prevent clashes */
47 #define connect s_connect
48 #define accept s_accept
49 #define listen s_listen
50 #define socket s_socket
51 #define getsockname s_getsockname
52
53 /* The function prototype checking is better than the include files
54 */
55
56 extern s_close(int s);
57 extern s_read(int s, char *buffer, int buflen);
58 extern s_write(int s, const char *buffer, int buflen);
59
60 extern bind(int s, struct sockaddr *name, int namelen);
61 extern accept(int s, struct sockaddr *addr, int *addrlen);
62 extern listen(int s, int qlen);
63 extern connect(int s, struct sockaddr *addr, int addrlen);
64
65 extern s_socket(int domain, int type, int protocol);
66 extern s_getsockname(int s, struct sockaddr *name, int *namelen);
67 extern struct hostent *gethostent(const char * name);
68 extern unsigned long inet_addr(const char * name);
69
70 #endif
71
72
73 /*      On the NeXT, there's a little package of include files.
74 */
75 #ifdef NeXT
76 #include <libc.h>               /* NeXT has all this packaged up */
77 #define ntohs(x) (x)
78 #define htons(x) (x)
79 #include <sys/errno.h>          /* Get ECONNRESET etc */
80 #define SELECT                  /* Is supported ok */
81 #define INCLUDES_DONE
82
83 #else                           /* Not NeXT */
84 #ifndef STDIO_H
85 #include <stdio.h>
86 #define STDIO_H
87 #endif
88
89
90 /*      On the IBM RS-6000, AIX is almost Unix.
91 **      But AIX must be defined in the makefile.
92 */
93 #ifdef AIX
94 #define unix
95 #endif
96
97 /*      MVS is compiled as for VM. MVS has no unix-style I/O
98 **      The command line compile options seem to come across in
99 **      lower case.
100 **
101 **      See aslo lots of VM stuff lower down.
102 */
103 #ifdef mvs
104 #define MVS
105 #endif
106
107 #ifdef MVS
108 #define VM
109 #endif
110
111 #ifdef NEWLIB
112 #pragma linkage(newlib,OS)      /* Enables recursive NEWLIB */
113 #endif
114
115 /*      VM doesn't have a built-in predefined token, so we cheat: */
116 #ifdef __STDIO__
117 #define VM
118 #else
119 #include <string.h>             /* For bzero etc - not NeXT or VM */
120 #endif
121 #define SELECT                  /* Handle >1 channel if we can.         */
122 #endif                          /* Not NeXT */
123
124
125 /*      Under VMS, there are many versions of TCP-IP. Define one if you
126 **      do not use Digital's UCX product:
127 **
128 **              UCX             DEC's "Ultrix connection" (default)
129 **              WIN_TCP         From Wollongong, now GEC software.
130 **              MULTINET        From SRI, now from TGV Inv.
131 **
132 **      The second two do not interfere with the unix i/o library, and so they
133 **      need special calls to read, write and close sockets. In these cases the
134 **      socket number is a VMS channel number, so we make the HORRIBLE
135 **      assumption that a channel number will be greater than 10 but a
136 **      unix file descriptor less than 10.
137 */
138 #ifdef vms
139 #ifdef WIN_TCP
140 #undef NETREAD
141 #undef NETWRITE
142 #undef NETCLOSE
143 #define NETREAD(s,b,l)  ((s)>10 ? netread((s),(b),(l)) : read((s),(b),(l)))
144 #define NETWRITE(s,b,l) ((s)>10 ? netwrite((s),(b),(l)) : write((s),(b),(l)))
145 #define NETCLOSE(s)     ((s)>10 ? netclose(s) : close(s))
146 #endif
147
148 #ifdef MULTINET
149 #undef NETCLOSE
150 #undef NETREAD
151 #undef NETWRITE
152 #define NETREAD(s,b,l)  ((s)>10 ? socket_read((s),(b),(l)) : read((s),(b),(l)))
153 #define NETWRITE(s,b,l) ((s)>10 ? socket_write((s),(b),(l)) : \
154                                 write((s),(b),(l)))
155 #define NETCLOSE(s)     ((s)>10 ? socket_close(s) : close(s))
156 #endif
157
158 /*      Certainly this works for UCX and Multinet; not tried for Wollongong
159 */
160 #ifdef MULTINET
161 #include "multinet_root:[multinet.include.sys]types.h"
162 #include "multinet_root:[multinet.include]errno.h"
163 #include "multinet_root:[multinet.include.sys]time.h"
164 #else
165 #include types
166 #include errno
167 #include time
168 #endif
169 #include string
170 #ifndef STDIO_H
171 #include stdio
172 #define STDIO_H
173 #endif
174
175 #include file
176 #include unixio
177
178 #define INCLUDES_DONE
179
180 #ifdef MULTINET  /* Include from standard Multinet directories */
181 #include "multinet_root:[multinet.include.sys]socket.h"
182 #ifdef __TIME_LOADED  /* defined by sys$library:time.h */
183 #define __TIME  /* to avoid double definitions in next file */
184 #endif
185 #include "multinet_root:[multinet.include.netinet]in.h"
186 #include "multinet_root:[multinet.include.arpa]inet.h"
187 #include "multinet_root:[multinet.include]netdb.h"
188 #else
189 #include socket
190 #include in
191 #include inet
192 #include netdb
193 #endif
194 #define TCP_INCLUDES_DONE
195
196 #endif  /* vms */
197
198
199 /*      IBM VM/CMS or MVS
200 **      -----------------
201 **
202 **      Note:   All files must have lines <= 80 characters
203 **              All include file names must have 8 chars max (+".h")
204 **
205 **      Under VM, compile with "DEF=VM"
206 **
207 **      Under MVS, compile with "NOMAR DEF(MVS)" to get rid of 72 char margin
208 **        System include files TCPIP and COMMMAC neeed line number removal(!)
209 */
210
211 #ifdef VM                       /* or MVS -- see above. */
212 #define NOT_ASCII               /* char type is not ASCII */
213 #define NO_UNIX_IO              /* Unix I/O routines are not supported */
214 #define NO_GETPID               /* getpid() does not exist */
215 #define NO_GETWD                /* getwd() does not exist */
216 #ifndef SHORT_NAMES
217 #define SHORT_NAMES             /* 8 character uniqueness for globals */
218 #endif
219 #include <manifest.h>                                                           
220 #include <bsdtypes.h>                                                           
221 #include <stdefs.h>                                                             
222 #include <socket.h>                                                             
223 #include <in.h>
224 #include <inet.h>
225 #include <netdb.h>                                                                 
226 #include <errno.h>          /* independent */
227 extern char asciitoebcdic[], ebcdictoascii[];
228 #define TOASCII(c)   (c=='\n' ?  10  : ebcdictoascii[c])
229 #define FROMASCII(c) (c== 10  ? '\n' : asciitoebcdic[c])                                   
230 #include <bsdtime.h>
231 #include <time.h>
232 #include <string.h>                                                            
233 #define INCLUDES_DONE
234 #define TCP_INCLUDES_DONE
235 #endif
236
237
238 /*      IBM-PC running MS-DOS with SunNFS for TCP/IP
239 **      ---------------------
240 **
241 **      This code thanks to Eelco van Asperen <evas@cs.few.eur.nl>
242 */
243
244 #ifdef PCNFS
245 #include <sys/types.h>
246 #include <string.h>
247 #ifndef STDIO_H
248 #include <stdio.h>
249 #define STDIO_H
250 #endif
251
252 #include <errno.h>          /* independent */
253 #include <sys/time.h>       /* independent */
254 #include <sys/stat.h>
255 #include <fcntl.h>          /* In place of sys/param and sys/file */
256 #define INCLUDES_DONE
257
258 #define FD_SET(fd,pmask) (*(unsigned*)(pmask)) |=  (1<<(fd))
259 #define FD_CLR(fd,pmask) (*(unsigned*)(pmask)) &= ~(1<<(fd))
260 #define FD_ZERO(pmask)   (*(unsigned*)(pmask))=0
261 #define FD_ISSET(fd,pmask) (*(unsigned*)(pmask) & (1<<(fd)))
262 #endif
263
264
265 /*      Regular BSD unix versions:      (default)
266 **      -------------------------
267 */
268
269 #ifndef INCLUDES_DONE
270 #include <sys/types.h>
271 /* #include <streams/streams.h>                 not ultrix */
272 #include <string.h>
273 #ifndef STDIO_H
274 #include <stdio.h>
275 #define STDIO_H
276 #endif
277
278 #include <errno.h>          /* independent */
279 #include <sys/time.h>       /* independent */
280 #include <sys/stat.h>
281 #include <sys/param.h>
282 #include <sys/file.h>       /* For open() etc */
283 #define INCLUDES_DONE
284 #endif  /* Normal includes */
285
286
287 /*      Default include files for TCP
288 */
289 #ifndef TCP_INCLUDES_DONE
290 #include <sys/socket.h>
291 #include <netinet/in.h>
292 #include <arpa/inet.h>      /* Must be after netinet/in.h */
293 #include <netdb.h>
294 #endif  /* TCP includes */
295
296
297 /*      Default macros for manipulating masks for select()
298 */
299 #ifndef FD_SET
300 typedef unsigned int fd_set;
301 #define FD_SET(fd,pmask) (*(pmask)) |=  (1<<(fd))
302 #define FD_CLR(fd,pmask) (*(pmask)) &= ~(1<<(fd))
303 #define FD_ZERO(pmask)   (*(pmask))=0
304 #define FD_ISSET(fd,pmask) (*(pmask) & (1<<(fd)))
305 #endif
306
307
308 /*      Default macros for converting characters
309 **
310 */
311 #ifndef TOASCII
312 #define TOASCII(c) (c)
313 #define FROMASCII(c) (c)                                   
314 #endif
315
316 #ifndef TOLOWER
317 #ifdef pyr                      /* Pyramid can't uppercase non-alpha */
318 #define TOLOWER(c) (isupper(c) ? tolower(c) : (c))
319 #define TOUPPER(c) (islower(c) ? toupper(c) : (c))
320 #else
321 #define TOLOWER(c) tolower(c)
322 #define TOUPPER(c) toupper(c)
323 #endif /* pyr */
324 #endif /* ndef TOUPPER */
325
326 #endif /* TCP_H */