The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::SIP::Leg - Wrapper around Socket for sending and receiving SIP packets

SYNOPSIS

  my $leg = Net::SIP::Leg->new( addr => '192.168.0.2' );
  $leg->deliver( $packet, '192.168.0.5:5060' );

DESCRIPTION

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.

CONSTRUCTOR

new ( %ARGS )

The constructor creates a new object based on the hash %ARGS. The following keys are used from %ARGS:

sock

The socket as IO::Socket::INET object. addr, port and proto will be determined from this object and not from %ARGS.

addr

The local address of the socket.

port

The port of the socket. Defaults to 5060.

proto

The connection protocol, e.g. 'tcp' or 'udp'. Defaults to 'udp'.

contact

Optional contact information which will be added as Record-route header to outgoing requests. If not given it will be created based on addr, port and proto.

If no socket is given with sock it will be created based on addr, port and proto. If this fails the constructur will die().

The constructor will creeate a uniq branch tag for this leg.

METHODS

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 ] )

Delivers Net::SIP::Packet PACKET through the leg $self to ADDR, which is "ip:port". Usually this method will be call from within Net::SIP::Dispatcher.

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.

receive

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.