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.
Classes Net::SockAddr::Inet4, Net::SockAddr::Inet6 and Net::SockAddr::Unix contains more specialised constructors from ip/port or path.
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
CONSTANTS
- AF_UNSPEC
- AF_INET
- AF_INET6
- AF_UNIX
-
Only for Unix systems
- INADDR_ANY
-
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
);
- INADDR_LOOPBACK
-
Binary IPv4 address of the loopback interface
- INADDR_BROADCAST
-
Binary IPv4 broadcast address
- INADDR_NONE
-
Binary IPv4 invalid address (usually '255.255.255.255')
- SOCKADDR_ANY
-
IPv4 sockaddr for binding to all interfaces with auto-selected port.
$server
->
bind
(Net::SockAddr::SOCKADDR_ANY);
SOCKADDR_ANY
is the same asNet::SockAddr::Inet4->new(Net::SockAddr::INADDR_ANY, 0);
- SOCKADDR_LOOPBACK
-
IPv4 sockaddr for binding to loopback interface with auto-selected port. The same as
Net::SockAddr::Inet4->new(Net::SockAddr::INADDR_LOOPBACK, 0);
- IN6ADDR_ANY
-
Binary IPv6 address for binding to all interfaces on machine.
- IN6ADDR_LOOPBACK
-
Binary IPv6 address of the loopback interface
- SOCKADDR6_ANY
-
IPv6 sockaddr for binding to all interfaces with auto-selected port.
$server
->
bind
(Net::SockAddr::SOCKADDR6_ANY);
SOCKADDR6_ANY
is the same asNet::SockAddr::Inet6->new(Net::SockAddr::IN6ADDR_ANY, 0);
- SOCKADDR6_LOOPBACK
-
IPV6 sockaddr for binding to loopback interface with auto-selected port. The same as
Net::SockAddr::Inet6->new(Net::SockAddr::IN6ADDR_LOOPBACK, 0);
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>
Ivan Baidakou <i.baydakov@crazypanda.ru>
Crazy Panda LTD
LICENSE
You may distribute this code under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 183:
Unknown directive: =head