1 /*********************************************************************
2 Project : GUSI - Grand Unified Socket Interface
3 File : GUSI.h - Socket calls
4 Author : Matthias Neeracher
8 Revision 1.1 1998/08/18 14:52:33 jack
9 Putting Python-specific GUSI modifications under CVS.
11 Revision 1.2 1994/12/31 01:45:54 neeri
14 Revision 1.1 1994/02/25 02:56:49 neeri
17 Revision 0.15 1993/06/27 00:00:00 neeri
20 Revision 0.14 1993/06/20 00:00:00 neeri
23 Revision 0.13 1993/02/14 00:00:00 neeri
26 Revision 0.12 1992/12/08 00:00:00 neeri
29 Revision 0.11 1992/11/15 00:00:00 neeri
30 remove netdb.h definitions
32 Revision 0.10 1992/09/26 00:00:00 neeri
33 Separate dirent and stat
35 Revision 0.9 1992/09/12 00:00:00 neeri
38 Revision 0.8 1992/09/07 00:00:00 neeri
41 Revision 0.7 1992/08/03 00:00:00 neeri
44 Revision 0.6 1992/07/21 00:00:00 neeri
47 Revision 0.5 1992/06/26 00:00:00 neeri
50 Revision 0.4 1992/05/18 00:00:00 neeri
53 Revision 0.3 1992/04/27 00:00:00 neeri
56 Revision 0.2 1992/04/19 00:00:00 neeri
59 Revision 0.1 1992/04/17 00:00:00 neeri
62 *********************************************************************/
67 #include <sys/types.h>
69 /* Feel free to increase FD_SETSIZE as needed */
70 #define GUSI_MAX_FD FD_SETSIZE
72 #include <sys/cdefs.h>
74 #include <sys/ioctl.h>
75 #include <sys/fcntl.h>
81 #include <AppleTalk.h>
82 #include <CTBUtilities.h>
84 #include <PPCToolBox.h>
85 #include <StandardFile.h>
88 #include <sys/socket.h>
90 #include <netinet/in.h>
94 #include <machine/endian.h>
96 typedef enum spin_msg
{
97 SP_MISC
, /* some weird thing, usually just return immediately if you get this */
98 SP_SELECT
, /* in a select call */
99 SP_NAME
, /* getting a host by name */
100 SP_ADDR
, /* getting a host by address */
101 SP_STREAM_READ
, /* Stream read call */
102 SP_STREAM_WRITE
, /* Stream write call */
103 SP_DGRAM_READ
, /* Datagram read call */
104 SP_DGRAM_WRITE
, /* Datagram write call */
105 SP_SLEEP
, /* sleeping, passes ticks left to sleep */
106 SP_AUTO_SPIN
/* Autospin, passes argument to SpinCursor */
109 typedef int (*GUSISpinFn
)(spin_msg msg
, long param
);
110 typedef void (*GUSIEvtHandler
)(EventRecord
* ev
);
111 typedef GUSIEvtHandler GUSIEvtTable
[24];
114 * Address families, defined in sys/socket.h
117 #define AF_UNSPEC 0 // unspecified
118 #define AF_UNIX 1 // local to host (pipes, portals)
119 #define AF_INET 2 // internetwork: UDP, TCP, etc.
120 #define AF_CTB 3 // Apple Comm Toolbox (not yet supported)
121 #define AF_FILE 4 // Normal File I/O (used internally)
122 #define AF_PPC 5 // PPC Toolbox
123 #define AF_PAP 6 // Printer Access Protocol (client only)
124 #define AF_APPLETALK 16 // Apple Talk
128 #define ATALK_SYMADDR 272 /* Symbolic Address for AppleTalk */
131 * Some Implementations of GUSI require you to call GUSISetup for the
132 * socket families you'd like to have defined. It's a good idea to call
133 * this for *all* implementations.
135 * GUSIDefaultSetup() will include all socket families.
137 * Never call any of the GUSIwithXXX routines directly.
141 void GUSIwithAppleTalkSockets();
142 void GUSIwithInternetSockets();
143 void GUSIwithPAPSockets();
144 void GUSIwithPPCSockets();
145 void GUSIwithUnixSockets();
146 void GUSIwithSIOUXSockets();
147 void GUSIwithMPWSockets();
149 void GUSISetup(void (*socketfamily
)());
150 void GUSIDefaultSetup();
151 void GUSILoadConfiguration(Handle
);
154 * Types, defined in sys/socket.h
157 #define SOCK_STREAM 1 // stream socket
158 #define SOCK_DGRAM 2 // datagram socket
163 * Defined in sys/un.h
173 #ifndef PRAGMA_ALIGN_SUPPORTED
174 #error Apple had some fun with the conditional macros again
177 #if PRAGMA_ALIGN_SUPPORTED
178 #pragma options align=mac68k
181 struct sockaddr_atlk
{
186 struct sockaddr_atlk_sym
{
191 struct sockaddr_ppc
{
193 LocationNameRec location
;
197 /* Definitions for choose() */
199 #define CHOOSE_DEFAULT 1 /* Use *name as default name */
200 #define CHOOSE_NEW 2 /* Choose new entity name, not existing one */
201 #define CHOOSE_DIR 4 /* Choose a directory name, not a file */
213 /* Definitions for sa_constr_ppc */
215 #define PPC_CON_NEWSTYLE 0x8000 /* Required */
216 #define PPC_CON_MATCH_NAME 0x0001 /* Match name */
217 #define PPC_CON_MATCH_TYPE 0x0002 /* Match port type */
218 #define PPC_CON_MATCH_NBP 0x0004 /* Match NBP type */
226 #if PRAGMA_ALIGN_SUPPORTED
227 #pragma options align=reset
232 * IO/Socket stuff, defined elsewhere (unistd.h, sys/socket.h
235 int socket(int domain, int type, short protocol);
236 int bind(int s, void *name, int namelen);
237 int connect(int s, void *addr, int addrlen);
238 int listen(int s, int qlen);
239 int accept(int s, void *addr, int *addrlen);
241 int read(int s, char *buffer, unsigned buflen);
242 int readv(int s, struct iovec *iov, int count);
243 int recv(int s, void *buffer, int buflen, int flags);
244 int recvfrom(int s, void *buffer, int buflen, int flags, void *from, int *fromlen);
245 int recvmsg(int s,struct msghdr *msg,int flags);
246 int write(int s, const char *buffer, unsigned buflen);
247 int writev(int s, struct iovec *iov, int count);
248 int send(int s, void *buffer, int buflen, int flags);
249 int sendto (int s, void *buffer, int buflen, int flags, void *to, int tolen);
250 int sendmsg(int s,struct msghdr *msg,int flags);
251 int select(int width, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
252 int getdtablesize(void);
253 int getsockname(int s, void *name, int *namelen);
254 int getpeername(int s, struct sockaddr *name, int *namelen);
255 int shutdown(int s, int how);
256 int fcntl(int s, unsigned int cmd, int arg);
258 int dup2(int s, int s1);
259 int ioctl(int d, unsigned int request, long *argp);
260 int getsockopt(int s, int level, int optname, char *optval, int * optlen);
261 int setsockopt(int s, int level, int optname, char *optval, int optlen);
263 int remove(const char *filename);
264 int rename(const char *oldname, const char *newname);
265 int creat(const char*);
266 int faccess(char*, unsigned int, long*);
267 long lseek(int, long, int);
268 int open(const char*, int);
270 int symlink(char* linkto, char* linkname);
271 int readlink(char* path, char* buf, int bufsiz);
272 int truncate(char *path, long length);
273 int ftruncate(int fd, long length);
274 int chdir(char * path);
275 int mkdir(char * path);
276 int rmdir(char * path);
277 char * getcwd(char * buf, int size);
285 void fsetfileinfo (char *filename
, unsigned long newcreator
, unsigned long newtype
);
288 void fgetfileinfo (char *filename
, unsigned long * creator
, unsigned long * type
);
291 FILE *fdopen(int fd
, const char *mode
);
292 int fwalk(int (*func
)(FILE * stream
));
305 * Hostname routines, defined in netdb.h
308 struct hostent * gethostbyname(char *name);
309 struct hostent * gethostbyaddr(struct in_addr *addrP, int, int);
310 int gethostname(char *machname, long buflen);
311 struct servent * getservbyname (char * name, char * proto);
312 struct protoent * getprotobyname(char * name);
316 char * inet_ntoa(struct in_addr inaddr
);
317 struct in_addr
inet_addr(char *address
);
320 * GUSI supports a number of hooks. Every one of them has a different prototype, but needs
321 * to be passed as a GUSIHook
325 GUSI_SpinHook
, /* A GUSISpinFn, to be called when a call blocks */
326 GUSI_ExecHook
, /* Boolean (*hook)(const GUSIFileRef & ref), decides if file is executable */
327 GUSI_FTypeHook
,/* Boolean (*hook)(const FSSpec & spec) sets a default file type */
328 GUSI_SpeedHook
/* A long integer, to be added to the cursor spin variable */
331 typedef void (*GUSIHook
)(void);
332 void GUSISetHook(GUSIHookCode code
, GUSIHook hook
);
333 GUSIHook
GUSIGetHook(GUSIHookCode code
);
336 * What to do when a routine blocks
339 /* Defined for compatibility */
340 #define GUSISetSpin(routine) GUSISetHook(GUSI_SpinHook, (GUSIHook)routine)
341 #define GUSIGetSpin() (GUSISpinFn) GUSIGetHook(GUSI_SpinHook)
343 int GUSISetEvents(GUSIEvtTable table
);
344 GUSIEvtHandler
* GUSIGetEvents(void);
346 extern GUSIEvtHandler GUSISIOWEvents
[];
352 * BSD memory routines, defined in compat.h
355 #define index(a, b) strchr(a, b)
356 #define rindex(a, b) strrchr(a, b)
357 #define bzero(from, len) memset(from, 0, len)
358 #define bcopy(from, to, len) memcpy(to, from, len)
359 #define bcmp(s1, s2, len) memcmp(s1, s2, len)
360 #define bfill(from, len, x) memset(from, x, len)