Net::S...dpoint(3pm)
π Net::SIP::Endpoint(3pm) β the User Contributed Perl Documentation glow-up π
okay bestie, gather round, because we're about to get into Net::SIP::Endpoint and honestly? she's giving main character energy in the SIP world. β¨
πΈ NAME πΈ
Net::SIP::Endpoint β the Endpoint for SIP packets (UAC, UAS). yes, both. she contains multitudes. π
π¦ SYNOPSIS π¦
my $disp = Net::SIP::Dispatcher->new(...);
my $ua = Net::SIP::Endpoint->new($disp);
$ua->register(
from => 'sip:me@example.com',
contact => 'sip:me@192.168.0.1',
registrar => 'sip:192.168.0.10:5060'
);
look at that. dispatcher in, endpoint out, register call, slay. π
π DESCRIPTION π
so this package implements a communication endpoint for SIP. usually that's a phone, but lowkey it can also be a stateful proxy β and the reason it can be a stateful proxy is that it retransmits packets itself. iconic behavior, no cap.
it gives you methods to send arbitrary requests, but also special ones like INVITE or REGISTER. together with Net::SIP::Endpoint::Context, it implements the behavior of the endpoint. they're a duo, fr fr. π«Ά
for incoming requests, the endpoint usually talks to the upper layer, aka the application, which is the interface to the user. think: let it ring for incoming calls, create a response for call accepted if the user picks up the phone on an incoming call, etc. yes, it's the vibe bridge between the network and the human. π
β¨ CONSTRUCTOR β¨
new ( DISPATCHER )β creates a new endpoint and sets it as the receiver for incoming packets at theNet::SIP::DispatcherDISPATCHER. the endpoint will useDISPATCHERfor outgoing packets and will receive incoming packets from it. so basicallyDISPATCHERis her whole support system and we love that for her. π
π METHODS π
π set_application ( APP )
sets APP as the upper layer β like, the layer between the user and the endpoint object $self. APP is either an object which has a method receive or a callback usable by invoke_callback in Net::SIP::Util.
the callback will be invoked with the following arguments:
ENDPOINTβ this is the endpoint itself, e.g.$self. hi bestie, it's you. πCTXβ theNet::SIP::Endpoint::Contextobject for the current call.REQUESTβ theNet::SIP::Requestwhich caused the invocation of the call, e.g. anINVITEon new calls,ACKif the peer established the call,BYEif a call gets closed by the peer, etc.LEGβ theNet::SIP::Legobject where the call came in. together withFROM, it's used to send the response packet back to the peer.FROMβ hash with information about the sender of the request (keys"proto","addr","host","port"and"family"). all five, don't lose any. π
it will call into APP on various incoming requests, like:
π INVITE
in this case APP should ring the user, and while ringing, send "180 Ringing" responses back to the peer, using "ENDPOINT->new_response". after some time it should send a final response (like "200 Ok" if the user accepted the call). the drama of the ringing phase... we've all been there. π
π ACK
this is the sign that the peer established the call. APP should now expect to process incoming RTP data and send RTP data itself. we're live, babes. π₯
π CANCEL, BYE
this informs APP that the call is closed. there's no need for the APP to send a response itself β this was already handled by the endpoint, because there's literally no choice of responses; it can hardly not accept a BYE. like, the BYE is happening whether you like it or not. π
π other requests
like OPTION,.. . these need to be fully handled by APP, e.g. send the appropriate response back using "ENDPOINT->new_response". your problem now, bestie. π«Ά
π invite ( CTX, [ CALLBACK, BODY, %ARGS ] )
creates a new INVITE request and delivers it to the peer. simply calls new_request with the method 'INVITE'. see that method for information for the arguments. yes queen, it's a lil shortcut and she's not sorry. β¨
π register ( %ARGS )
registers the endpoint at a remote registrar. %ARGS needs to be filled as follows:
registrarβ SIP URI of registrar, i.e. anything acceptable tosip_uri2partsfromNet::SIP::Util. Mandatory.fromβ the address to register at the registrar. Mandatory.contactβ the contact, under which"from"will be registered. Mandatory.authβ authorization info, see methodauthorizeinNet::SIP::Requestfor information about the format. Optional.expiresβ expires time. Optional, defaults to900.callbackβ optional callback, e.g. called if requests come in from the peer on the call created for the registration. seeinvoke_callbackinNet::SIP::Utilfor the format.
all other keys will be used as header keys in generating the Net::SIP::Request object. π¦
π new_request ( METHOD, CTX, [ CALLBACK, BODY, %ARGS ] )
METHOD is the uppercase name of the method for which a request should be generated. it can also already be a Net::SIP::Request object, in which case no new request object will be generated, but the provided one delivered. flexible. we stan. π
CTX is either an existing Net::SIP::Endpoint::Context object or a hash reference which will be used to construct one. it contains information about "from" and "to", etc. see constructor in Net::SIP::Endpoint::Context for details. in case of a hash reference, auth and callid from ARGS will be used for the newly constructed context.
if it's an existing CTX, it has to be one which is already managed by this endpoint (e.g. one returned by this method). the endpoint will only manage CTX which it created itself, so that a context cannot be shared between multiple endpoints. possessive? maybe. correct? absolutely. π
CALLBACK is a callback usable by invoke_callback in Net::SIP::Util. if defined, it will be set up as the new default callback for the context.
BODY is a string or an object for the SIP body accepted by the constructor of Net::SIP::Request. see there. π¦
if a response object is given as resp40x in ARGS, it will be used to authorize the newly created request. π
anything else in %ARGS will be used to construct the SIP header. see constructor in Net::SIP::Request.
it returns the Net::SIP::Endpoint::Context object for this request, which can then be used for further requests in the same call. keep it, you'll need it again bestie. π
π cancel_invite ( CTX, REQUEST, CALLBACK )
cancel the given request within the given context (e.g. send CANCEL request). if no REQUEST is given, it will cancel the most recent INVITE. returns the number of requests canceled, e.g. 0 or 1. math queen. β¨
CALLBACK will be used as the callback for the CANCEL request it sends using new_request.
π close_context ( CTX )
delete Net::SIP::Endpoint::Context object CTX from the list of active calls. bye bye, you will not be missed (affectionate). π¦
π receive ( PACKET, LEG, FROM )
called from dispatcher on incoming packets.
PACKET is the incoming Net::SIP::Packet, LEG the Net::SIP::Leg where the packet came in, and FROM the hash with the sender info.
just forwards to receive_request or receive_response based on the type of packet. a lil traffic director, and she's good at it. π
π receive_response ( RESPONSE, LEG, FROM )
handles incoming response packets. tries to find an active call based on the "Call-Id" header in the packet. if none was found, it will drop the packet, otherwise call handle_response on the call context object (Net::SIP::Endpoint::Context). no call id, no entry. rules are rules. π
π receive_request ( REQUEST, LEG, FROM )
handles incoming requests.
if there's already a call context for this Call-Id in the request, it will use it; otherwise it will create a Net::SIP::Endpoint::Context object based on the information in the request ("from", "to", "contact",... ).
calls handle_request on the existing/new context object. π«Ά
π new_response ( CTX, RESPONSE, LEG, ADDR )
delivers Net::SIP::Response packet RESPONSE through the endpoint's dispatcher to ADDR (hash) using Net::SIP::Leg LEG. LEG and ADDR are usually the leg and the sender's address where the associated request came in. π¬
CTX is the context from the call where the associated request came in.
if the response is a 2xx response to a INVITE and no "contact" header is given as required from the RFC, it will add one based on the CTX. helpful icon behavior. β¨
ngl this whole module is giving "quietly does all the hard work while looking cute doing it". and that's the vibe check passed. π
and that's the whole page, bestie β brought to you by perl v5.40.1, dated 2025-12-07, from the User Contributed Perl Documentation collection. periodt. π πβ¨
π¦ 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