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 anIO::Socketobject.addr,port,familyandprotoget determined from this object, not from%ARGS. this is what's used to create the SocketPool object. no cap.socketpoolβ the socketpool as aNet::SIP::SocketPool-compatible object. > β οΈ you cannot use this argument together withsock. instead, it determines the master socket by callingmasteron 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 fromaddrβ but only if it's in the"host:port"format. πhostβ the hostname matchingaddr. 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 to5060.familyβ the family of the socket. if omitted, it gets determined fromaddr.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 keyshost,addr,portandfamily.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 onaddr,portandproto.tlsβ optional arguments used when creating a TLS connection, exactly as expected byIO::Socket::SSL. these get used for both incoming and outgoing TLS connections. typically this involvesSSL_cert_file,SSL_key_fileandSSL_ca_fileor 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 theNet::SIP::PacketPACKET in-place for forwarding. what does that mean? she strips the top Via header in responses, adds thereceivedparameter 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 toforward_incoming, but gets called on the outgoing leg. LEG_IN is theNet::SIP::Legwhere the packet came in (aka whereforward_incomingwas called). she'll add the Record-Route header and remove herself from Route. self-removal? that's main character energy. π«Άdeliver ( PACKET, ADDR, [ CALLBACK ] )β deliversNet::SIP::PacketPACKET through the leg$selfto ADDR. ADDR is a hash with the keyshost,addr,portandfamily. usually this method gets called from withinNet::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, seeinvoke_callbackinNet::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 theNet::SIP::PacketPACKET was received from FROM. FROM is given as a hash with the keysaddr,port,familyandproto. 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 theNet::SIP::PacketPACKET 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 insideget_legsinNet::SIP::Dispatcherto grab all the legs matching specific criteria. the SPEC can contain the keysaddr,portandproto, which match the arguments given during construction of the leg or are obtained from the leg's socket. additionally,subcan 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 theNet::SIP::SocketPoolobject associated with the leg.laddr(LEVEL)β returns the local address of the socket, either as just the address (LEVEL is0) 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
- ubuntu resolute: libnet-sip-perl 0.840-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libnet-sip-perl 0.840-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms