[pve-devel] [PATCH 2/4] provide Tools::unpack_sockaddr_in46

Wolfgang Bumiller w.bumiller at proxmox.com
Fri May 8 12:24:42 CEST 2015


---
 src/PVE/Tools.pm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index d886a3d..75ca5a6 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -4,6 +4,7 @@ use strict;
 use warnings;
 use POSIX qw(EINTR);
 use IO::Socket::IP;
+use Socket qw(AF_INET AF_INET6);
 use IO::Select;
 use File::Basename;
 use File::Path qw(make_path);
@@ -1043,4 +1044,12 @@ sub fnv31a {
 
 sub fnv31a_hex { return sprintf("%X", fnv31a(@_)); }
 
+sub unpack_sockaddr_in46 {
+    my ($sin) = @_;
+    my $family = Socket::sockaddr_family($sin);
+    my ($port, $host) = ($family == AF_INET6 ? Socket::unpack_sockaddr_in6($sin)
+                                             : Socket::unpack_sockaddr_in($sin));
+    return ($family, $port, $host);
+}
+
 1;
-- 
2.1.4





More information about the pve-devel mailing list