]> git.ipfire.org Git - thirdparty/squid.git/blob - src/recv-announce.cc
lint
[thirdparty/squid.git] / src / recv-announce.cc
1
2
3 /*
4 * $Id: recv-announce.cc,v 1.17 1998/02/03 04:21:20 wessels Exp $
5 *
6 * DEBUG: section 0 Announcement Server
7 * AUTHOR: Harvest Derived
8 *
9 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
10 * --------------------------------------------------------
11 *
12 * Squid is the result of efforts by numerous individuals from the
13 * Internet community. Development is led by Duane Wessels of the
14 * National Laboratory for Applied Network Research and funded by
15 * the National Science Foundation.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 *
31 */
32
33 /*
34 * Copyright (c) 1994, 1995. All rights reserved.
35 *
36 * The Harvest software was developed by the Internet Research Task
37 * Force Research Group on Resource Discovery (IRTF-RD):
38 *
39 * Mic Bowman of Transarc Corporation.
40 * Peter Danzig of the University of Southern California.
41 * Darren R. Hardy of the University of Colorado at Boulder.
42 * Udi Manber of the University of Arizona.
43 * Michael F. Schwartz of the University of Colorado at Boulder.
44 * Duane Wessels of the University of Colorado at Boulder.
45 *
46 * This copyright notice applies to software in the Harvest
47 * ``src/'' directory only. Users should consult the individual
48 * copyright notices in the ``components/'' subdirectories for
49 * copyright information about other software bundled with the
50 * Harvest source code distribution.
51 *
52 * TERMS OF USE
53 *
54 * The Harvest software may be used and re-distributed without
55 * charge, provided that the software origin and research team are
56 * cited in any use of the system. Most commonly this is
57 * accomplished by including a link to the Harvest Home Page
58 * (http://harvest.cs.colorado.edu/) from the query page of any
59 * Broker you deploy, as well as in the query result pages. These
60 * links are generated automatically by the standard Broker
61 * software distribution.
62 *
63 * The Harvest software is provided ``as is'', without express or
64 * implied warranty, and with no support nor obligation to assist
65 * in its use, correction, modification or enhancement. We assume
66 * no liability with respect to the infringement of copyrights,
67 * trade secrets, or any patents, and are not responsible for
68 * consequential damages. Proper use of the Harvest software is
69 * entirely the responsibility of the user.
70 *
71 * DERIVATIVE WORKS
72 *
73 * Users may make derivative works from the Harvest software, subject
74 * to the following constraints:
75 *
76 * - You must include the above copyright notice and these
77 * accompanying paragraphs in all forms of derivative works,
78 * and any documentation and other materials related to such
79 * distribution and use acknowledge that the software was
80 * developed at the above institutions.
81 *
82 * - You must notify IRTF-RD regarding your distribution of
83 * the derivative work.
84 *
85 * - You must clearly notify users that your are distributing
86 * a modified version and not the original Harvest software.
87 *
88 * - Any derivative product is also subject to these copyright
89 * and use restrictions.
90 *
91 * Note that the Harvest software is NOT in the public domain. We
92 * retain copyright, as specified above.
93 *
94 * HISTORY OF FREE SOFTWARE STATUS
95 *
96 * Originally we required sites to license the software in cases
97 * where they were going to build commercial products/services
98 * around Harvest. In June 1995 we changed this policy. We now
99 * allow people to use the core Harvest software (the code found in
100 * the Harvest ``src/'' directory) for free. We made this change
101 * in the interest of encouraging the widest possible deployment of
102 * the technology. The Harvest software is really a reference
103 * implementation of a set of protocols and formats, some of which
104 * we intend to standardize. We encourage commercial
105 * re-implementations of code complying to this set of standards.
106 */
107
108 #include <stdio.h>
109 #include <fcntl.h>
110 #include <stdlib.h>
111 #include <string.h>
112 #include <sys/types.h>
113 #include <sys/socket.h>
114 #include <netinet/in.h>
115 #include <arpa/inet.h>
116 #include <netdb.h>
117 #include <unistd.h>
118 #include <signal.h>
119
120 #define RECV_BUF_SIZE 8192
121
122 extern void xmemcpy(void *from, void *to, int len);
123
124 /*
125 * This program must be run from inetd. First add something like this
126 * to /etc/services:
127 *
128 * cached_announce 3131/udp # cache announcements
129 *
130 * And then add something like this to /etc/inetd/conf:
131 *
132 * cached_announce dgram udp wait cached /tmp/recv-announce recv-announce /tmp/recv-announce.log
133 *
134 *
135 * A single instance of this process will continue to handle incoming
136 * requests. If it dies, or is killed, inetd should restart it when the
137 * next message arrives.
138 *
139 */
140
141 /*
142 * usage: recv-announce logfile
143 */
144
145 static void
146 sig_handle(void)
147 {
148 fflush(stdout);
149 close(2);
150 close(1);
151 close(0);
152 exit(0);
153 }
154
155
156 int
157 main(int argc, char *argv[])
158 {
159 char buf[RECV_BUF_SIZE];
160 struct sockaddr_in R;
161 int len;
162 struct hostent *hp = NULL;
163 char logfile[BUFSIZ];
164 char ip[4];
165
166 for (len = 0; len < 32; len++) {
167 signal(len, sig_handle);
168 }
169
170
171 if (argc > 1)
172 strcpy(logfile, argv[1]);
173 else
174 strcpy(logfile, "/tmp/recv-announce.log");
175
176 close(1);
177 if (open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0660) < 0) {
178 perror(logfile);
179 exit(1);
180 }
181 close(2);
182 dup(1);
183
184
185 for(;;) {
186 memset(buf, '\0', RECV_BUF_SIZE);
187 memset(&R, '\0', len = sizeof(R));
188
189 if (recvfrom(0, buf, RECV_BUF_SIZE, 0, &R, &len) < 0) {
190 perror("recv");
191 exit(2);
192 }
193 xmemcpy(ip, &R.sin_addr.s_addr, 4);
194 hp = gethostbyaddr(ip, 4, AF_INET);
195 printf("==============================================================================\n");
196 printf("Received from %s [%s]\n",
197 inet_ntoa(R.sin_addr),
198 (hp && hp->h_name) ? hp->h_name : "Unknown");
199 fputs(buf, stdout);
200 fflush(stdout);
201 }
202 return 0;
203 }