1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Added options for name and port

This commit is contained in:
Klaus Schmidinger 2018-02-25 21:50:18 +01:00
parent e4af94d3f9
commit dd6c37c13d

View File

@ -13,30 +13,37 @@ use Getopt::Std;
use IO::Socket; use IO::Socket;
use IO::Select; use IO::Select;
$DefaultSvdrpPort = 6419;
$DefaultSvdrpName = "peerdemo";
$Usage = qq{ $Usage = qq{
Usage: $0 options 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; $Verbose = $opt_v || 0;
$SvdrpPort = 6419;
$MyName = "peerdemo";
# Open TCP and UDP sockets: # Open TCP and UDP sockets:
$TcpSocket = new IO::Socket::INET(Listen => 5, LocalPort => $SvdrpPort, Proto => "tcp", ReusePort => 1) || die "$!"; $TcpPort = $Port;
$UdpSocket = new IO::Socket::INET( LocalPort => $SvdrpPort, Proto => "udp", ReusePort => 1) || die "$!"; $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); $SvdrpSelect = new IO::Select($TcpSocket);
setsockopt($UdpSocket, SOL_SOCKET, SO_RCVTIMEO, pack('L!L!', 0, 1000)); # 1ms timeout on UDP socket setsockopt($UdpSocket, SOL_SOCKET, SO_RCVTIMEO, pack('L!L!', 0, 1000)); # 1ms timeout on UDP socket
# Send UDP broadcast: # Send UDP broadcast:
$BcastSocket = new IO::Socket::INET(PeerAddr => '255.255.255.255', PeerPort => $SvdrpPort, Proto => "udp", Broadcast => 1) || die "$!"; $BcastSocket = new IO::Socket::INET(PeerAddr => '255.255.255.255', PeerPort => $UdpPort, Proto => "udp", Broadcast => 1) || die "$!";
$BcastMsg = "SVDRP:discover name:$MyName port:6419 vdrversion:20309 apiversion:20309 timeout:300"; $BcastMsg = "SVDRP:discover name:$Name port:$TcpPort vdrversion:20309 apiversion:20309 timeout:300";
Log('>', $BcastSocket, $BcastMsg); Log('>', $BcastSocket, $BcastMsg);
print($BcastSocket $BcastMsg); print($BcastSocket $BcastMsg);
$BcastSocket->close(); $BcastSocket->close();
@ -45,7 +52,7 @@ $BcastSocket->close();
while (1) { while (1) {
if ($UdpSocket->recv($Request, 1024)) { if ($UdpSocket->recv($Request, 1024)) {
if (Extract($Request, "name") ne $MyName) { if (Extract($Request, "name") ne $Name) {
Log('<', $UdpSocket, $Request); Log('<', $UdpSocket, $Request);
ReportVDR($Request, $UdpSocket->peerhost()); ReportVDR($Request, $UdpSocket->peerhost());
} }
@ -57,7 +64,7 @@ while (1) {
my $new = $TcpSocket->accept(); my $new = $TcpSocket->accept();
Log('<', $new, "incoming TCP connection"); Log('<', $new, "incoming TCP connection");
# send mandatory response to simulate an SVDRP host: # 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); Log('>', $new, $Prompt);
print($new "$Prompt\n"); print($new "$Prompt\n");
# add incoming connection to select: # add incoming connection to select:
@ -80,7 +87,7 @@ while (1) {
Reply($fh, "250 OK"); Reply($fh, "250 OK");
} }
elsif ($Request =~ /^PING/) { elsif ($Request =~ /^PING/) {
Reply($fh, "250 $MyName is alive"); Reply($fh, "250 $Name is alive");
} }
elsif ($Request =~ /^QUIT/) { elsif ($Request =~ /^QUIT/) {
# close connection: # close connection: