2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* selsubs.c - common code for client and server. */
16 #include <sys/select.h>
17 #include <sys/types.h>
18 #include <sys/socket.h>
21 #include <netinet/in.h>
24 #include <sys/ioctl.h>
28 #include <afs/param.h>
29 #include <afsconfig.h>
37 #ifdef NEEDS_ALLOCFDSET
38 /* Include these if testing against 32 bit fd_set IOMGR. */
39 fd_set *IOMGR_AllocFDSet(void)
41 fd_set *tmp = (fd_set*)malloc(sizeof(fd_set));
42 bzero((char*)tmp, sizeof(fd_set));
46 void IOMGR_FreeFDSet(fd_set *fds)
52 /* The TCP spec calls for writing at least one byte of OOB data which is
53 * read by the receiver using recv with the MSG_OOB flag set.
59 Log("Sending OOB.\n");
60 if (send(fd, &c, 1, MSG_OOB)<0) {
69 Log("Received OOB\n");
70 if (recv(fd, &c, 1, MSG_OOB)<0) {
76 void assertNullFDSet(int fd, fd_set *fds)
79 int n = sizeof(*fds)/sizeof(int);
91 * Open file descriptors until file descriptor n or higher is returned.
102 for (i=0; i<n; i++) {
103 if (fstat(i, &sbuf)==0)
105 if ((fd = open("/dev/null", 0, 0)) < 0) {
123 /* If flag is set, abort. */
124 void Die(int flag, char *msg)
127 extern char *program;
129 (void) sprintf(tmp, "%s: %s: ", program ? program : "", msg);
140 void Log(char *fmt, ...)
147 extern char *program;
149 code = gettimeofday(&now);
152 ltime = localtime((time_t*)&now.tv_sec);
154 LWP_CurrentProcess(&pid);
155 fprintf(stderr, "%s 0x%x %02d:%02d:%02d.%d: ", program ? program : "", pid,
156 ltime->tm_hour, ltime->tm_min, ltime->tm_sec, now.tv_usec);
160 vfprintf(stderr, fmt, args);