9 /* Some of our own infrastructure where the WinSock stuff was too hairy
10 to dump into a clean Unix program... */
12 typedef WSABUF sg_buf
;
14 #define SG_ADVANCE(SG, N) \
17 : ((SG)->buf += (N), (SG)->len -= (N), 0))
19 #define SG_LEN(SG) ((SG)->len + 0)
20 #define SG_BUF(SG) ((SG)->buf + 0)
21 #define SG_SET(SG, B, N) ((SG)->buf = (char *)(B),(SG)->len = (N))
23 #define SOCKET_INITIALIZE() 0
24 #define SOCKET_CLEANUP()
25 #define SOCKET_ERRNO (WSAGetLastError())
26 #define SOCKET_SET_ERRNO(x) (WSASetLastError (x))
27 #define SOCKET_NFDS(f) (0) /* select()'s first arg is ignored */
28 #define SOCKET_READ(fd, b, l) (recv(fd, b, l, 0))
29 #define SOCKET_WRITE(fd, b, l) (send(fd, b, l, 0))
30 #define SOCKET_CONNECT connect /* XXX */
31 #define SOCKET_GETSOCKNAME getsockname /* XXX */
32 #define SOCKET_CLOSE close /* XXX */
33 #define SOCKET_EINTR WSAEINTR
35 /* Return -1 for error or number of bytes written.
36 TMP is a temporary variable; must be declared by the caller, and
37 must be used by this macro (to avoid compiler warnings). */
38 /* WSASend returns 0 or SOCKET_ERROR. */
39 #define SOCKET_WRITEV_TEMP DWORD
40 #define SOCKET_WRITEV(FD, SG, LEN, TMP) \
41 (WSASend((FD), (SG), (LEN), &(TMP), 0, 0, 0) ? -1 : (TMP))
43 #define SHUTDOWN_READ SD_RECEIVE
44 #define SHUTDOWN_WRITE SD_SEND
45 #define SHUTDOWN_BOTH SD_BOTH
48 #define EINPROGRESS WSAEINPROGRESS
51 #define EWOULDBLOCK WSAEWOULDBLOCK
54 #define ECONNRESET WSAECONNRESET
57 #define ECONNABORTED WSAECONNABORTED
60 #define ECONNREFUSED WSAECONNREFUSED
63 #define EHOSTUNREACH WSAEHOSTUNREACH
66 #define ETIMEDOUT WSAETIMEDOUT
69 #elif defined(__palmos__)
71 /* If this source file requires it, define struct sockaddr_in
72 (and possibly other things related to network I/O). */
76 typedef int socklen_t
;
78 #else /* UNIX variants */
82 #include <sys/types.h>
83 #include <netinet/in.h> /* For struct sockaddr_in and in_addr */
84 #include <arpa/inet.h> /* For inet_ntoa */
87 #ifndef HAVE_NETDB_H_H_ERRNO
88 extern int h_errno
; /* In case it's missing, e.g., HP-UX 10.20. */
91 #include <sys/param.h> /* For MAXHOSTNAMELEN */
92 #include <sys/socket.h> /* For SOCK_*, AF_*, etc */
93 #include <sys/time.h> /* For struct timeval */
94 #include <net/if.h> /* For struct ifconf, for localaddr.c */
96 #include <sys/uio.h> /* For struct iovec, for sg_buf */
98 #ifdef HAVE_SYS_FILIO_H
99 #include <sys/filio.h> /* For FIONBIO on Solaris. */
102 /* Either size_t or int or unsigned int is probably right. Under
103 SunOS 4, it looks like int is desired, according to the accept man
105 #ifndef HAVE_SOCKLEN_T
106 typedef int socklen_t
;
109 /* XXX should only be done if sockaddr_storage not found */
110 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
111 struct krb5int_sockaddr_storage
{
112 struct sockaddr_in s
;
113 /* Plenty of slop just in case we get an ipv6 address anyways. */
116 #define sockaddr_storage krb5int_sockaddr_storage
120 * Compatability with WinSock calls on MS-Windows...
123 #define INVALID_SOCKET ((SOCKET)~0)
124 #define closesocket close
125 #define ioctlsocket ioctl
126 #define SOCKET_ERROR (-1)
128 typedef struct iovec sg_buf
;
130 #define SG_ADVANCE(SG, N) \
131 ((SG)->iov_len < (N) \
133 : ((SG)->iov_base = (char *) (SG)->iov_base + (N), \
134 (SG)->iov_len -= (N), 0))
136 #define SG_LEN(SG) ((SG)->iov_len + 0)
137 #define SG_BUF(SG) ((char*)(SG)->iov_base + 0)
138 #define SG_SET(SG, B, L) ((SG)->iov_base = (char*)(B), (SG)->iov_len = (L))
140 /* Some of our own infrastructure where the WinSock stuff was too hairy
141 to dump into a clean Unix program... */
143 #define SOCKET_INITIALIZE() (0) /* No error (or anything else) */
144 #define SOCKET_CLEANUP() /* nothing */
145 #define SOCKET_ERRNO errno
146 #define SOCKET_SET_ERRNO(x) (errno = (x))
147 #define SOCKET_NFDS(f) ((f)+1) /* select() arg for a single fd */
148 #define SOCKET_READ read
149 #define SOCKET_WRITE write
150 #define SOCKET_CONNECT connect
151 #define SOCKET_GETSOCKNAME getsockname
152 #define SOCKET_CLOSE close
153 #define SOCKET_EINTR EINTR
154 #define SOCKET_WRITEV_TEMP int
155 /* Use TMP to avoid compiler warnings and keep things consistent with
157 #define SOCKET_WRITEV(FD, SG, LEN, TMP) \
158 ((TMP) = writev((FD), (SG), (LEN)), (TMP))
160 #define SHUTDOWN_READ 0
161 #define SHUTDOWN_WRITE 1
162 #define SHUTDOWN_BOTH 2
164 #ifndef HAVE_INET_NTOP
165 #define inet_ntop(AF,SRC,DST,CNT) \
168 ? (SOCKET_SET_ERRNO(ENOSPC), (const char *)NULL) \
169 : (sprintf((DST), "%d.%d.%d.%d", \
170 ((const unsigned char *)(const void *)(SRC))[0] & 0xff, \
171 ((const unsigned char *)(const void *)(SRC))[1] & 0xff, \
172 ((const unsigned char *)(const void *)(SRC))[2] & 0xff, \
173 ((const unsigned char *)(const void *)(SRC))[3] & 0xff), \
175 : (SOCKET_SET_ERRNO(EAFNOSUPPORT), (const char *)NULL))
176 #define HAVE_INET_NTOP
184 extern int socket (int, int, int) /*@*/;
188 #endif /*_PORT_SOCKET_H*/