package CS::Functions;
use strict;
use IO::Socket::INET;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
require Exporter;
$VERSION = '0.1';
@ISA = qw(Exporter);
@EXPORT = qw(opensocket absgrep);
@EXPORT_OK = qw();
=head1 NAME
CS::Functions - Checkservice shared generic functions
=head1 SYNOPSIS
use CS::Functions;
my $sock = opensocket('localhost', 25);
die "Opening new socket failed\n" unless $sock;
while (<$sock>) { ...} # Read from the socket
my @tmp = ("foo", "bar");
die "Baz not found!\n" unless absgrep(@tmp, "baz");
=head1 DESCRIPTION
I<CS::Functions> provides several functions used by checkservice and
plugings.
=head1 FUNCTIONS
=over 4
=item opensocket(HOST, PORT)
Opens a connection to HOST:PORT. The skalar (socket) that is returned, can be
used to read/write from/to that socket. The skalar is undefined if
opensocket() wasn't successful in opening a connection.
=cut
sub opensocket {
my ($host, $port, $proto) = @_;
my $sock = IO::Socket::INET->new(PeerHost => $host,
PeerPort => $port,
Proto => $proto);
return $sock;
}
=item absgrep(ARRAY, VAL)
Searches for absolute match of value VAL in ARRAY, similar to grep.
Returns number of times VAL was found in the array.
=cut
sub absgrep {
my $val = pop;
return grep(/^$val$/, @_);
}
=head1 BUGS
Not that I know of!
=head1 COPYRIGHT
Copyright (c) 2001 Paul van Tilburg. All rights reserved. This program
is free software; you can redistribute it and/or modify it under the same
terms as Checkservice itself.
=head1 AUTHOR INFORMATION
Paul van Tilburg <paul@linvision.com>, Checkservice homepage:
http://www.linvision.com/checkservice/
=head1 SEE ALSO
L<perl(1)>, L<checkservice(5)>.
=cut
1;
syntax highlighted by Code2HTML, v. 0.9.1