]>
git.ipfire.org Git - thirdparty/squid.git/blob - scripts/icp-test.pl
3 ## Copyright (C) 1996-2021 The Squid Software Foundation and contributors
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.
12 # Duane Wessels, Nov 1996
14 # Usage: icp-test.pl host:port ... < url-list
16 # Sends a continuous stream of ICP queries to a set of caches. Stdin is
17 # a list of URLs to request.
25 # just copy this from src/proto.c
54 require 'sys/socket.ph';
56 $sockaddr = 'S n a4 x8';
57 ($name, $aliases, $proto) = getprotobyname("udp");
58 $thissock = pack($sockaddr, &AF_INET
, 0, "\0\0\0\0");
60 chop($me=`uname -a|cut -f2 -d' '`);
61 $myip=(gethostbyname($me))[4];
63 die "socket: $!\n" unless
64 socket (SOCK
, &AF_INET
, &SOCK_DGRAM
, $proto);
68 $flags |= 0x40000000 if ($opt_n);
71 while ($ARGV[0] =~ /([^:]+):(\d+)/) {
74 ($fqdn, $aliases, $type, $len, $themaddr) = gethostbyname($host);
75 $ADDR{$host} = pack('Sna4x8', &AF_INET
, $port, $themaddr);
76 $ip = join('.', unpack('C4', $themaddr));
85 $len = length($_) + 1;
86 $request_template = sprintf 'CCnNNa4a4x4a%d', $len;
87 $request = pack($request_template,
97 foreach $host (keys %ADDR) {
99 @ip = split('\.', $IP{$host});
100 $them = pack('SnC4x8', &AF_INET
, $port, @ip);
101 ($sport,@IP) = unpack('x2nC4x8', $ADDR{$host});
102 die "send: $!\n" unless send(SOCK
, $request, 0, $ADDR{$host});
107 vec($rin,fileno(SOCK
),1) = 1;
108 ($nfound,$timeleft) = select($rout=$rin, undef, undef, 2.0);
109 last if ($nfound == 0);
110 die "recv: $!\n" unless
111 $theiraddr = recv(SOCK
, $reply, 1024, 0);
112 ($junk, $junk, $sourceaddr, $junk) = unpack($sockaddr, $theiraddr);
113 $ip = join('.', unpack('C4', $sourceaddr));
114 ($type,$ver,$len,$flag,$p1,$p2,$payload) = unpack('CCnx4Nnnx4A', $reply);
115 printf "\t%-20.20s %-10.10s",
118 print " hop=$p1" if ($opt_n);
119 print " rtt=$p2" if ($opt_n);