mopd: add new package for alpha netboot
[openadk.git] / package / mopd / src / common / loop-linux2.c
blob04654510cc868241e50aaa943668183d6e229327
1 /*
2 * Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement:
14 * This product includes software developed by Mats O Jansson.
15 * 4. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef LINT
31 static char rcsid[] = "$Id: loop-linux2.c,v 1.1.1.1 2001/06/24 19:33:53 atp Exp $";
32 #endif
34 #include <stdlib.h>
35 #include <strings.h>
36 #include <unistd.h>
37 #if defined(__bsdi__) || defined(__FreeBSD__)
38 #include <sys/time.h>
39 #endif
40 #include <sys/ioctl.h>
41 #include <sys/errno.h>
43 #include "os.h"
44 #include "common.h"
45 #include "mopdef.h"
47 int
48 mopOpenRC(p, trans)
49 struct if_info *p;
50 int trans;
52 #ifndef NORC
53 return (*(p->iopen))(p->if_name,
54 O_RDWR,
55 MOP_K_PROTO_RC,
56 trans);
57 #else
58 return -1;
59 #endif
62 int
63 mopOpenDL(p, trans)
64 struct if_info *p;
65 int trans;
67 #ifndef NODL
68 return (*(p->iopen))(p->if_name,
69 O_RDWR,
70 MOP_K_PROTO_DL,
71 trans);
72 #else
73 return -1;
74 #endif
77 void
78 mopReadRC()
82 void
83 mopReadDL()
88 * The list of all interfaces that are being listened to. loop()
89 * "selects" on the descriptors in this list.
91 struct if_info *iflist;
93 void mopProcess __P((struct if_info *, u_char *));
96 * Loop indefinitely listening for MOP requests on the
97 * interfaces in 'iflist'.
99 void
100 Loop()
102 u_char *buf, *bp, *ep;
103 int cc;
104 fd_set fds, listeners;
105 int bufsize = 1100, maxfd =0;
106 struct if_info *ii;
109 if (iflist == 0) {
110 syslog(LOG_ERR, "no interfaces");
111 exit(0);
114 buf = (u_char *) malloc((unsigned) bufsize);
116 if (buf == 0) {
117 syslog(LOG_ERR, "malloc: %m");
118 exit(0);
121 * Find the highest numbered file descriptor for select().
122 * Initialize the set of descriptors to listen to.
124 FD_ZERO(&fds);
125 for (ii = iflist; ii; ii = ii->next) {
126 if (ii->fd != -1) {
127 FD_SET(ii->fd, &fds);
128 if (ii->fd > maxfd)
129 maxfd = ii->fd;
132 while (1) {
133 listeners = fds;
134 if (select(maxfd + 1, &listeners, (fd_set *) 0,
135 (fd_set *) 0, (struct timeval *) 0) < 0) {
136 syslog(LOG_ERR, "select: %m");
137 exit(0);
139 for (ii = iflist; ii; ii = ii->next) {
140 if (ii->fd != -1) {
141 if (!FD_ISSET(ii->fd, &listeners))
142 continue;
144 again:
145 cc = read(ii->fd, (char *) buf, bufsize);
146 /* Don't choke when we get ptraced */
147 if (cc < 0 && errno == EINTR)
148 goto again;
150 bp = buf;
151 ep = bp + cc;
153 if(bp < ep)
155 mopProcess(ii,buf);