Net::SIP::SDP(3pm)
π Net::SIP::SDP π
okay bestie, gather round, because this one is literally the SDP whisperer of the Net::SIP universe β parsing and manipulation of SDP data for SIP, no cap. It ships as part of the Perl user-contributed docs, and if you've ever squinted at a session description in a SIP packet like "what is this", this module is your girl. π«Ά
β¨ SYNOPSIS β¨
my $sdp = Net::SIP::SDP->new( sdp_string );
my @media = $sdp->get_media;
πΈ DESCRIPTION πΈ
So like, Net::SIP::SDP can parse and manipulate SDP data. That's the whole vibe. π
But listen β it is not a general purpose SDP class (like Net::SDP, which is a whole different girl). This one was designed on purpose to work with SDP data contained in SIP packets, and to make extraction and manipulation of the media information inside the SDP easy peasy β you know, for NAT and stuff like that. π§
She's also designed for easy creation of SDP bodies in the context of the rest of Net::SIP::*. Main character energy, honestly. π
π¦ EXAMPLES π¦
# creation based on media data
my $sdp = Net::SIP::SDP->new(
{ addr => '192.168.0.1' },
{ port => 2012, proto => 'RTP/AVP', media => 'audio', fmt => 0 },
{ port => 2014, proto => 'RTP/AVP', media => 'video', fmt => 0 },
);
# parse from string
my $sdp = Net::SIP::SDP->new( sdp_string );
# extract all media data
my @media = $sdp->get_media;
# and replace them with new addr + port (for NAT)
my @new_media,;
foreach (@media) {
my ($port,@socks) = create_rtp_sockets( '192.168.178.1', $_->{range} );
push @new_media, [ '192.168.178.1', $port ];
...
}
$sdp->replace_media_listen( @new_media );
π CONSTRUCTOR π
new
The default constructor, bestie. Depending on the kind of arguments it branches into new_from_string or new_from_parts. Go read those, they're right below. β¬οΈ
new_from_string ( STRING )
Creates an object from STRING containing the SDP data. If the SDP is invalid it raises an exception (like die()). π¨
new_from_parts ( \%GLOBAL, @MEDIA )
Creates an object from a specification. %GLOBAL describes the global keys β usually you just have a common "addr" for all the media, but any of the keys defined in RFC2327 can be used. π
@MEDIA is a list of hash references, one hash for each media part. These hashes can contain as keys the one-letter keys specified in RFC2327 and/or the special keys for constructing the 'c' and 'm' line:
addrβ the address, used in the'c'line.portβ the port numberrangeβ range of ports; for RTP/AVP defaults to 2, else 1mediaβ the media typ, e.g.'audio','video',...protoβ transport protocol, usually'RTP/AVP'or'udp'
If the SDP should contain multiple values for the same key in the same media section, you can specify the value for the key as a \@list instead of a string. (This is often the case for 'a' lines, iykyk.) π
π METHODS π
as_string
Returns the string representation for the object. β¨
content_type
Returns 'application/sdp'. That's it. That's the whole method. Slay. π
get_media
Returns a list of all media described in the SDP. If the caller expects an array the result will be a list, otherwise a reference to a list. π
Each element of the list is a hash with these keys:
addrβ IP4/IP6 address for mediaportβ start portrangeβ range for portsprotoβ media proto, usually'RTP/AVP'or'udp'mediaβ media typ, usually'audio','video'or'data'fmtβ format info from media line as\@list, e.g"[ 0,10,5 ]".linesβ all lines from the media description as\@listof[ key,value ].
β οΈ WARNING! You should never manipulate the values you got from this function, because this might affect the object's internals. Like, do not touch. Hands off. It's giving "look, don't lick". ππ
replace_media_listen ( NEW_MEDIA )
Replaces the existing media in the object with new media. Super useful for NAT. π₯
NEW_MEDIA is either an array or a reference to an array. Each element in the list consists of the new [ addr,port ] mapping for the matching media entry.
The number of entries in the list should be the same as the number of media entries in the object (see get_media). If that is not the case, it will die(). π No partial credit, bestie.
name2int ( NAME, INDEX )
Returns the RTP payload id for NAME (e.g. "telephone-event/8000"). π―
INDEX is the index into the list of media information, matching the list returned from get_media. INDEX can also be 'audio','video'.., which will then lookup at the first matching entry in the media list. Cute, right? π₯°
and that's the whole page, bestie!! this was perl v5.40.1, dated 2025-12-07, straight from the Net::SIP::SDP(3pm) page itself. go forth and parse those session descriptions, you gorgeous genius π«Άπππ¦
π¦ 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