summaryrefslogtreecommitdiffstats
path: root/web/attachments/295596-check_ircd.pl.diff
blob: b3792c406c5765335747f1711abc27fb0adbe377 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
--- 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 (<ClientSocket>) {
+	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);