--- check_ircd.pl.orig 2002-05-06 22:35:49.000000000 -0700 +++ check_ircd.pl 2008-10-01 01:22:43.496305819 -0700 @@ -43,15 +43,17 @@ # ----------------------------------------------------------------[ Require ]-- -require 5.004; +require 5.6.0; # -------------------------------------------------------------------[ Uses ]-- -use Socket; use strict; +use IO::Socket; +use Sys::Hostname; use Getopt::Long; use vars qw($opt_V $opt_h $opt_t $opt_p $opt_H $opt_w $opt_c $verbose); use vars qw($PROGNAME); +use vars qw($ClientSocket); use lib utils.pm; use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); @@ -60,7 +62,6 @@ sub print_help (); sub print_usage (); sub connection ($$$$); -sub bindRemote ($$$); # -------------------------------------------------------------[ Enviroment ]-- @@ -104,7 +105,7 @@ $answer = "Server $in_remotehost has less than 0 users! Something is Really WRONG!\n"; } - print ClientSocket "quit\n"; + print $ClientSocket "quit\n"; print $answer; exit $ERRORS{$state}; } @@ -140,38 +141,6 @@ "; } -# -------------------------------------------------------------[ bindRemote ]-- - -sub bindRemote ($$$) -{ - my ($in_remotehost, $in_remoteport, $in_hostname) = @_; - 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); - - if (!socket(ClientSocket,AF_INET, 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"}; - } - select(ClientSocket); $| = 1; select(STDOUT); - return \*ClientSocket; -} - # ===================================================================[ MAIN ]== MAIN: @@ -222,24 +191,34 @@ alarm($TIMEOUT); - chomp($hostname = `/bin/hostname`); + $hostname = 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); + + $ClientSocket = IO::Socket::INET->new( + PeerAddr => $remotehost, + PeerPort => $remoteport, + LocalAddr => $hostname, + Proto => "tcp" + ); + + if (! $ClientSocket) { + print "IRCD UNKNOWN: Could not connect socket ($!)\n"; + exit $ERRORS{"UNKNOWN"}; + } - print ClientSocket "NICK $NICK\nUSER $USER_INFO\n"; + print $ClientSocket "NICK $NICK\nUSER $USER_INFO\n"; - while () { + while (<$ClientSocket>) { print "MAIN(debug): default var = $_\n" if $verbose; # DALnet,LagNet,UnderNet etc. Require this! # Replies with a PONG when presented with a PING query. # If a server doesn't require it, it will be ignored. - if (m/^PING (.*)/) {print ClientSocket "PONG $1\n";} + if (m/^PING (.*)/) {print $ClientSocket "PONG $1\n";} alarm(0);