aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterWebInterface/Util/AddressFormat.pm
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2022-07-19 18:28:00 +0200
committerDarkelarious <darkelarious@333networks.com>2022-07-19 18:28:00 +0200
commite9b4cd5fc79ca2d044eba4fed8bf62b138f44249 (patch)
treef396b20f3f415989529484eaacf12314dc72e019 /lib/MasterWebInterface/Util/AddressFormat.pm
parent30adff959ed724224d4a9e1d37b08705f5d62f53 (diff)
downloadWebInterface-Perl-e9b4cd5fc79ca2d044eba4fed8bf62b138f44249.tar.gz
WebInterface-Perl-e9b4cd5fc79ca2d044eba4fed8bf62b138f44249.zip
simplify address format
Diffstat (limited to 'lib/MasterWebInterface/Util/AddressFormat.pm')
-rwxr-xr-xlib/MasterWebInterface/Util/AddressFormat.pm54
1 files changed, 0 insertions, 54 deletions
diff --git a/lib/MasterWebInterface/Util/AddressFormat.pm b/lib/MasterWebInterface/Util/AddressFormat.pm
deleted file mode 100755
index 68cf82c..0000000
--- a/lib/MasterWebInterface/Util/AddressFormat.pm
+++ /dev/null
@@ -1,54 +0,0 @@
-package MasterWebInterface::Util::AddressFormat;
-use strict;
-use warnings;
-use TUWF ':html';
-use Exporter 'import';
-our @EXPORT = qw| from_addr_str
- to_ipv4_str |;
-
-################################################################################
-# parse incoming addresses to IPv6 type used by MasterServer-Qt5 and port
-# parses IPv4 to ::ffff:0.0.0.0 and port
-# this is only a semi-sanity check -- invalid values (like port > 65535)
-# are ignored since they will simply not be found in the database.
-################################################################################
-sub from_addr_str {
- my ($self, $str_addr) = @_;
- my ($ip, $port);
-
- # ::ffff:127.0.0.1:7778
- if ($str_addr =~ /^::ffff:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}$/)
- {
- # ipv4 in ipv6 format is already in the correct format
- return ($ip, $port) = $str_addr =~ m/^(::ffff:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})$/;
- }
-
- # ipv6 (without leading ::) and trailing :7778 / port
- if ($str_addr =~ /^\w{4}:\w{4}:\w{4}:\w{4}:\w{4}:\w{4}:\w{4}:\w{4}:\d{1,5}$/)
- {
- # ipv6 already in the correct format
- return ($ip, $port) = $str_addr =~ m/^(\w{4}:\w{4}:\w{4}:\w{4}:\w{4}:\w{4}:\w{4}:\w{4}):(\d{1,5})$/;
- }
-
- # ipv4 (127.0.0.1:7778)
- if ($str_addr =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}$/)
- {
- # rewrite to ::ffff:127.0.0.1
- ($ip, $port) = $str_addr =~ m/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})$/;
- return ("::ffff:".$ip, $port);
- }
-
- # failure
- return ("0.0.0.0", 0);
-}
-
-# write ::ffff:0.0.0.0 to 0.0.0.0 format if possible
-# return ipv6 addresses untouched
-sub to_ipv4_str
-{
- my ($self, $str_addr) = @_;
- $str_addr =~ s/^::ffff://;
- return $str_addr;
-}
-
-1;