1 | /* Copyright 1998 by the Massachusetts Institute of Technology. |
---|
2 | * |
---|
3 | * Permission to use, copy, modify, and distribute this |
---|
4 | * software and its documentation for any purpose and without |
---|
5 | * fee is hereby granted, provided that the above copyright |
---|
6 | * notice appear in all copies and that both that copyright |
---|
7 | * notice and this permission notice appear in supporting |
---|
8 | * documentation, and that the name of M.I.T. not be used in |
---|
9 | * advertising or publicity pertaining to distribution of the |
---|
10 | * software without specific, written prior permission. |
---|
11 | * M.I.T. makes no representations about the suitability of |
---|
12 | * this software for any purpose. It is provided "as is" |
---|
13 | * without express or implied warranty. |
---|
14 | */ |
---|
15 | |
---|
16 | static const char rcsid[] = "$Id: busyd.c,v 1.3 2000-09-21 20:09:37 ghudson Exp $"; |
---|
17 | |
---|
18 | #include <sys/types.h> |
---|
19 | #include <sys/socket.h> |
---|
20 | #include <netinet/in.h> |
---|
21 | #include <larv.h> |
---|
22 | |
---|
23 | /* Reject queries from the echo, daytime, chargen, time, domain, and |
---|
24 | * busyd ports. |
---|
25 | */ |
---|
26 | static int reject[] = { 7, 13, 19, 37, 53, 49154 }; |
---|
27 | #define NREJECT (sizeof(reject) / sizeof(*reject)) |
---|
28 | |
---|
29 | int main(int argc, char **argv) |
---|
30 | { |
---|
31 | struct sockaddr_in sin; |
---|
32 | int sz = sizeof(sin), i; |
---|
33 | char dummy; |
---|
34 | |
---|
35 | /* We were run (we hope) from inetd. Read the request packet to |
---|
36 | * clear it from the queue. |
---|
37 | */ |
---|
38 | if (recvfrom(0, &dummy, 1, 0, (struct sockaddr *) &sin, &sz) < 0) |
---|
39 | return 1; |
---|
40 | |
---|
41 | /* Reject queries from ports of well-known services which we could |
---|
42 | * get into a loop with. |
---|
43 | */ |
---|
44 | for (i = 0; i < NREJECT; i++) |
---|
45 | { |
---|
46 | if (ntohs(sin.sin_port) == reject[i]) |
---|
47 | return 1; |
---|
48 | } |
---|
49 | |
---|
50 | /* Now send the response. */ |
---|
51 | if (larv_send_status(0, (struct sockaddr *) &sin, sz) == -1) |
---|
52 | return 1; |
---|
53 | |
---|
54 | return 0; |
---|
55 | } |
---|