Net::SIP::Leg - Wrapper around Socket for sending and receiving SIP packets
my $leg = Net::SIP::Leg->new( addr => '192.168.0.2' ); $leg->deliver( $packet, '192.168.0.5:5060' );
A Leg wraps the socket which is used to send and receive packets. It provides ways to strip Via header from incoming packets, to add Via header to outgoing packets and to add Record-Route header while forwarding.
It's usually not used directly, but from Net::SIP::Dispatcher.
- new ( %ARGS )
The constructor creates a new object based on the hash %ARGS. The following keys are used from %ARGS:
The socket as IO::Socket::INET object.
protowill be determined from this object and not from %ARGS.
The local address of the socket.
The port of the socket. Defaults to 5060.
The connection protocol, e.g. 'tcp' or 'udp'. Defaults to 'udp'.
Optional contact information which will be added as Record-route header to outgoing requests. If not given it will be created based on
If no socket is given with
sockit will be created based on
proto. If this fails the constructur will
The constructor will creeate a uniq branch tag for this leg.
- forward_incoming ( PACKET )
Modifies the Net::SIP::Packet PACKET in-place for forwarding, e.g strips top Via header in responses, adds received parameter to top Via header in requests, handles the difference between forwarding of requests to strict or loose routes and inserts Record-Route header in requests.
- deliver ( PACKET, ADDR, [ CALLBACK ] )
If the packet was received by the other end (which is only possible to say if a reliable protocol, e.g. 'tcp' was used) it will call CALLBACK if provided. See invoke_callback in Net::SIP::Util for the format of callbacks. If the packet could not be delivered CALLBACK will be invoked with the appropriate errno (
While delivering requests it adds a Via header.
Reads a packet from the socket and returns the Net::SIP::Packet PACKET and the senders ADDR as
"ip:port". If reading failed will return
- check_via ( PACKET )
Returns TRUE if the top Via header in the Net::SIP::Packet PACKET contains the branch-tag from
$self, otherwise FALSE. Used to check if the response came in through the same leg the response was send.
- can_deliver_to ( ADDR )
Returns TRUE if the leg can deliver to ADDR (IP), else FALSE. Rigth now returns TRUE in all cases, because it cannot use the route information from the underlying OS.