2000-06-20 20:50:37 -04:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
#
|
2016-06-27 00:56:38 -04:00
|
|
|
# Copyright (C) 2000, 2001, 2004, 2007, 2010-2013, 2016 Internet Systems Consortium, Inc. ("ISC")
|
2012-06-28 21:39:47 -04:00
|
|
|
#
|
2016-06-27 00:56:38 -04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2004-03-05 00:14:21 -05:00
|
|
|
|
2011-03-01 18:48:07 -05:00
|
|
|
# $Id: testsock.pl,v 1.20 2011/03/01 23:48:05 tbox Exp $
|
2000-06-22 18:00:42 -04:00
|
|
|
|
2000-06-20 20:50:37 -04:00
|
|
|
# Test whether the interfaces on 10.53.0.* are up.
|
|
|
|
|
|
2000-06-24 19:09:44 -04:00
|
|
|
require 5.001;
|
|
|
|
|
|
|
|
|
|
use Socket;
|
2000-06-24 21:40:05 -04:00
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
|
|
my $port = 0;
|
2001-02-13 19:09:44 -05:00
|
|
|
my $id = 0;
|
|
|
|
|
GetOptions("p=i" => \$port,
|
|
|
|
|
"i=i" => \$id);
|
2000-06-20 20:50:37 -04:00
|
|
|
|
2001-02-13 19:09:44 -05:00
|
|
|
my @ids;
|
|
|
|
|
if ($id != 0) {
|
2001-04-23 21:23:28 -04:00
|
|
|
@ids = ($id);
|
2001-02-13 19:09:44 -05:00
|
|
|
} else {
|
2013-01-09 03:08:59 -05:00
|
|
|
@ids = (1..8);
|
2001-02-13 19:09:44 -05:00
|
|
|
}
|
2001-04-23 21:52:16 -04:00
|
|
|
|
2001-02-13 19:09:44 -05:00
|
|
|
foreach $id (@ids) {
|
2000-06-24 22:30:18 -04:00
|
|
|
my $addr = pack("C4", 10, 53, 0, $id);
|
|
|
|
|
my $sa = pack_sockaddr_in($port, $addr);
|
2000-06-24 19:09:44 -04:00
|
|
|
socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname("tcp"))
|
|
|
|
|
or die "$0: socket: $!\n";
|
2001-04-23 21:52:16 -04:00
|
|
|
setsockopt(SOCK, SOL_SOCKET, SO_REUSEADDR, pack("l", 1));
|
|
|
|
|
|
2000-06-24 19:09:44 -04:00
|
|
|
bind(SOCK, $sa)
|
2000-06-24 22:30:18 -04:00
|
|
|
or die sprintf("$0: bind(%s, %d): $!\n",
|
|
|
|
|
inet_ntoa($addr), $port);
|
2000-06-26 13:53:25 -04:00
|
|
|
close(SOCK);
|
2000-06-20 20:50:37 -04:00
|
|
|
}
|