TT#72350 add proper CLI options support to rtpengine-ctl

Change-Id: Ifc3ef56340c02ac4c43054d7e5243c71160cc90b
changes/71/35971/5
Richard Fuchs 6 years ago
parent dc1daa90ab
commit ac60133799

@ -4,34 +4,28 @@ use strict;
use warnings;
use IO::Socket::INET;
my $num_args = $#ARGV + 1;
if ( ($num_args == 0) or
(($num_args == 1) && (($ARGV[0] eq "--help") or ($ARGV[0] eq "-h"))) )
{
showusage();
exit;
}
use Getopt::Long;
my $argumentstring = "";
my $ip = "127.0.0.1";
my $port = "9900";
my $port = 9900;
for (my $argnum=0; $argnum <= $#ARGV; $argnum++) {
if ($ARGV[$argnum] eq "-ip") {
die "No argument after -ip\n" unless $argnum+1<=$#ARGV;
$argnum = $argnum+1;
$ip = $ARGV[$argnum];
if ($ip =~ s/:(\d)$//) {
$port = $1;
}
} elsif ($ARGV[$argnum] eq "-port") {
die "No argument after -port\n" unless $argnum+1<=$#ARGV;
$argnum = $argnum+1;
$port = $ARGV[$argnum];
} else {
$argumentstring .= "$ARGV[$argnum] ";
}
my $optret = GetOptions(
'help|h' => sub { showusage(); exit 0; },
'ip=s' => \$ip,
'port=i' => \$port,
);
if ($ip =~ s/:(\d+)$//) {
$port = $1;
}
$argumentstring = "@ARGV";
$argumentstring = trim($argumentstring);
if (!$argumentstring || !$optret || $port <= 0 || $port > 65535) {
showusage();
exit 1;
}
# create a connecting socket
@ -48,7 +42,6 @@ $socket->autoflush(1);
setsockopt($socket, SOL_SOCKET, SO_SNDTIMEO, pack('L!L!', 3, 0) ) or die $!;
setsockopt($socket, SOL_SOCKET, SO_RCVTIMEO, pack('L!L!', 3, 0) ) or die $!;
$argumentstring = trim($argumentstring);
my $size = $socket->send("$argumentstring\n");
# receive a response of up to 10MB

Loading…
Cancel
Save