.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Net::Works::Address 3pm" .TH Net::Works::Address 3pm "2019-01-15" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Net::Works::Address \- An object representing a single IP (4 or 6) address .SH "VERSION" .IX Header "VERSION" version 0.22 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Net::Works::Address; \& \& my $ip = Net::Works::Address\->new_from_string( string => \*(Aq192.0.2.1\*(Aq ); \& print $ip\->as_string(); # 192.0.2.1 \& print $ip\->as_integer(); # 3221225985 \& print $ip\->as_binary(); # 4\-byte packed form of the address \& print $ip\->as_bit_string(); # 11000000000000000000001000000001 \& print $ip\->version(); # 4 \& print $ip\->prefix_length(); # 32 \& \& my $next = $ip\->next_ip(); # 192.0.2.2 \& my $prev = $ip\->previous_ip(); # 192.0.2.0 \& \& if ( $next > $ip ) { print $ip\->as_string(); } \& \& my @sorted = sort $next, $prev, $ip; \& \& my $ipv6 = Net::Works::Address\->new_from_string( string => \*(Aq2001:db8::1234\*(Aq ); \& print $ipv6\->as_integer(); # 42540766411282592856903984951653831220 \& \& my $ip_from_int = Net::Works::Address\->new_from_integer( \& integer => "42540766411282592856903984951653831220" \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Objects of this class represent a single \s-1IP\s0 address. It can handle both IPv4 and IPv6 addresses. It provides various methods for getting information about the address, and also overloads the objects so that addresses can be compared as integers. .PP For IPv6, it uses 128\-bit integers (via Math::Int128) to represent the numeric value of an address. .SH "METHODS" .IX Header "METHODS" This class provides the following methods: .SS "Net::Works::Address\->new_from_string( ... )" .IX Subsection "Net::Works::Address->new_from_string( ... )" This method takes a \f(CW\*(C`string\*(C'\fR parameter and an optional \f(CW\*(C`version\*(C'\fR parameter. The \f(CW\*(C`string\*(C'\fR parameter should be a string representation of an \s-1IP\s0 address. .PP The \f(CW\*(C`version\*(C'\fR parameter should be either \f(CW4\fR or \f(CW6\fR, but you don't really need this unless you're trying to force a dotted quad to be interpreted as an IPv6 address or to a force an IPv6 address colon-separated hex number to be interpreted as an IPv4 address. .SS "Net::Works::Address\->new_from_integer( ... )" .IX Subsection "Net::Works::Address->new_from_integer( ... )" This method takes a \f(CW\*(C`integer\*(C'\fR parameter and an optional \f(CW\*(C`version\*(C'\fR parameter. The \f(CW\*(C`integer\*(C'\fR parameter should be an integer representation of an \&\s-1IP\s0 address. .PP The \f(CW\*(C`version\*(C'\fR parameter should be either \f(CW4\fR or \f(CW6\fR. Unlike with strings, you'll need to set the version explicitly to get an IPv6 address. .ie n .SS "$ip\->\fBas_string()\fP" .el .SS "\f(CW$ip\fP\->\fBas_string()\fP" .IX Subsection "$ip->as_string()" Returns a string representation of the address in the same format as inet_ntop, e.g., \*(L"192.0.2.1\*(R", \*(L"::192.0.2.1\*(R", or \*(L"2001:db8::1234\*(R". .ie n .SS "$ip\->\fBas_integer()\fP" .el .SS "\f(CW$ip\fP\->\fBas_integer()\fP" .IX Subsection "$ip->as_integer()" Returns the address as an integer. For IPv6 addresses, this is returned as a Math::Int128 object, regardless of the value. .ie n .SS "$ip\->\fBas_binary()\fP" .el .SS "\f(CW$ip\fP\->\fBas_binary()\fP" .IX Subsection "$ip->as_binary()" Returns the packed binary form of the address (4 or 16 bytes). .ie n .SS "$ip\->\fBas_bit_string()\fP" .el .SS "\f(CW$ip\fP\->\fBas_bit_string()\fP" .IX Subsection "$ip->as_bit_string()" Returns the address as a string of 1's and 0's, like \&\*(L"00000000000000000000000000010000\*(R". .ie n .SS "$ip\->\fBas_ipv4_string()\fP" .el .SS "\f(CW$ip\fP\->\fBas_ipv4_string()\fP" .IX Subsection "$ip->as_ipv4_string()" This returns a dotted quad representation of an address, even if it's an IPv6 address. However, this will die if the address is greater than the max value of an IPv4 address (2**32 \- 1). It's primarily useful for debugging. .ie n .SS "$ip\->\fBversion()\fP" .el .SS "\f(CW$ip\fP\->\fBversion()\fP" .IX Subsection "$ip->version()" Returns a 4 or 6 to indicate whether this is an IPv4 or IPv6 address. .ie n .SS "$ip\->\fBprefix_length()\fP" .el .SS "\f(CW$ip\fP\->\fBprefix_length()\fP" .IX Subsection "$ip->prefix_length()" Returns the prefix length for the \s-1IP\s0 address, which is either 32 (IPv4) or 128 (IPv6). .ie n .SS "$ip\->\fBbits()\fP" .el .SS "\f(CW$ip\fP\->\fBbits()\fP" .IX Subsection "$ip->bits()" An alias for \f(CW\*(C`$ip\->prefix_length()\*(C'\fR. This helps make addresses & network objects interchangeable in some cases. .ie n .SS "$ip\->\fBnext_ip()\fP" .el .SS "\f(CW$ip\fP\->\fBnext_ip()\fP" .IX Subsection "$ip->next_ip()" Returns the numerically next \s-1IP,\s0 regardless of whether or not it's in the same subnet as the current \s-1IP.\s0 .PP This will throw an error if the current \s-1IP\s0 address it the last address in its \&\s-1IP\s0 range. .ie n .SS "$ip\->\fBprevious_ip()\fP" .el .SS "\f(CW$ip\fP\->\fBprevious_ip()\fP" .IX Subsection "$ip->previous_ip()" Returns the numerically previous \s-1IP,\s0 regardless of whether or not it's in the same subnet as the current \s-1IP.\s0 .PP This will throw an error if the current \s-1IP\s0 address it the first address in its \s-1IP\s0 range (address 0). .SH "OVERLOADING" .IX Header "OVERLOADING" This class overloads comparison, allowing you to compare two objects and to sort them (either as numbers or strings). .PP It also overloads stringification to call the \f(CW\*(C`$ip\->as_string()\*(C'\fR method. .SH "AUTHORS" .IX Header "AUTHORS" .IP "\(bu" 4 Dave Rolsky .IP "\(bu" 4 Greg Oschwald .IP "\(bu" 4 Olaf Alders .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2016 by MaxMind, Inc. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.