--- check_ircd.pl.orig 2008-09-16 12:41:20.000000000 +0200 +++ check_ircd.pl 2008-09-16 12:43:23.000000000 +0200 @@ -1,4 +1,4 @@ -#!/usr/bin/perl -wT +#! /usr/bin/perl -wT # ----------------------------------------------------------------------------- # File Name: check_ircd.pl @@ -50,7 +50,7 @@ use Socket; use strict; use Getopt::Long; -use vars qw($opt_V $opt_h $opt_t $opt_p $opt_H $opt_w $opt_c $verbose); +use vars qw($opt_V $opt_h $opt_t $opt_p $opt_H $opt_w $opt_c $verbose $opt_6); use vars qw($PROGNAME); use lib utils.pm; use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); @@ -60,7 +60,7 @@ sub print_help (); sub print_usage (); sub connection ($$$$); -sub bindRemote ($$$); +sub connectRemote ($$); # -------------------------------------------------------------[ Enviroment ]-- @@ -140,30 +140,36 @@ "; } -# -------------------------------------------------------------[ bindRemote ]-- +# ----------------------------------------------------------[ connectRemote ]-- -sub bindRemote ($$$) +sub connectRemote ($$) { - my ($in_remotehost, $in_remoteport, $in_hostname) = @_; + my ($in_remotehost, $in_remoteport) = @_; my $proto = getprotobyname('tcp'); my $sockaddr; - my $this; - my $thisaddr = gethostbyname($in_hostname); my $that; - my ($name, $aliases,$type,$len,$thataddr) = gethostbyname($in_remotehost); -# ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($in_hostname); + my $pf; + if ($opt_6) { + require Socket6; + $pf = PF_INET6; + unless ($that = (Socket6::getaddrinfo($in_remotehost, $in_remoteport, AF_INET6, SOCK_STREAM, $proto))[3]) { + print "IRCD UNKNOWN: Could not resolve $in_remotehost\n"; + exit $ERRORS{"UNKNOWN"}; + } + } else { + $pf = PF_INET; + unless ($that = gethostbyname($in_remotehost)) { + print "IRCD UNKNOWN: Could not resolve $in_remotehost\n"; + exit $ERRORS{"UNKNOWN"}; + } + $sockaddr = 'S n a4 x8'; + $that = pack($sockaddr, AF_INET, $in_remoteport, $that); + } - if (!socket(ClientSocket,AF_INET, SOCK_STREAM, $proto)) { + if (!socket(ClientSocket, $pf, SOCK_STREAM, $proto)) { print "IRCD UNKNOWN: Could not start socket ($!)\n"; exit $ERRORS{"UNKNOWN"}; } - $sockaddr = 'S n a4 x8'; - $this = pack($sockaddr, AF_INET, 0, $thisaddr); - $that = pack($sockaddr, AF_INET, $in_remoteport, $thataddr); - if (!bind(ClientSocket, $this)) { - print "IRCD UNKNOWN: Could not bind socket ($!)\n"; - exit $ERRORS{"UNKNOWN"}; - } if (!connect(ClientSocket, $that)) { print "IRCD UNKNOWN: Could not connect socket ($!)\n"; exit $ERRORS{"UNKNOWN"}; @@ -183,6 +189,7 @@ ("V" => \$opt_V, "version" => \$opt_V, "h" => \$opt_h, "help" => \$opt_h, "v" => \$verbose,"verbose" => \$verbose, + "6" => \$opt_6, "t=i" => \$opt_t, "timeout=i" => \$opt_t, "w=i" => \$opt_w, "warning=i" => \$opt_w, "c=i" => \$opt_c, "critical=i" => \$opt_c, @@ -190,15 +197,16 @@ "H=s" => \$opt_H, "hostname=s" => \$opt_H); if ($opt_V) { - print_revision($PROGNAME,'$Revision$ '); + print_revision($PROGNAME,'$Revision: 1.3 $ '); exit $ERRORS{'OK'}; } if ($opt_h) {print_help(); exit $ERRORS{'OK'};} ($opt_H) || ($opt_H = shift) || usage("Host name/address not specified\n"); - my $remotehost = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/); + my $remotehost = $1 if ($opt_H =~ /^([-.:A-Za-z0-9]+)$/); ($remotehost) || usage("Invalid host: $opt_H\n"); + $opt_6 ++ if $remotehost =~ /:/; ($opt_w) || ($opt_w = shift) || ($opt_w = 50); my $warn = $1 if ($opt_w =~ /^([0-9]+)$/); @@ -222,13 +230,8 @@ alarm($TIMEOUT); - chomp($hostname = `/bin/hostname`); - $hostname = $1 if ($hostname =~ /([-.a-zA-Z0-9]+)/); - my ($name, $alias, $proto) = getprotobyname('tcp'); - print "MAIN(debug): hostname = $hostname\n" if $verbose; - - print "MAIN(debug): binding to remote host: $remotehost -> $remoteport -> $hostname\n" if $verbose; - my $ClientSocket = &bindRemote($remotehost,$remoteport,$hostname); + print "MAIN(debug): connecting to $remotehost:$remoteport\n" if $verbose; + my $ClientSocket = &connectRemote($remotehost,$remoteport); print ClientSocket "NICK $NICK\nUSER $USER_INFO\n";