]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/recv-announce.cc
3 * $Id: recv-announce.cc,v 1.26 2003/02/21 22:50:10 robertc Exp $
5 * DEBUG: section 0 Announcement Server
6 * AUTHOR: Harvest Derived
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
50 #define RECV_BUF_SIZE 8192
53 * This program must be run from inetd. First add something like this
56 * cached_announce 3131/udp # cache announcements
58 * And then add something like this to /etc/inetd/conf:
60 * cached_announce dgram udp wait cached /tmp/recv-announce recv-announce /tmp/recv-announce.log
63 * A single instance of this process will continue to handle incoming
64 * requests. If it dies, or is killed, inetd should restart it when the
65 * next message arrives.
70 * usage: recv-announce logfile
85 main(int argc
, char *argv
[])
87 char buf
[RECV_BUF_SIZE
];
92 struct hostent
*hp
= NULL
;
96 for (len
= 0; len
< 32; len
++) {
97 signal(len
, sig_handle
);
102 strcpy(logfile
, argv
[1]);
104 strcpy(logfile
, "/tmp/recv-announce.log");
108 if (open(logfile
, O_WRONLY
| O_CREAT
| O_APPEND
, 0660) < 0) {
118 memset(buf
, '\0', RECV_BUF_SIZE
);
119 memset(&R
, '\0', len
= sizeof(R
));
121 if (recvfrom(0, buf
, RECV_BUF_SIZE
, 0, (sockaddr
*)&R
, &len
) < 0) {
126 xmemcpy(ip
, &R
.sin_addr
.s_addr
, 4);
127 hp
= gethostbyaddr(ip
, 4, AF_INET
);
128 printf("==============================================================================\n");
129 printf("Received from %s [%s]\n",
130 inet_ntoa(R
.sin_addr
),
131 (hp
&& hp
->h_name
) ? hp
->h_name
: "Unknown");