I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2010-09-23 14:45:20.679533-07 by skaraluk
I can't send a 200 Response for an Option Request
Hi everyone, I'm new here and I'm new too with telephony, so maybe my problem is that I can't understand what I'm doing. Anyway, I have this code trying to make a call to an ip-telephone in my network. I'm using Net::SIP:Simple to do this, and after a loong time using the test and error method to write the program finally I can send a Invite Request without an error, but the PBX send me now an Option Request, when I send a 200 Ok Response to the PBX it sends me the same Request again, so as you can see I'm in a dead point now and I don't know what to do.

This is the code:
#!/usr/bin/perl use IO::Socket::INET; use Net::SIP::Leg; use Net::SIP::Simple; use Net::SIP::Simple::Call; use Net::SIP::Simple::RTP; use Net::SIP::Dispatcher; use Net::SIP::Dispatcher::Eventloop; use Net::SIP::Endpoint; use Net::SIP::Endpoint::Context; use Net::SIP::Packet; use Net::SIP::Request; $| = 1; my $ip_me = 'xxx.xxx.xx.xx'; #The server where the code is executed my $ip_pbx = 'yyy.yyy.yy.yy'; #The PBX my $ip_to = 'zzz.zzz.zz.zzz'; #The phone ip # create new socket and leg print 'CREATING SOCKET AND LEG... '; my $sock_tel_1 = IO::Socket::INET->new(LocalAddr => $ip_me, PeerAddr => $ip_pbx, PeerPort => '5060' +, Proto => 'udp') or die "Can't bind : $@\n"; my $leg_tel_1 = Net::SIP::Leg->new( sock => $sock_tel_1); print 'OK'.$/; # create new rtp print 'CREATING RTP... '; my $echo_10 = Net::SIP::Simple->rtp( 'media_recv_echo', 'output.pcmu-8000' ); print 'OK'.$/; # create new agent print 'CREATING AGENT... '; my $ua = Net::SIP::Simple->new( registrar => $ip_pbx, domain => 'mydomain.com', from => 'user@mydomain.com', leg => $leg_tel_1, auth => ['user','password'] ); print $ua->error.' '; print 'OK'.$/; # get endpoint print 'GETTING ENDPOINT... '; my $endpoint = $ua->{endpoint}; print 'OK'.$/; # get dispatcher print 'GETTING DISPATCHER... '; my $disp = $ua->{dispatcher}; print 'OK'.$/; # Register agent my $err = ''; print 'TRY TO REGISTER... '; $ua->register(); $err = $ua->error; if ($err ne ''){ print $err.$/; }else{ print 'OK'.$/; } # Invite other party, send anncouncement once connected print 'SEND INVITE... '; my $call = $ua->invite( $ip_to, init_media => $echo_10); $err = $ua->error; if ($err ne ''){ print $err.$/; }else{ print 'OK'.$/; } # Receive response/request print 'RECEIVE REQUEST/RESPONSE... '.$/; my ($packet,$ipport) = $leg_tel_1->receive; print $packet->as_string.$/; print 'OK'.$/; # create a new context; print 'CREATE CONTEXT... '; $ctx = Net::SIP::Endpoint::Context->new( incoming => 1, from => scalar( $packet->get_header( 'from' )), to => scalar( $packet->get_header( 'to' )), remote_contact => scalar( $packet->get_header( 'contact' )), callid => scalar( $packet->get_header( 'call-id' )), via => [ $packet->get_header( 'via' ) ], ); print 'OK'.$/; # Create and send Response my $response = $packet->create_response( '200','Ok',$call->{options} ); print $response->as_string.$/; $endpoint->new_response( $ctx,$response,$leg_tel_1,$ip_to.':5060' ); # Receive response/request print 'RECEIVE REQUEST/RESPONSE... '.$/; my ($packet,$ipport) = $leg_tel_1->receive; print $packet->as_string.$/; print 'OK'.$/;


And this is the output:
CREATING SOCKET AND LEG... OK CREATING RTP... OK CREATING AGENT... OK GETTING ENDPOINT... OK GETTING DISPATCHER... OK TRY TO REGISTER... OK SEND INVITE... OK RECEIVE REQUEST/RESPONSE... OPTIONS user@xxx.xxx.xx.xx:35350 SIP/2.0 Via: SIP/2.0/UDP yyy.yyy.yy.yy:5060;branch=z9hG4bK06291840;rport From: "asterisk" <sip:asterisk@yyy.yyy.yy.yy>;tag=as43c708cf To: <user@xxx.xxx.xx.xx:35350> Contact: <sip:asterisk@yyy.yyy.yy.yy> Call-ID: 44dae00b34fa36304c11b779127f6c8d@yyy.yyy.yy.yy CSeq: 102 OPTIONS User-Agent: Asterisk PBX Max-Forwards: 70 Date: Thu, 23 Sep 2010 21:09:03 GMT Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY Content-Length: 0 OK CREATE CONTEXT... OK SIP/2.0 200 Ok Accept: application/sdp Accept-encoding: Accept-language: en Allow: INVITE, ACK, CANCEL, OPTIONS, BYE Call-id: 44dae00b34fa36304c11b779127f6c8d@yyy.yyy.yy.yy Cseq: 102 OPTIONS From: "asterisk" <sip:asterisk@yyy.yyy.yy.yy>;tag=as43c708cf Supported: To: <user@xxx.xxx.xx.xx:35350> Via: SIP/2.0/UDP yyy.yyy.yy.yy:5060;branch=z9hG4bK06291840;rport Content-length: 0 RECEIVE REQUEST/RESPONSE... OPTIONS user@xxx.xxx.xx.xx:35350 SIP/2.0 Via: SIP/2.0/UDP yyy.yyy.yy.yy:5060;branch=z9hG4bK0843fb37;rport From: "asterisk" <sip:asterisk@yyy.yyy.yy.yy>;tag=as536fab35 To: <user@xxx.xxx.xx.xx:35350> Contact: <sip:asterisk@yyy.yyy.yy.yy> Call-ID: 37966fe56ee040b40b89626535f0a09c@yyy.yyy.yy.yy CSeq: 102 OPTIONS User-Agent: Asterisk PBX Max-Forwards: 70 Date: Thu, 23 Sep 2010 21:09:14 GMT Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY Content-Length: 0 OK


As you can see, I get the same Request from the PBX.
Pleeeeease I need help with this code, it's breaking my head.
Direct Responses: 12955 | Write a response
Posted on 2010-09-23 22:12:20.972448-07 by noxxi in response to 12954
Re: I can't send a 200 Response for an Option Request
I have no idea why do you make it so complex.
Especially it won't work to use Net::SIP::Simple on one side and than trying to send and receive packets yourself on the other side.
Please have a look at the examples coming with the distribution. What you are trying to accomplish can be done with something like this:
my $ua = Net::SIP::Simple->new... $ua->register(..) $ua->invite(..) $ua->loop

This will take care of replying to OPTION request it gets itself.
Only if you need to do more than simple stuff than you need to have access to the dispatcher, context etc. But then you should not use Net::SIP::Simple any longer, because it's no longer simple.
Direct Responses: 12957 | Write a response
Posted on 2010-09-24 09:28:33.878324-07 by skaraluk in response to 12955
Re: I can't send a 200 Response for an Option Request
You where right, I was making it too complex, this is what I have now:

#!/usr/bin/perl use IO::Socket::INET; use Net::SIP::Leg; use Net::SIP::Simple; use Net::SIP::Simple::Call; use Net::SIP::Simple::RTP; use Net::SIP::Debug qw( Net::SIP*=6 Registrar=1 ); Net::SIP::Debug->level(6); $| = 1; my $ip_me = 'xxx.xxx.xx.xx'; my $ip_pbx = 'yyy.yyy.yy.yy'; my $ip_to = 'zzz.zzz.zz.zzz'; # create new socket and leg print 'CREATING SOCKET AND LEG... '; my $sock_tel_1 = IO::Socket::INET->new(LocalAddr => $ip_me, PeerAddr => $ip_pbx, PeerPort => '5060' +, Proto => 'udp') or die "Can't bind : $@\n"; my $leg_tel_1 = Net::SIP::Leg->new( sock => $sock_tel_1); print 'OK'.$/; # create new rtp print 'CREATING RTP... '; my $echo_10 = Net::SIP::Simple->rtp( 'media_recv_echo', 'output.pcmu-8000' ); print 'OK'.$/; # create new agent print 'CREATING AGENT... '; my $ua = Net::SIP::Simple->new( registrar => $ip_pbx, domain => $ip_pbx, from => 'user', leg => $leg_tel_1, auth => ['user','password'] ); print $ua->error.' '; print 'OK'.$/; # Register agent my $err = ''; print 'TRY TO REGISTER... '; $ua->register(); $err = $ua->error; if ($err ne ''){ print $err.$/; }else{ print 'OK'.$/; } # Invite other party, send anncouncement once connected print 'SEND INVITE... '; $ua->invite( $ip_to, init_media => $echo_10); $err = $ua->error; if ($err ne ''){ print $err.$/; }else{ print 'OK'.$/; } $ua->loop;


It works nice until I get to the SEND INVITE, I send the Invite with the auth and I have in return this:

Net::SIP::Leg::receive[421]: received on xxx.xxx.xx.xx:58878 from yyy.yyy.yy.yy:5060 packet 1285344323.5501 DEBUG:<2> SIP/2.0 488 Not acceptable here 1285344323.5501 DEBUG:<2> Via: SIP/2.0/UDP xxx.xxx.xx.xx:58878;branch=z9hG4bKaceb6f17ba923db0 +403cb902ec43902dead7e6b2c6b52055b20a0140f206b838;received=xxx.xxx.xx.xx 1285344323.5501 DEBUG:<2> From: user <sip:user@yyy.yyy.yy.yy>;tag=7088fe36c469c5fc90bea18501b +7a70b 1285344323.5501 DEBUG:<2> To: zzz.zzz.zz.zzz <sip:zzz.zzz.zz.zzz@yyy.yyy.yy.yy>;tag=as1a6d536 +1 1285344323.5501 DEBUG:<2> Call-ID: 0c41792f3024801835a7404d4354daee 1285344323.5501 DEBUG:<2> CSeq: 2 INVITE 1285344323.5501 DEBUG:<2> User-Agent: Asterisk PBX 1285344323.5501 DEBUG:<2> Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY 1285344323.5501 DEBUG:<2> Contact: <sip:zzz.zzz.zz.zzz@yyy.yyy.yy.yy> 1285344323.5501 DEBUG:<2> Content-Length: 0 1285344323.5501 DEBUG:<2> 1285344323.5501 DEBUG:<2> 1285344323.5520 DEBUG:<2> Net::SIP::Leg::deliver[330]: delivery from xxx.xxx.xx.xx:58878 to yyy.yyy +.yy.yy:5060 OK: 1285344323.5520 DEBUG:<2> ACK sip:zzz.zzz.zz.zzz@yyy.yyy.yy.yy SIP/2.0 1285344323.5520 DEBUG:<2> Via: SIP/2.0/UDP xxx.xxx.xx.xx:58878;branch=z9hG4bKaceb6f17ba923db0 +403cb902ec43902dead7e6b2c6b52055b20a0140f206b838 1285344323.5520 DEBUG:<2> Call-id: 0c41792f3024801835a7404d4354daee 1285344323.5520 DEBUG:<2> Cseq: 2 ACK 1285344323.5520 DEBUG:<2> From: user <sip:user@yyy.yyy.yy.yy>;tag=7088fe36c469c5fc90bea18501b +7a70b 1285344323.5520 DEBUG:<2> To: zzz.zzz.zz.zzz <sip:zzz.zzz.zz.zzz@yyy.yyy.yy.yy>;tag=as1a6d536 +1 1285344323.5520 DEBUG:<2> Content-length: 0 1285344323.5520 DEBUG:<2> 1285344323.5520 DEBUG:<2> OK 1285344324.5350 DEBUG:<2> Net::SIP::Leg::receive[421]: received on xxx.xxx.xx.xx:58878 from yyy.yyy +.yy.yy:5060 packet 1285344324.5350 DEBUG:<2> OPTIONS sip:user@xxx.xxx.xx.xx:58878 SIP/2.0 1285344324.5350 DEBUG:<2> Via: SIP/2.0/UDP yyy.yyy.yy.yy:5060;branch=z9hG4bK42e6c66e;rport 1285344324.5350 DEBUG:<2> From: "asterisk" <sip:asterisk@yyy.yyy.yy.yy>;tag=as22bfe35f 1285344324.5350 DEBUG:<2> To: <sip:user@xxx.xxx.xx.xx:58878> 1285344324.5350 DEBUG:<2> Contact: <sip:asterisk@yyy.yyy.yy.yy> 1285344324.5350 DEBUG:<2> Call-ID: 3adff39b40cfb40f26a74ef83b9e0820@yyy.yyy.yy.yy 1285344324.5350 DEBUG:<2> CSeq: 102 OPTIONS 1285344324.5350 DEBUG:<2> User-Agent: Asterisk PBX 1285344324.5350 DEBUG:<2> Max-Forwards: 70 1285344324.5350 DEBUG:<2> Date: Fri, 24 Sep 2010 16:01:23 GMT 1285344324.5350 DEBUG:<2> Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY 1285344324.5350 DEBUG:<2> Content-Length: 0


After this I just keep receiving the Options Request without sending anything else.
Direct Responses: Write a response