]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/recv-announce.cc
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 00 Announcement Server */
16 #include <sys/socket.h>
17 #include <netinet/in.h>
18 #include <arpa/inet.h>
22 #define RECV_BUF_SIZE 8192
25 * This program must be run from inetd. First add something like this
28 * cached_announce 3131/udp # cache announcements
30 * And then add something like this to /etc/inetd/conf:
32 * cached_announce dgram udp wait cached /tmp/recv-announce recv-announce /tmp/recv-announce.log
35 * A single instance of this process will continue to handle incoming
36 * requests. If it dies, or is killed, inetd should restart it when the
37 * next message arrives.
42 * usage: recv-announce logfile
56 main(int argc
, char *argv
[])
58 char buf
[RECV_BUF_SIZE
];
63 struct hostent
*hp
= NULL
;
67 for (len
= 0; len
< 32; ++len
) {
68 signal(len
, sig_handle
);
74 logfile
= "/tmp/recv-announce.log";
78 if (open(logfile
, O_WRONLY
| O_CREAT
| O_APPEND
, 0660) < 0) {
87 chat tmp
[MAX_HOSTNAMELEN
];
89 memset(buf
, '\0', RECV_BUF_SIZE
);
90 memset(&R
, '\0', len
= sizeof(R
));
92 if (recvfrom(0, buf
, RECV_BUF_SIZE
, 0, (sockaddr
*)&R
, &len
) < 0) {
97 memcpy(ip
, &R
.sin_addr
.s_addr
, 4);
98 hp
= gethostbyaddr(ip
, 4, AF_INET
);
100 printf("==============================================================================\n");
101 printf("Received from %s [%s]\n",
102 ipa
.toStr(tmp
,MAX_HOSTNAMELEN
),
103 (hp
&& hp
->h_name
) ? hp
->h_name
: "Unknown");