]> git.ipfire.org Git - thirdparty/squid.git/blame - scripts/AnnounceCache.pl
Source Format Enforcement (#963)
[thirdparty/squid.git] / scripts / AnnounceCache.pl
CommitLineData
090089c4 1#!/usr/local/bin/perl
a151895d 2#
bf95c10a 3## Copyright (C) 1996-2022 The Squid Software Foundation and contributors
a151895d
AJ
4##
5## Squid software is distributed under GPLv2+ license and includes
6## contributions from numerous individuals and organizations.
7## Please see the COPYING and CONTRIBUTORS files for details.
8##
090089c4 9
10$|=1;
11
12$host = (shift || 'sd.cache.nlanr.net');
13$port = (shift || '3131');
14
15require "$ENV{'HARVEST_HOME'}/lib/socket.ph";
16
17$sockaddr = 'S n a4 x8';
18($name, $aliases, $proto) = getprotobyname("udp");
19($fqdn, $aliases, $type, $len, $themaddr) = gethostbyname($host);
20$thissock = pack($sockaddr, &AF_INET, 0, "\0\0\0\0");
21$them = pack($sockaddr, &AF_INET, $port, $themaddr);
22
23chop($me=`uname -a|cut -f2 -d' '`);
24$myip=(gethostbyname($me))[4];
25
26die "socket: $!\n" unless
47f28373 27 socket (SOCK, &AF_INET, &SOCK_DGRAM, $proto);
090089c4 28
29while (<>) {
47f28373
FC
30 chop;
31 $request_template = 'CCnx4x8x4a4a' . length;
32 $request = pack($request_template, 1, 1, 24 + length, $myip, $_);
33 die "send: $!\n" unless
34 send(SOCK, $request, 0, $them);
35 die "recv: $!\n" unless
36 recv(SOCK, $reply, 1024, 0);
37 ($type,$ver,$len,$payload) = unpack('CCnx4x8x4A', $reply);
38 print $CODES[$type] . " $_\n";
090089c4 39}
40