Net::SIP::Leg(3pm)

πŸ’– Net::SIP::Leg πŸ’–

okay bestie, welcome to Net::SIP::Leg β€” straight out of the User Contributed Perl Documentation collection. it's a wrapper around a Socket for sending and receiving SIP packets, and honestly? it's giving infrastructure queen. she's not the one you invite to the party, she's the one who runs the party. πŸŽ€


✨ SYNOPSIS ✨

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

like. two lines. that's the whole vibe. slay. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so a Leg wraps the socket that's used to send and receive packets. that's the whole job description, but she does it so much:

  • she strips the Via header off incoming packets
  • she adds the Via header onto outgoing packets
  • she adds the Record-Route header while forwarding

ngl you usually don't talk to her directly β€” she gets called from Net::SIP::Dispatcher. it's giving "I don't work with the public, I work with the manager." iykyk. πŸ™ˆ


🌸 CONSTRUCTOR 🌸

new ( %ARGS )

the constructor makes you a brand new object based on the hash %ARGS. these are the keys she actually reads from %ARGS, and bestie, there are a lot of them, so buckle up:

  • sock β€” the socket, as an IO::Socket object. addr, port, family and proto get determined from this object, not from %ARGS. this is what's used to create the SocketPool object. no cap.
  • socketpool β€” the socketpool as a Net::SIP::SocketPool-compatible object. > ⚠️ you cannot use this argument together with sock. instead, it determines the master socket by calling master on the SocketPool object you hand it.
  • addr β€” the local IP address of the socket. if you give this but no port, she'll extract the port from addr β€” but only if it's in the "host:port" format. πŸ‘‘
  • host β€” the hostname matching addr. this is used to create default contact info and the Via header. if you don't give it, it defaults to the IP address. why would you use a hostname instead of an IP? it's relevant for TLS, where the name is needed to validate the peer's certificate. so like, not optional energy if you're doing TLS. πŸ”₯
  • port β€” the port of the socket. defaults to 5060.
  • family β€” the family of the socket. if omitted, it gets determined from addr.
  • proto β€” the connection protocol, e.g. 'udp', 'tcp' or 'tls'. defaults to 'udp'.
  • dst β€” the optional fixed target of the leg, as a hash with the keys host, addr, port and family.
  • contact β€” optional contact information that gets added as a Record-route header to outgoing requests, and used inside the Contact header for 200 Responses to INVITE. if you don't give it, it gets created based on addr, port and proto.
  • tls β€” optional arguments used when creating a TLS connection, exactly as expected by IO::Socket::SSL. these get used for both incoming and outgoing TLS connections. typically this involves SSL_cert_file, SSL_key_file and SSL_ca_file or similar. 🧚

if no socket is given via sock, one gets created based on addr, port and proto. and if that fails? the constructor will die(). πŸ’€ dramatic but fair.

oh and β€” the constructor creates a uniq branch tag for this leg. remember that, it comes back later. ⭐


πŸ’… METHODS πŸ’…

  • forward_incoming ( PACKET ) β€” modifies the Net::SIP::Packet PACKET in-place for forwarding. what does that mean? she strips the top Via header in responses, adds the received parameter to the top Via header in requests, handles the difference between forwarding requests to strict or loose routes, and inserts the Record-Route header in requests. multitasking icon behavior. πŸ‘‘
  • forward_outgoing ( PACKET, LEG_IN ) β€” similar to forward_incoming, but gets called on the outgoing leg. LEG_IN is the Net::SIP::Leg where the packet came in (aka where forward_incoming was called). she'll add the Record-Route header and remove herself from Route. self-removal? that's main character energy. 🫢
  • deliver ( PACKET, ADDR, [ CALLBACK ] ) β€” delivers Net::SIP::Packet PACKET through the leg $self to ADDR. ADDR is a hash with the keys host, addr, port and family. usually this method gets called from within Net::SIP::Dispatcher. if the packet was received by the other end β€” which you can only actually know if a reliable protocol like 'tcp' was used β€” she'll call CALLBACK if you provided one. for the callback format, see invoke_callback in Net::SIP::Util. and if the packet could not be delivered, CALLBACK gets invoked with the appropriate errno ($!). while delivering requests, she adds a Via header. ✨
  • receive(PACKET, FROM) β€” called from the dispatcher when the Net::SIP::Packet PACKET was received from FROM. FROM is given as a hash with the keys addr, port, family and proto. this function might process the packet further, or just block it. she returns (PACKET, FROM) in the normal case, or () if blocked. sometimes the answer is just silence bestie 😭
  • check_via ( PACKET ) β€” returns TRUE if the top Via header in the Net::SIP::Packet PACKET contains the branch-tag from $self, otherwise FALSE. this is used to check whether the response came in through the same leg the response was sent through. (there's the uniq branch tag from the constructor! told you she'd come back πŸŽ€)
  • add_via ( PACKET ) β€” adds itself to PACKET as the Via header. insert yourself into the conversation, queen.
  • can_deliver_to ( ADDR|%SPEC ) β€” returns TRUE if the leg can deliver to the address specified by ADDR or %SPEC. ADDR is a full or partial SIP URI. if the caller already has 'proto', 'addr', 'port' and 'family' as separate items, it can call the method with %SPEC instead.
🫠 right now she has no way to check if the leg can deliver to a specific host, because she has no access to the routing information of the underlying OS. so only proto gets checked. that's a real limitation, not a cute quirk.
  • match(%SPEC) β€” checks if the given SPEC matches the leg. this is used from inside get_legs in Net::SIP::Dispatcher to grab all the legs matching specific criteria. the SPEC can contain the keys addr, port and proto, which match the arguments given during construction of the leg or are obtained from the leg's socket. additionally, sub can be used to specify a function which gets called with the leg object and must return true on match only. the method returns true on a full match and false otherwise. vibe check complete. πŸ’–
  • socketpool β€” returns the Net::SIP::SocketPool object associated with the leg.
  • laddr(LEVEL) β€” returns the local address of the socket, either as just the address (LEVEL is 0) or as "ip:port" (higher levels). lowkey level up behavior. 🌈
  • dump β€” returns a string containing information about the leg. used for debugging. the "tell me everything" method, we love her. πŸ”₯

🌟 SEE ALSO 🌟

(no SEE ALSO section in this page, bestie β€” she keeps her circle small πŸ¦‹)


perl v5.40.1 Β· 2025-12-07 Β· that's the version and the date this page was generated, and honestly? a whole mood. go forth and forward those packets, angel. πŸ’œβœ¨

πŸ“¦ where this page comes from