summaryrefslogtreecommitdiff
path: root/svdrpsend.pl
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2001-02-18 14:18:13 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2001-02-18 14:18:13 +0100
commit3586013b8fa8006afdc9624a97e8f14fa111d753 (patch)
treebeec284353d545cbb0e24995634bab99a9be19ba /svdrpsend.pl
parentc464c4f9b9043e2a852c646f644f7a5c4b0e69d7 (diff)
downloadvdr-3586013b8fa8006afdc9624a97e8f14fa111d753.tar.gz
vdr-3586013b8fa8006afdc9624a97e8f14fa111d753.tar.bz2
New SVDRP command MESG; SVDRP can reuse port; SVDRP timeout
Diffstat (limited to 'svdrpsend.pl')
-rwxr-xr-xsvdrpsend.pl57
1 files changed, 57 insertions, 0 deletions
diff --git a/svdrpsend.pl b/svdrpsend.pl
new file mode 100755
index 00000000..5efd504b
--- /dev/null
+++ b/svdrpsend.pl
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+
+use Socket;
+use Getopt::Std;
+
+$Usage = qq{
+Usage: $0 options command...
+
+Options: -d hostname destination hostname (default: localhost)
+ -p port SVDRP port number (default: 2001)
+};
+
+die $Usage if (!$ARGV[0] || !getopts("d:p:"));
+
+$Dest = $opt_d || "localhost";
+$Port = $opt_p || 2001;
+$Cmd = "@ARGV" || Error("missing command");
+
+$Timeout = 10; # max. seconds to wait for response
+
+$SIG{ALRM} = sub { Error("timeout"); };
+alarm($Timeout);
+
+$iaddr = inet_aton($Dest) || Error("no host: $Dest");
+$paddr = sockaddr_in($Port, $iaddr);
+
+$proto = getprotobyname('tcp');
+socket(SOCK, PF_INET, SOCK_STREAM, $proto) || Error("socket: $!");
+connect(SOCK, $paddr) || Error("connect: $!");
+select(SOCK); $| = 1;
+Receive();
+Send($Cmd);
+Send("quit");
+close(SOCK) || Error("close: $!");
+
+sub Send
+{
+ my $cmd = shift || Error("no command to send");
+ print SOCK "$cmd\r\n";
+ Receive();
+}
+
+sub Receive
+{
+ while (<SOCK>) {
+ print STDOUT $_;
+ last if substr($_, 3, 1) ne "-";
+ }
+}
+
+sub Error
+{
+ print STDERR "@_\n";
+ close(SOCK);
+ exit 0;
+}
+