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