File: listen.pl

package info (click to toggle)
libnet-sip-perl 0.46-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 720 kB
  • ctags: 328
  • sloc: perl: 7,312; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,121 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use strict;
use Net::SIP qw(:all);
use Getopt::Long qw(:config posix_default bundling);

my $debug;
my $from = 'sip:me@two.example.com';
my $leg = '127.0.0.1:5070';
my $registrar;

GetOptions(
	'd|debug:i' => \$debug,
	'h|help' => sub { usage() },
	'F|from=s' => \$from,
	'L|leg=s' => \$leg,
	'R|registrar=s' => \$registrar,
) || usage( 'bad options' );
Debug->level( $debug || 1 ) if defined $debug;

my $ua = Simple->new(
	from => $from,
	leg => $leg,
	registrar => $registrar,
);
if ( $registrar ) {
	die "Registration failed\n" if ! $ua->register;
	print STDERR "Registered\n";
}


$ua->listen(
	# echo everything back
	init_media => $ua->rtp( 'recv_echo' ),
);
print "Listening...\n";
$ua->loop;


sub usage {
	print STDERR "ERROR: @_\n" if @_;
	print STDERR <<USAGE;

Listen on given address and receive calls, echo RTP back.
Handles multiple calls in parallel.
Usage: $0 options
Options:
 -h|--help    This usage
 -d|--debug   Switch on debugging with optional level
 -F|--from    senders address, default $from
 -L|--leg     Leg to listen on, default $leg
 -R|--registrar   Optional Registrar

USAGE
	exit(2);
}