#!/usr/bin/perl # TeleCam UDP client # http://fastolfe.net/features/telecam/ # # Copyright (c) 2000 David Nesting # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published # by the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # # Sends simple 1-byte UDP messages to a listening telecamd daemon. # # Tab stops at 4, please. use strict; use Socket; require 'getopts.pl'; use vars qw{ $opt_h $opt_p }; do Getopts('h:p:'); my $SERVER = $opt_h || "localhost"; my $PORT = $opt_p || 1502; my $message = shift or die "No message to send"; my $times = shift || 1; my $proto = getprotobyname('udp'); my $paddr = sockaddr_in(0, INADDR_ANY); socket(CLIENT, PF_INET, SOCK_DGRAM, $proto) || die "socket: $!"; bind(CLIENT, $paddr) || die "bind: $!"; my $iaddr = inet_aton($SERVER) or die "Unable to resolve hostname: $SERVER"; $paddr = sockaddr_in($PORT, $iaddr); for (1 .. $times) { send(CLIENT, $message, 0, $paddr) || die "Could not send message: $!"; }