summaryrefslogtreecommitdiffstats
path: root/web/attachments/293580-check_ircd.pl.patch
blob: 511b719b535e887b1b7a5a4b938563f10062f408 (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
120
121
--- 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";