Net::SockAddr - Socket address OO-wrapper with Perl and C++ interface.
Supports AF_INET, AF_INET6 and AF_UNIX, can create sockaddrs and pack/unpack ips.
use Net::SockAddr; $sa = Net::SockAddr::Inet4->new("1.2.3.4", 80); $sa = Net::SockAddr::Inet6->new("2001:db8::ae21:ad12", 80); $sa = Net::SockAddr::Unix->new("/tmp/mysock"); connect($sock, $sa->get); $sa = Net::SockAddr->new($connection->getpeername()); if ($sa->is_inet4 or $sa->is_inet6) { say $sa->ip; say $sa->port; } else { # UNIX socket say $sa->path; }
#include <panda/net/sockaddr.h> using panda::net::SockAddr;
Creates SockAddr object from $sa. Return value will be of class Net::SockAddr::Inet4, Net::SockAddr::Inet6 or Net::SockAddr::Unix depending on the $sa.
$sa
$sa may be:
A binary string representing struct sockaddr_in/in6/un (like what Socket::sockaddr_in returns)
A C<Net::SockAddr> object. In this case, copy is created.
If $sa is undefined or contains sockaddr with AF_UNSPEC family, constructor returns undef.
Classes Net::SockAddr::Inet4, Net::SockAddr::Inet6 and Net::SockAddr::Unix contains more specialised constructors from ip/port or path.
Returns AF_INET / AF_INET6 / AF_UNIX
Returns true if family == AF_INET
family == AF_INET
Returns true if family == AF_INET6
family == AF_INET6
Returns true if family == AF_UNIX
family == AF_UNIX
Returns binary string suitable for passing to Perl's connect() functions (representing struct sockaddr_in/in6/un, like what Socket::sockaddr_in returns)
connect()
Object stringifies to "ip:port" for IPv4, "[ip]:port" for IPv6 and "path" for AF_UNIX
Two objects are equal if all properties of their underlying sockaddrs are equal
Only for Unix systems
Binary IPv4 address for binding to all interfaces on machine.
my $sa = Net::SockAddr::Inet4::from_addr(Net::SockAddr::INADDR_ANY, 80); $server->bind($sa);
Binary IPv4 address of the loopback interface
Binary IPv4 broadcast address
Binary IPv4 invalid address (usually '255.255.255.255')
IPv4 sockaddr for binding to all interfaces with auto-selected port.
$server->bind(Net::SockAddr::SOCKADDR_ANY);
SOCKADDR_ANY is the same as
SOCKADDR_ANY
Net::SockAddr::Inet4->new(Net::SockAddr::INADDR_ANY, 0);
IPv4 sockaddr for binding to loopback interface with auto-selected port. The same as
Net::SockAddr::Inet4->new(Net::SockAddr::INADDR_LOOPBACK, 0);
Binary IPv6 address for binding to all interfaces on machine.
Binary IPv6 address of the loopback interface
IPv6 sockaddr for binding to all interfaces with auto-selected port.
$server->bind(Net::SockAddr::SOCKADDR6_ANY);
SOCKADDR6_ANY is the same as
SOCKADDR6_ANY
Net::SockAddr::Inet6->new(Net::SockAddr::IN6ADDR_ANY, 0);
IPV6 sockaddr for binding to loopback interface with auto-selected port. The same as
Net::SockAddr::Inet6->new(Net::SockAddr::IN6ADDR_LOOPBACK, 0);
This module exposes panda::net::SockAddr typemap to use from XS modules. This typemap allows for receiving binary or object-based sockaddr from perl.
panda::net::SockAddr
#include <xs/net/sockaddr.h> string myfunc (panda::net::SockAddr sa) { RETVAL = sa->ip(); }
Net::SockAddr::Inet4
Net::SockAddr::Inet6
Net::SockAddr::Unix
Pronin Oleg <syber@crazypanda.ru>
Ivan Baidakou <i.baydakov@crazypanda.ru>
Crazy Panda LTD
You may distribute this code under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
Unknown directive: =head
To install Net::SockAddr, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::SockAddr
CPAN shell
perl -MCPAN -e shell install Net::SockAddr
For more information on module installation, please visit the detailed CPAN module installation guide.