From 0b509d832bfd5ecb416d8992b04055b866d534b7 Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Tue, 6 Dec 2016 14:44:57 +0000 Subject: Better fix for handling IPv6 addresses --- lib/CatDap/Controller/user.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/CatDap/Controller/user.pm b/lib/CatDap/Controller/user.pm index 6f8ac9f..4bfc4ed 100644 --- a/lib/CatDap/Controller/user.pm +++ b/lib/CatDap/Controller/user.pm @@ -7,6 +7,7 @@ use Net::LDAP::Extension::SetPassword; use Net::LDAP::Control::PasswordPolicy 0.02; use Crypt::CBC; use Data::UUID; +use Socket qw(inet_pton AF_INET6); #use Data::Dumper; BEGIN {extends 'Catalyst::Controller'; } @@ -118,8 +119,7 @@ sub get_keyprefix : Private { if ($c->req->address =~ m/:/) { # For IPv6 the first 3 can be special and shared by many people, # bytes 6-8 are more interesting - my @address_chunks = split /:/, $c->req->address; - $keyprefix = sprintf( "%02x%02x%02x", splice(@address_chunks, 5, 3)); + $keyprefix = substr(unpack('H*', inet_pton(AF_INET6, $c->req->address)), 10, 6); } else { $keyprefix = sprintf( "%02x%02x%02x", split /\./, $c->req->address ); -- cgit v1.2.1