summaryrefslogtreecommitdiff
path: root/peerdemo
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2018-02-25 21:50:18 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2018-02-25 21:50:18 +0100
commitdd6c37c13dbafadd0d00c4c55e8e56e24829fa61 (patch)
treec2cb8f41efb907cc5c9bb973e13341543e5a0362 /peerdemo
parente4af94d3f938fdbae91d010c8120794d4558b83f (diff)
downloadvdr-dd6c37c13dbafadd0d00c4c55e8e56e24829fa61.tar.gz
vdr-dd6c37c13dbafadd0d00c4c55e8e56e24829fa61.tar.bz2
Added options for name and port
Diffstat (limited to 'peerdemo')
-rwxr-xr-xpeerdemo31
1 files changed, 19 insertions, 12 deletions
diff --git a/peerdemo b/peerdemo
index a80a59b9..3f0d5b19 100755
--- a/peerdemo
+++ b/peerdemo
@@ -13,30 +13,37 @@ use Getopt::Std;
use IO::Socket;
use IO::Select;
+$DefaultSvdrpPort = 6419;
+$DefaultSvdrpName = "peerdemo";
+
$Usage = qq{
Usage: $0 options
-Options: -v be verbose
+Options: -n name use the given VDR name (default: $DefaultSvdrpName)
+ -p port use the given TCP port (default: $DefaultSvdrpPort)
+ -v be verbose
};
-die $Usage if (!getopts("cv"));
+die $Usage if (!getopts("n:p:v"));
+$Name = $opt_n || $DefaultSvdrpName;
+$Port = $opt_p || $DefaultSvdrpPort;
$Verbose = $opt_v || 0;
-$SvdrpPort = 6419;
-$MyName = "peerdemo";
-
# Open TCP and UDP sockets:
-$TcpSocket = new IO::Socket::INET(Listen => 5, LocalPort => $SvdrpPort, Proto => "tcp", ReusePort => 1) || die "$!";
-$UdpSocket = new IO::Socket::INET( LocalPort => $SvdrpPort, Proto => "udp", ReusePort => 1) || die "$!";
+$TcpPort = $Port;
+$UdpPort = $DefaultSvdrpPort;
+
+$TcpSocket = new IO::Socket::INET(Listen => 5, LocalPort => $TcpPort, Proto => "tcp", ReusePort => 1) || die "$!";
+$UdpSocket = new IO::Socket::INET( LocalPort => $UdpPort, Proto => "udp", ReusePort => 1) || die "$!";
$SvdrpSelect = new IO::Select($TcpSocket);
setsockopt($UdpSocket, SOL_SOCKET, SO_RCVTIMEO, pack('L!L!', 0, 1000)); # 1ms timeout on UDP socket
# Send UDP broadcast:
-$BcastSocket = new IO::Socket::INET(PeerAddr => '255.255.255.255', PeerPort => $SvdrpPort, Proto => "udp", Broadcast => 1) || die "$!";
-$BcastMsg = "SVDRP:discover name:$MyName port:6419 vdrversion:20309 apiversion:20309 timeout:300";
+$BcastSocket = new IO::Socket::INET(PeerAddr => '255.255.255.255', PeerPort => $UdpPort, Proto => "udp", Broadcast => 1) || die "$!";
+$BcastMsg = "SVDRP:discover name:$Name port:$TcpPort vdrversion:20309 apiversion:20309 timeout:300";
Log('>', $BcastSocket, $BcastMsg);
print($BcastSocket $BcastMsg);
$BcastSocket->close();
@@ -45,7 +52,7 @@ $BcastSocket->close();
while (1) {
if ($UdpSocket->recv($Request, 1024)) {
- if (Extract($Request, "name") ne $MyName) {
+ if (Extract($Request, "name") ne $Name) {
Log('<', $UdpSocket, $Request);
ReportVDR($Request, $UdpSocket->peerhost());
}
@@ -57,7 +64,7 @@ while (1) {
my $new = $TcpSocket->accept();
Log('<', $new, "incoming TCP connection");
# send mandatory response to simulate an SVDRP host:
- my $Prompt = "220 $MyName SVDRP VideoDiskRecorder 2.3.9; Wed Nov 29 17:00:29 2017; ISO-8859-1";
+ my $Prompt = "220 $Name SVDRP VideoDiskRecorder 2.3.9; Wed Nov 29 17:00:29 2017; ISO-8859-1";
Log('>', $new, $Prompt);
print($new "$Prompt\n");
# add incoming connection to select:
@@ -80,7 +87,7 @@ while (1) {
Reply($fh, "250 OK");
}
elsif ($Request =~ /^PING/) {
- Reply($fh, "250 $MyName is alive");
+ Reply($fh, "250 $Name is alive");
}
elsif ($Request =~ /^QUIT/) {
# close connection: