source: trunk/third/cns/src/include/macsock.h @ 8789

Revision 8789, 5.1 KB checked in by ghudson, 28 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r8788, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * Mac interface compatible with WinSock and Unix Sockets.
3 *
4 * Implemented by John Gilmore, Cygnus Support, June 1994.
5 *
6 * Derived from:
7 *
8        Interface into the UDP class.
9        Written by Timothy Miller for Brown University.
10       
11        This class is extremely sketchy and not meant for general use.
12        It's only here because I need a machine independant interface
13        for UDP for internal use by kerberos. If you need to use udp to
14        do anything serious, be my guest and rewrite this! (Just be
15        sure to update the kerberos files send_to_kdc.cp and
16        time_stuff.cp if you change the interface.)
17 *
18 * This interface only implements a warped subset of sockets, suitable only
19 * for a Kerberos client's communication with its Key Distribution Centers.
20 */
21
22/* Handle ANSI C versus traditional C */
23#ifndef __STDC__
24#define const
25#define volatile
26#define signed
27#define PROTOTYPE(p) ()
28#else
29#define PROTOTYPE(p) p
30#endif
31
32/* The socket data structure itself.   */
33struct socket {
34        short           fMacTCPRef;             /* refnum of MacTCP driver */
35        unsigned long   fStream;                /* MacTCP socket/stream */
36#       define          UDPbuflen       4096
37        char            fRecvBuf[UDPbuflen];    /* receive buffer area */
38};
39
40typedef struct socket *SOCKET;
41
42#define WORD    short
43#define LOBYTE(x)        ((x)       & 0xFF)
44#define HIBYTE(x)       (((x) >> 8) & 0xFF)
45
46/* Error codes */
47/* FIXME -- picked at random */
48#define WSAVERNOTSUPPORTED      14563   /* WinSock version not supported */
49#define EMSGSIZE                14567   /* Received packet truncated */
50#define WSAEINTR                14568   /* Interrupted system call */
51
52
53/* Struct for initializing the socket library */
54struct WSAData {
55        WORD    wVersion;
56        WORD    wHighVersion;
57#define WSADESCRIPTION_LEN      256
58        char    szDescription[WSADESCRIPTION_LEN+1];
59#define WSASYSSTATUS_LEN        256
60        char    szSystemStatus[WSASYSSTATUS_LEN+1];
61        unsigned short  iMaxSockets;
62        unsigned short  iMaxUdpDg;
63        char    *lpVendorInfo;
64};
65
66typedef struct WSAData WSADATA;
67
68/*
69 * Internet address.  New code should use only the s_addr field.
70 */
71struct in_addr {
72        unsigned long s_addr;
73};
74
75
76/*
77 * Socket address, internet style.
78 */
79struct sockaddr_in {
80        short   sin_family;
81        unsigned short  sin_port;
82        struct  in_addr sin_addr;
83        char    sin_zero[8];
84};
85
86/* Socket address, other styles */
87#define sockaddr sockaddr_in
88
89/*
90 * Host name<->address mapping entries
91 */
92struct    hostent {
93    char *h_name;  /* official name of host */
94    char **h_aliases;   /* alias list */
95    int  h_addrtype;    /* address type */
96    int  h_length; /* length of address */
97    char **h_addr_list; /* list of addresses from name server */
98#define h_addr  h_addr_list[0]  /* address, for backward compatiblity */
99};
100
101/*
102 * Service name<->port mapping
103 */
104struct  servent {
105        char    *s_name;        /* official service name */
106        char    **s_aliases;    /* alias list */
107        int     s_port;         /* port # */
108        char    *s_proto;       /* protocol to use */
109};
110
111/* Timeout values */
112struct timeval {
113        long tv_sec;                    /* Seconds */
114        long tv_usec;                   /* Microseconds */
115};
116
117/* True Kludge version of select argument fd_set's */
118typedef int             fd_set;
119#define FD_ZERO(x)      0
120#define FD_CLEAR(x)     /* nothing */
121#define FD_SET(fd,x)    /* nothing */
122#define FD_ISSET(fd, x) 1
123
124/* Other misc constants */
125#define MAXHOSTNAMELEN  512     /* Why be stingy? */
126#define SOCK_DGRAM      2               /* Datagram socket type */
127#define AF_INET 2                       /* Internet address family */
128#define INADDR_ANY      ((unsigned long)0)      /* Internet addr: any host */
129
130/* Start using sockets */
131extern int
132WSAStartup PROTOTYPE ((WORD version, struct WSAData *));
133
134/* Finish using sockets */
135extern int
136WSACleanup PROTOTYPE ((void));
137
138/* Get a particular socket */
139extern SOCKET
140socket PROTOTYPE ((int af, int type, int protocol));
141
142/* Finish using a particular socket.  */
143extern int
144closesocket PROTOTYPE ((SOCKET theUDP));
145
146/* Bind a socket to a particular address.
147   In our case, this is just a no-op for bug-compatability with
148   the FTP Software WINSOCK library.  */
149extern int
150bind PROTOTYPE ((SOCKET s, const struct sockaddr *name, int namelen));
151
152/* Send a packet to a UDP peer.  */
153extern int
154sendto PROTOTYPE ((SOCKET theUDP, const char *buf, const int len, int flags,
155        const struct sockaddr *to, int tolen));
156
157/* Select for sockets that are ready for I/O.
158   This version just remembers the timeout for a future receive...
159   It always reports that one socket is ready for I/O.  */
160extern int
161select PROTOTYPE ((int nfds, fd_set *readfds, fd_set *writefds,
162                   fd_set *exceptfds, const struct timeval *timeout));
163
164/* Receive a packet from a UDP peer.  */
165extern int
166recvfrom PROTOTYPE ((SOCKET theUDP, char *buf, int len, int flags,
167                     struct sockaddr *from, int *fromlen));
168
169extern char *
170inet_ntoa PROTOTYPE ((struct in_addr ina));
171
172extern struct hostent *
173gethostbyname PROTOTYPE ((char *));
174
175extern struct hostent *
176gethostbyaddr PROTOTYPE ((char *addr, int len, int type));
177
178/* Bypass a few other functions we don't really need. */
179
180#define getservbyname(name,prot)        0
181
182/* Macs operate in network byte order (big-endian).  */
183#define htonl(x)        (x)
184#define htons(x)        (x)
185#define ntohl(x)        (x)
186#define ntohs(x)        (x)
187
188/*
189 * Compatability with WinSock calls on MS-Windows...
190 */
191#define INVALID_SOCKET  ((SOCKET)~0)
192#define SOCKET_ERROR    (-1)
193#define WSAGetLastError(x)      (errno)
194#define WSASetLastError(x)      (errno = (x))
195
196extern int errno;
Note: See TracBrowser for help on using the repository browser.