NAME
Net::SockAddr - Socket address OO-wrapper with Perl and C++ interface.
DESCRIPTION
Supports AF_INET, AF_INET6 and AF_UNIX, can create sockaddrs and pack/unpack ips.
SYNOPSIS
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;
}
C SYNOPSIS
#include <panda/net/sockaddr.h>
using panda::net::SockAddr;
METHODS
new($sa)
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
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.
family()
Returns AF_INET / AF_INET6 / AF_UNIX
is_inet4()
Returns true if family == AF_INET
is_inet6()
Returns true if family == AF_INET6
is_unix()
Returns true if family == AF_UNIX
get()
Returns binary string suitable for passing to Perl's connect()
functions (representing struct sockaddr_in/in6/un, like what Socket::sockaddr_in returns)
operator ""
Object stringifies to "ip:port" for IPv4, "[ip]:port" for IPv6 and "path" for AF_UNIX
operator==, operator!=
Two objects are equal if all properties of their underlying sockaddrs are equal
TYPEMAP
This module exposes panda::net::SockAddr
typemap to use from XS modules. This typemap allows for receiving binary or object-based sockaddr from perl.
#include <xs/net/sockaddr.h>
string myfunc (panda::net::SockAddr sa) {
RETVAL = sa->ip();
}
AUTHORS
Pronin Oleg <syber@crazypanda.ru>, Crazy Panda LTD
Ivan Baidakou <i.baydakov@crazypanda.ru>, Crazy Panda LTD
LICENSE
You may distribute this code under the same terms as Perl itself.