maxmind / net-works Goto Github PK
View Code? Open in Web Editor NEWSane APIs for IP addresses and networks
Home Page: https://metacpan.org/release/Net-Works/
License: Other
Sane APIs for IP addresses and networks
Home Page: https://metacpan.org/release/Net-Works/
License: Other
For IPv4 RFC5737 defines the blocks 192.0.2.0/24 (TEST-NET-1), 198.51.100.0/24 (TEST-NET-2) and 203.0.113.0/24 (TEST-NET-3).
For IPv6 RFC3849 defines the prefix 2001:db8::/32.
currently ::0/0 which doesn't conform to the IPv6 standard.
I have to work with a product that returns IPv4 networks with the subnet mask in dotted-quad notation and need to parse those.
Can we add support for in- and output of this format without breaking things?
Thanks!
Per RFC3330 and http://en.wikipedia.org/wiki/Reserved_IP_addresses
There are a bunch more we should exclude, both IPv4 and IPv6. See the wikipedia page for details.
This issue affects inheritance for
below is the test code snippet that demonstrates the issue
#####################
{
{
package Foo;
use base qw(Net::Works::Address);
}
TODO: {
my $ip = Foo->new_from_string( string => '1.2.3.4' );
my $next = $ip->next_ip();
isa_ok(
$next,
'Foo',
'return object of child class for value of ->next_ip'
);
my $prev = $ip->previous_ip();
isa_ok(
$prev,
'Foo',
'return object of child class for value of ->previous_ip'
);
}
}
######################
This was noticed during a cv-library pull-request
I expected this to die:
my $net = Net::Works::Network->new_from_string( string => '192.0.2.1/24' );
Instead it automagically changes the object to 192.0.2.0/24 which is neither documented nor enables a user to detect such cases.
I'm using it to validate user input, with NetAddr::IP my code looks like this:
unless ( $netaddr_obj->addr eq $netaddr_obj->network->addr ) {}
which I tried to recreate using Net::Works.
Benchmarks currently show that Net::Works is approximately half as fast as NetAddr::IP which isn't bad without XS.
I'd really like to see this fixed in ns::ac itself. We could probably steal code from namespace::sweep to do this.
I try to install Net::Works::Address inside alpine based docker image, but it failed:
build.log:
cpanm (App::cpanminus) 1.7044 on perl 5.026003 built for x86_64-linux-thread-multi
Work directory is /root/.cpanm/work/1559638667.26004
You have make /usr/bin/make
You have /usr/bin/wget
You have /bin/tar: tar (busybox) 1.29.3
You have /usr/bin/unzip
Searching install () on cpanmetadb ...
install is up to date. (0.01)
Searching Net::Works::Address () on cpanmetadb ...
--> Working on Net::Works::Address
Fetching http://www.cpan.org/authors/id/M/MA/MAXMIND/Net-Works-0.22.tar.gz
-> OK
Unpacking Net-Works-0.22.tar.gz
Entering Net-Works-0.22
Checking configure dependencies from META.json
Checking if you have ExtUtils::MakeMaker 6.58 ... Yes (7.24)
Configuring Net-Works-0.22
Running Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Net::Works
Writing MYMETA.yml and MYMETA.json
-> OK
Checking dependencies from MYMETA.json ...
Checking if you have File::Spec 0 ... Yes (3.67)
Checking if you have Sub::Quote 0 ... Yes (2.006003)
Checking if you have Moo::Role 0 ... Yes (2.003004)
Checking if you have strict 0 ... Yes (1.11)
Checking if you have Carp 0 ... Yes (1.42)
Checking if you have Exporter 0 ... Yes (5.72)
Checking if you have Test::Fatal 0 ... Yes (0.014)
Checking if you have Moo 0 ... Yes (2.003004)
Checking if you have integer 0 ... Yes (1.01)
Checking if you have overload 0 ... Yes (1.28)
Checking if you have ExtUtils::MakeMaker 0 ... Yes (7.24)
Checking if you have Test::More 0.96 ... Yes (1.302164)
Checking if you have Socket 1.99 ... Yes (2.020_03)
Checking if you have Scalar::Util 0 ... Yes (1.46_02)
Checking if you have warnings 0 ... Yes (1.37)
Checking if you have List::AllUtils 0 ... Yes (0.15)
Checking if you have namespace::autoclean 0.16 ... Yes (0.28)
Checking if you have Math::BigInt 0 ... Yes (1.999806)
Checking if you have B 0 ... Yes (1.68)
Checking if you have Math::Int128 0.06 ... Yes (0.22)
Building and testing Net-Works-0.22
cp lib/Net/Works/Network.pm blib/lib/Net/Works/Network.pm
cp lib/Net/Works/Address.pm blib/lib/Net/Works/Address.pm
cp lib/Net/Works.pm blib/lib/Net/Works.pm
cp lib/Net/Works/Role/IP.pm blib/lib/Net/Works/Role/IP.pm
cp lib/Net/Works/Util.pm blib/lib/Net/Works/Util.pm
cp lib/Net/Works/Types.pm blib/lib/Net/Works/Types.pm
Manifying 4 pod documents
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
#
# Versions for all modules listed in MYMETA.json (including optional ones):
#
# === Configure Requires ===
#
# Module Want Have
# ------------------- ---- ----
# ExtUtils::MakeMaker any 7.24
#
# === Build Requires ===
#
# Module Want Have
# ------------------- ---- ----
# ExtUtils::MakeMaker any 7.24
#
# === Test Requires ===
#
# Module Want Have
# ------------------- ---- --------
# B any 1.68
# ExtUtils::MakeMaker any 7.24
# File::Spec any 3.67
# Math::BigInt any 1.999806
# Test::Fatal any 0.014
# Test::More 0.96 1.302164
#
# === Test Recommends ===
#
# Module Want Have
# ---------- -------- --------
# CPAN::Meta 2.120900 2.150010
#
# === Runtime Requires ===
#
# Module Want Have
# -------------------- ---- --------
# Carp any 1.42
# Exporter any 5.72
# List::AllUtils any 0.15
# Math::Int128 0.06 0.22
# Moo any 2.003004
# Moo::Role any 2.003004
# Scalar::Util any 1.46_02
# Socket 1.99 2.020_03
# Sub::Quote any 2.006003
# integer any 1.01
# namespace::autoclean 0.16 0.28
# overload any 1.28
# strict any 1.11
# warnings any 1.37
#
t/00-report-prereqs.t ..... ok
# Failed test 'address objects sort numerically'
# at t/Address.t line 97.
# Structures begin differing at:
# $got->[0] = '::102:304'
# $expected->[0] = '::1.2.3.4'
# Failed test 'address objects sort alphabetically'
# at t/Address.t line 103.
# Structures begin differing at:
# $got->[0] = '::102:304'
# $expected->[0] = '::1.2.3.4'
# Failed test 'new_from_integer(2**32 - 1), IPv6'
# at t/Address.t line 254.
# got: '::ffff:ffff'
# expected: '::255.255.255.255'
# Looks like you failed 3 tests of 41.
t/Address.t ...............
Dubious, test returned 3 (wstat 768, 0x300)
Failed 3/41 subtests
t/author-00-compile.t ..... skipped: these tests are for testing by the author
t/author-eol.t ............ skipped: these tests are for testing by the author
t/author-no-tabs.t ........ skipped: these tests are for testing by the author
t/author-pod-coverage.t ... skipped: these tests are for testing by the author
t/author-pod-spell.t ...... skipped: these tests are for testing by the author
t/author-pod-syntax.t ..... skipped: these tests are for testing by the author
t/author-portability.t .... skipped: these tests are for testing by the author
t/author-synopsis.t ....... skipped: these tests are for testing by the author
t/author-test-version.t ... skipped: these tests are for testing by the author
t/bad-data.t .............. ok
t/Network-splitting.t ..... ok
# Failed test 'network objects sort numerically'
# at t/Network.t line 129.
# Structures begin differing at:
# $got->[0] = '::102:300/124'
# $expected->[0] = '::1.2.3.0/124'
# Failed test 'network objects sort alphabetically'
# at t/Network.t line 135.
# Structures begin differing at:
# $got->[0] = '::102:300/124'
# $expected->[0] = '::1.2.3.0/124'
# Looks like you failed 2 tests of 367.
t/Network.t ...............
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/367 subtests
t/release-cpan-changes.t .. skipped: these tests are for release candidate testing
t/release-tidyall.t ....... skipped: these tests are for release candidate testing
Test Summary Report
-------------------
t/Address.t (Wstat: 768 Tests: 41 Failed: 3)
Failed tests: 11-12, 31
Non-zero exit status: 3
t/Network.t (Wstat: 512 Tests: 367 Failed: 2)
Failed tests: 16-17
Non-zero exit status: 2
Files=16, Tests=1474, 1 wallclock secs ( 0.13 usr 0.01 sys + 0.96 cusr 0.08 csys = 1.18 CPU)
Result: FAIL
Failed 2/16 test programs. 5/1474 subtests failed.
make: *** [Makefile:901: test_dynamic] Error 255
-> FAIL Installing Net::Works::Address failed. See /root/.cpanm/work/1559638667.26004/build.log for details. Retry with --force to force install it.
on debian:
perl -e 'use Net::Works::Address; print(Net::Works::Address->new_from_string(string => "::1.2.3.4")->as_string())'
::1.2.3.4
on alpine:
perl -e 'use Net::Works::Address; print(Net::Works::Address->new_from_string(string => "::1.2.3.4")->as_string());'
::102:304
Env: strawberry per 5.22.0 x64
"D:\devel\perl\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t/*.t
t/00-compile.t ............ ok
t/00-report-prereqs.t ..... #
# Versions for all modules listed in MYMETA.json (including optional ones):
#
# === Configure Requires ===
#
# Module Want Have
# ------------------- ---- -------
# ExtUtils::MakeMaker any 7.04_01
#
# === Build Requires ===
#
# Module Want Have
# ------------------- ---- -------
# ExtUtils::MakeMaker any 7.04_01
#
# === Test Requires ===
#
# Module Want Have
# ------------------- ---- --------
# B any 1.58
# ExtUtils::MakeMaker any 7.04_01
# File::Spec any 3.60
# IO::Handle any 1.35
# IPC::Open3 any 1.18
# Math::BigInt any 1.999710
# Test::Fatal any 0.014
# Test::More 0.96 1.001014
#
# === Test Recommends ===
#
# Module Want Have
# ---------- -------- --------
# CPAN::Meta 2.120900 2.150005
#
# === Runtime Requires ===
#
# Module Want Have
# -------------------- ---- --------
# Carp any 1.38
# Exporter any 5.72
# List::AllUtils any 0.09
# Math::Int128 0.06 0.22
# Moo any 2.000002
# Moo::Role any 2.000002
# Scalar::Util any 1.42
# Socket 1.99 2.021
# Sub::Quote any 2.000002
# integer any 1.01
# namespace::autoclean 0.16 0.28
# overload any 1.26
# strict any 1.09
# warnings any 1.32
#
t/00-report-prereqs.t ..... ok
t/Address.t ............... ok
t/author-eol.t ............ skipped: these tests are for testing by the author
t/author-no-tabs.t ........ skipped: these tests are for testing by the author
t/author-pod-spell.t ...... skipped: these tests are for testing by the author
t/bad-data.t .............. 1/?
# Failed test 'Net::Works::Address->new_from_string() died with 1.1 as string (v4)'
# at t/bad-data.t line 85.
# undef
# doesn't match '(?^:1\.1\ is\ not\ a\ valid\ IPv4\ address)'
# Failed test 'Net::Works::Network->new_from_string() died with 1.1/20 as string (v4)'
# at t/bad-data.t line 97.
# undef
# doesn't match '(?^:1\.1\/20\ is\ not\ a\ valid\ IP\ network)'
# Failed test 'Net::Works::Address->new_from_string() died with 1.1 as string (v4)'
# at t/bad-data.t line 118.
# 'The new() method for Net::Works::Address expects a hash reference or a key/value list. You passed an odd number of arguments
# '
# doesn't match '(?^:1\.1\ is\ not\ a\ valid\ IPv6\ address)'
# Looks like you failed 3 tests of 74.
t/bad-data.t .............. Dubious, test returned 3 (wstat 768, 0x300)
Failed 3/74 subtests
t/Network-splitting.t ..... ok
t/Network.t ............... ok
t/release-cpan-changes.t .. skipped: these tests are for release candidate testing
t/release-pod-coverage.t .. skipped: these tests are for release candidate testing
t/release-pod-syntax.t .... skipped: these tests are for release candidate testing
t/release-portability.t ... skipped: these tests are for release candidate testing
t/release-synopsis.t ...... skipped: these tests are for release candidate testing
t/release-test-version.t .. skipped: these tests are for release candidate testing
t/release-tidyall.t ....... skipped: these tests are for release candidate testing
Test Summary Report
-------------------
t/bad-data.t (Wstat: 768 Tests: 74 Failed: 3)
Failed tests: 27-28, 41
Non-zero exit status: 3
Files=16, Tests=1468, 5 wallclock secs ( 0.31 usr + 0.08 sys = 0.39 CPU)
Result: FAIL
Failed 1/16 test programs. 3/1468 subtests failed.
dmake.exe: Error code 255, while making 'test_dynamic'
FAIL
I'd like to start a discussion about how ::Network objects should stringify in case they are in fact addresses (/32 for IPv4 and /128 for IPv6).
We use ::Network objects for attributes that can be networks but also addresses.
Adding another class for that mixed case would be an option as well as changing the stringification of network objects to remove the subnet mask if all bits are set.
What are your opinions?
The IPv6 RFCs use prefix_length
.
Net::Works::Address->new_from_integer(integer => '42540766416916187176308156905784606720')
returns the address for 255.255.255.255
rather than 2001:db8:1234::
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.