public class IPv6Address extends IPAddress implements java.lang.Iterable<IPv6Address>
You can construct an IPv6 address from a byte array, from a BigInteger, from a Address.SegmentValueProvider
,
from Inet6Address, from MACAddress, from an IPv6AddressSection
of 8 segments, or from an array of 8 IPv6AddressSegment
objects.
To construct one from a String
use
IPAddressString.toAddress()
or IPAddressString.getAddress()
, IPAddressString.toHostAddress()
or IPAddressString.getHostAddress()
Modifier and Type | Class and Description |
---|---|
static interface |
IPv6Address.IPv6AddressConverter |
IPAddress.IPVersion
Address.AddressProvider, Address.SegmentValueProvider
Modifier and Type | Field and Description |
---|---|
static char |
ALTERNATIVE_ZONE_SEPARATOR |
static int |
BIT_COUNT |
static int |
BITS_PER_SEGMENT |
static int |
BYTE_COUNT |
static int |
BYTES_PER_SEGMENT |
static int |
DEFAULT_TEXTUAL_RADIX |
static int |
MAX_VALUE_PER_SEGMENT |
static int |
MIXED_ORIGINAL_SEGMENT_COUNT |
static int |
MIXED_REPLACED_SEGMENT_COUNT |
static java.lang.String |
REVERSE_DNS_SUFFIX |
static java.lang.String |
REVERSE_DNS_SUFFIX_DEPRECATED |
static int |
SEGMENT_COUNT |
static char |
SEGMENT_SEPARATOR |
static char |
UNC_RANGE_SEPARATOR |
static java.lang.String |
UNC_RANGE_SEPARATOR_STR |
static char |
UNC_SEGMENT_SEPARATOR |
static java.lang.String |
UNC_SUFFIX |
static char |
UNC_ZONE_SEPARATOR |
static char |
ZONE_SEPARATOR |
DEFAULT_ADDRESS_CONVERTER, PREFIX_LEN_SEPARATOR
ALTERNATIVE_RANGE_SEPARATOR, ALTERNATIVE_RANGE_SEPARATOR_STR, ALTERNATIVE_SEGMENT_WILDCARD_STR, DEFAULT_ADDRESS_COMPARATOR, HEX_PREFIX, OCTAL_PREFIX, RANGE_SEPARATOR, RANGE_SEPARATOR_STR, SEGMENT_SQL_SINGLE_WILDCARD, SEGMENT_SQL_SINGLE_WILDCARD_STR, SEGMENT_SQL_WILDCARD, SEGMENT_SQL_WILDCARD_STR, SEGMENT_WILDCARD, SEGMENT_WILDCARD_STR
Constructor and Description |
---|
IPv6Address(Address.SegmentValueProvider valueProvider)
Constructs an IPv6 address.
|
IPv6Address(Address.SegmentValueProvider lowerValueProvider,
Address.SegmentValueProvider upperValueProvider)
Constructs an IPv6 address or subnet.
|
IPv6Address(Address.SegmentValueProvider lowerValueProvider,
Address.SegmentValueProvider upperValueProvider,
java.lang.CharSequence zone)
Constructs an IPv6 address.
|
IPv6Address(Address.SegmentValueProvider lowerValueProvider,
Address.SegmentValueProvider upperValueProvider,
java.lang.Integer networkPrefixLength)
Constructs an IPv6 address or subnet.
|
IPv6Address(Address.SegmentValueProvider valueProvider,
java.lang.Integer networkPrefixLength)
Constructs an IPv6 address.
|
IPv6Address(java.math.BigInteger val)
Constructs an IPv6 address.
|
IPv6Address(java.math.BigInteger val,
java.lang.CharSequence zone)
Constructs an IPv6 address.
|
IPv6Address(java.math.BigInteger val,
java.lang.Integer networkPrefixLength)
Constructs an IPv6 address.
|
IPv6Address(java.math.BigInteger val,
java.lang.Integer networkPrefixLength,
java.lang.CharSequence zone)
Constructs an IPv6 address or subnet.
|
IPv6Address(byte[] bytes)
Constructs an IPv6 address.
|
IPv6Address(byte[] bytes,
java.lang.CharSequence zone)
Constructs an IPv6 address.
|
IPv6Address(byte[] bytes,
java.lang.Integer networkPrefixLength)
Constructs an IPv6 address or subnet.
|
IPv6Address(byte[] bytes,
int byteStartIndex,
int byteEndIndex)
Constructs an IPv6 address or subnet.
|
IPv6Address(byte[] bytes,
int byteStartIndex,
int byteEndIndex,
java.lang.Integer networkPrefixLength)
Constructs an IPv6 address or subnet.
|
IPv6Address(java.net.Inet6Address inet6Address)
Constructs an IPv6 address.
|
IPv6Address(IPv6Address prefix,
MACAddress eui)
Constructs an IPv6 address from a modified EUI-64 (Extended Unique Identifier) address section and an IPv6 address section network prefix.
|
IPv6Address(IPv6AddressSection section) |
IPv6Address(IPv6AddressSection section,
java.lang.CharSequence zone) |
IPv6Address(IPv6AddressSection section,
MACAddress eui)
Constructs an IPv6 address from a modified EUI-64 (Extended Unique Identifier) address section and an IPv6 address section network prefix.
|
IPv6Address(IPv6AddressSection section,
MACAddressSection eui)
Constructs an IPv6 address from a modified EUI-64 (Extended Unique Identifier) address and an IPv6 address section network prefix.
|
IPv6Address(IPv6AddressSection section,
MACAddressSection eui,
java.lang.CharSequence zone) |
IPv6Address(IPv6AddressSegment[] segments)
Constructs an IPv6 address or subnet.
|
IPv6Address(IPv6AddressSegment[] segments,
java.lang.CharSequence zone)
Constructs an IPv6 address or a set of addresses.
|
IPv6Address(IPv6AddressSegment[] segments,
java.lang.Integer networkPrefixLength)
Constructs an IPv6 address or a set of addresses.
|
Modifier and Type | Method and Description |
---|---|
IPv6Address |
adjustPrefixBySegment(boolean nextSegment)
Increases or decreases prefix length to the next segment boundary.
|
IPv6Address |
adjustPrefixBySegment(boolean nextSegment,
boolean zeroed)
Increases or decreases prefix length to the next segment boundary.
|
IPv6Address |
adjustPrefixLength(int adjustment)
Increases or decreases prefix length by the given increment.
|
IPv6Address |
adjustPrefixLength(int adjustment,
boolean zeroed)
Increases or decreases prefix length by the given increment.
|
IPv6Address |
applyPrefixLength(int networkPrefixLength)
Applies the given prefix length to create a new segment series.
|
IPv6Address |
assignMinPrefixForBlock()
Constructs an equivalent address with the smallest CIDR prefix possible (largest network),
such that the range of values are a set of subnet blocks for that prefix.
|
IPv6Address |
assignPrefixForSingleBlock()
Returns the equivalent CIDR address with a prefix length for which the address subnet block matches the range of values in this address.
|
IPv6Address |
bitwiseOr(IPAddress mask)
Equivalent to calling
IPAddress.bitwiseOr(IPAddress, boolean) with the second argument as false. |
IPv6Address |
bitwiseOr(IPAddress mask,
boolean retainPrefix)
Does the bitwise disjunction with this address.
|
IPv6Address |
bitwiseOrNetwork(IPAddress mask,
int networkPrefixLength)
Does the bitwise disjunction with this address.
|
boolean |
contains(Address other) |
IPv4Address |
get6to4IPv4Address()
Returns the second and third bytes as an
IPv4Address . |
int |
getBitCount() |
int |
getByteCount()
returns the number of bytes in each of the address components represented by this instance
|
IPv6AddressSegment |
getDivision(int index) |
IPv4Address |
getEmbeddedIPv4Address()
Returns the embedded
IPv4Address in the lowest (least-significant) two segments. |
IPv4Address |
getEmbeddedIPv4Address(int byteIndex)
Produces an IPv4 address from any sequence of 4 bytes in this IPv6 address.
|
IPv6AddressSection |
getHostSection()
Returns the host section of the series.
|
IPv6AddressSection |
getHostSection(int networkPrefixLength)
Returns the host section of the address as indicated by the network prefix length provided.
|
IPv4AddressNetwork |
getIPv4Network() |
java.lang.Iterable<IPv6Address> |
getIterable()
Useful for using an instance in a "for-each loop".
|
IPv6Address |
getLower()
If this represents a series with ranging values, returns a series representing the lower values of the range.
|
IPv6Address |
getLowerNonZeroHost()
Similar to
IPAddressSegmentSeries.getLower() , but will not return a series that has a prefix length and whose host value is zero. |
MACAddressNetwork |
getMACNetwork() |
IPv6AddressNetwork |
getNetwork()
Returns the network object for series of the same version (eg IPv4, IPv6 and MAC each have their own network object)
|
IPv6AddressSection |
getNetworkSection()
Returns the network section of the series if the series has a CIDR network prefix length,
otherwise it returns the entire series as a prefixed series with prefix matching the address bit length.
|
IPv6AddressSection |
getNetworkSection(int networkPrefixLength)
Returns the network section of the series.
|
IPv6AddressSection |
getNetworkSection(int networkPrefixLength,
boolean withPrefixLength)
Returns the network section of the series.
|
IPAddressStringDivisionSeries[] |
getParts(IPAddressSection.IPStringBuilderOptions options)
Returns all the ways of breaking this address down into segments, as selected.
|
IPAddressStringDivisionSeries[] |
getParts(IPv6AddressSection.IPv6StringBuilderOptions options) |
IPv6AddressSection |
getSection()
Returns the address as an address section comprising all segments in the address.
|
IPv6AddressSection |
getSection(int index)
Gets the subsection from the series starting from the given index
|
IPv6AddressSection |
getSection(int index,
int endIndex)
Gets the subsection from the series starting from the given index and ending just before the give endIndex
|
IPv6AddressSegment |
getSegment(int index)
Returns the segment from this series at the given index.
|
int |
getSegmentCount()
Returns the number of segments in this series.
|
IPv6AddressSegment[] |
getSegments()
Returns the segments of this series of segments as an array.
|
IPv6Address |
getUpper()
If this represents a series with ranging values, returns a series representing the upper values of the range
If this represents a series with a single value in each segment, returns this.
|
java.lang.String |
getZone()
The zone or scope id, which is typically appended to an address with a '%', eg fe80::71a3:2b00:ddd3:753f%16
If there is no zone or scope id, returns null
|
int |
hashCode() |
boolean |
hasZone() |
IPv6Address |
increment(long increment)
Returns the series from the subnet that is the given increment upwards into the subnet range,
or if the given increment is negative the given increment downwards into the subnet range,
or if this is just an individual series, it simply adds the increment to this.
|
IPv6Address |
intersect(IPAddress other)
Produces the subnet whose addresses are found in both this and the given subnet argument.
|
boolean |
is6Over4()
Whether the address is 6over4
|
boolean |
is6To4()
Whether the address is IPv6 to IPv4 relay
|
boolean |
isEUI64() |
boolean |
isIPv4Compatible()
Whether the address is IPv4-compatible
|
boolean |
isIPv4Convertible()
Determines whether this address can be converted to IPv4.
|
boolean |
isIPv4Mapped()
Whether the address is IPv4-mapped
::ffff:x:x/96 indicates IPv6 address mapped to IPv4
|
boolean |
isIPv4Translatable() |
boolean |
isIPv6Convertible()
Determines whether an address can be converted to IPv6, if not IPv6 already.
|
boolean |
isIsatap()
Whether the address is ISATAP
|
boolean |
isLinkLocal()
Returns whether the address is link local, whether unicast or multicast.
|
boolean |
isLocal()
Returns true if the address is link local, site local, organization local, administered locally, or unspecified.
|
boolean |
isLoopback() |
boolean |
isMulticast()
Whether the MAC address or IP address or other form of address is multicast.
|
boolean |
isSameAddress(Address other) |
boolean |
isSameAddress(IPAddress other) |
boolean |
isSiteLocal() |
boolean |
isTeredo()
Whether the address is Teredo
|
boolean |
isUniqueLocal() |
boolean |
isWellKnownIPv4Translatable()
Whether the address has the well-known prefix for IPv4 translatable addresses as in rfc 6052 and 6144
|
java.util.Iterator<IPv6Address> |
iterator()
Iterates through the individual segment series.
|
IPv6Address |
mask(IPAddress mask)
Equivalent to calling
IPAddress.mask(IPAddress, boolean) with the second argument as false. |
IPv6Address |
mask(IPAddress mask,
boolean retainPrefix)
Applies the given mask to all addresses represented by this IPAddress.
|
IPv6Address |
maskNetwork(IPAddress mask,
int networkPrefixLength)
Applies the given mask to all addresses represented by this IPAddress while also applying the given prefix length at the same time.
|
IPv6Address[] |
mergePrefixBlocks(IPAddress... addresses)
Merges this with the list of addresses to produce the smallest list of prefix blocks
|
java.util.Iterator<IPv6Address> |
nonZeroHostIterator() |
java.util.Iterator<IPv6Address> |
prefixBlockIterator()
Iterates through the individual prefix blocks.
|
IPv6Address |
removePrefixLength()
Removes the prefix length.
|
IPv6Address |
removePrefixLength(boolean zeroed)
Removes the prefix length.
|
IPv6Address |
removeZone() |
IPv6Address |
replace(int startIndex,
int endIndex,
IPv6Address replacement,
int replacementIndex)
Replaces segments starting from startIndex and ending before endIndex with the same number of segments starting at replacementStartIndex from the replacement section
|
IPv6Address |
reverseBits(boolean perByte)
Returns a new segment series with the bits reversed.
|
IPv6Address |
reverseBytes()
Returns a new segment series with the bytes reversed.
|
IPv6Address |
reverseBytesPerSegment()
Returns a new segment series with the bytes reversed within each segment.
|
IPv6Address |
reverseSegments()
Returns a new segment series with the segments reversed.
|
java.util.Iterator<IPv6AddressSegment[]> |
segmentsIterator()
Iterates through the individual segments.
|
java.util.Iterator<IPv6AddressSegment[]> |
segmentsNonZeroHostIterator() |
IPv6Address |
setPrefixLength(int prefixLength)
Sets the prefix length.
|
IPv6Address |
setPrefixLength(int prefixLength,
boolean zeroed)
Sets the prefix length.
|
IPv6Address[] |
spanWithPrefixBlocks(IPAddress other)
Produces the list of prefix block subnets that span from this series to the given series.
|
IPv6Address[] |
subtract(IPAddress other)
Subtract the given subnet from this subnet, returning an array of subnets for the result (the subnets will not be contiguous so an array is required).
|
IPAddressPartStringCollection |
toAllStringCollection() |
java.lang.String |
toBase85String()
The base 85 string is described by RFC 1924
|
java.lang.String |
toBinaryString()
Writes this address as a single binary value with always the exact same number of characters
|
java.lang.String |
toCanonicalString()
This produces a canonical string.
|
java.lang.String |
toCanonicalWildcardString()
This produces a string similar to the canonical string but avoids the CIDR prefix.
|
java.lang.String |
toCompressedString()
This compresses the maximum number of zeros and/or host segments with the IPv6 compression notation '::'
|
java.lang.String |
toCompressedWildcardString()
This is similar to toNormalizedWildcardString, avoiding the CIDR prefix, but with compression as well.
|
java.lang.String |
toConvertedString()
Returns a mixed string if it represents a convertible IPv4 address, returns the normalized string otherwise.
|
MACAddress |
toEUI(boolean extended) |
java.lang.String |
toFullString()
This produces a string with no compressed segments and all segments of full length,
which is 4 characters for IPv6 segments and 3 characters for IPv4 segments.
|
java.lang.String |
toHexString(boolean with0xPrefix)
Writes this address as a single hexadecimal value with always the exact same number of characters, with or without a preceding 0x prefix.
|
java.net.Inet6Address |
toInetAddress()
Converts the lowest value of this address to an InetAddress
|
IPv4Address |
toIPv4()
If this address is IPv4 convertible, returns that address.
|
IPv6Address |
toIPv6() |
IPv4AddressSection |
toMappedIPv4Segments()
::ffff:x:x/96 indicates IPv6 address mapped to IPv4
|
IPv6Address |
toMaxHost()
Returns the segment series with a host of all ones.
|
IPv6Address |
toMaxHost(int prefixLength)
Produces the series with host values of all one bits for the given prefix length.
|
java.lang.String |
toMixedString() |
java.lang.String |
toNormalizedString()
The normalized string returned by this method is consistent with java.net.Inet6address.
|
java.lang.String |
toNormalizedString(boolean keepMixed,
IPv6AddressSection.IPv6StringOptions params)
Constructs a string representing this address according to the given parameters
|
java.lang.String |
toNormalizedString(IPAddressSection.IPStringOptions params)
Constructs a string representing this address according to the given parameters
|
static java.lang.String |
toNormalizedString(IPv6AddressNetwork network,
Address.SegmentValueProvider lowerValueProvider,
Address.SegmentValueProvider upperValueProvider,
java.lang.Integer prefixLength,
java.lang.CharSequence zone)
Creates the normalized string for an address without having to create the address objects first.
|
java.lang.String |
toNormalizedString(IPv6AddressSection.IPv6StringOptions params) |
java.lang.String |
toNormalizedWildcardString()
This produces a string similar to the normalized string but avoids the CIDR prefix.
|
java.lang.String |
toOctalString(boolean with0Prefix)
Writes this address as a single octal value with always the exact same number of characters, with or without a preceding 0 prefix.
|
IPv6Address |
toPrefixBlock()
Returns the subnet associated with the prefix length of this address.
|
IPv6Address |
toPrefixBlock(int networkPrefixLength)
Returns the segment series of the same length that spans all hosts.
|
java.lang.String |
toPrefixLengthString()
Returns a string with a CIDR network prefix length if this address has a network prefix length.
|
java.lang.String |
toSQLWildcardString()
This is the same as the string from toNormalizedWildcardString except that
it uses
Address.SEGMENT_SQL_WILDCARD instead of Address.SEGMENT_WILDCARD and also uses Address.SEGMENT_SQL_SINGLE_WILDCARD |
IPAddressPartStringCollection |
toStandardStringCollection() |
IPAddressPartStringCollection |
toStringCollection(IPAddressSection.IPStringBuilderOptions opts) |
IPAddressPartStringCollection |
toStringCollection(IPv6AddressSection.IPv6StringBuilderOptions opts) |
java.lang.String |
toSubnetString()
Produces a consistent subnet string that looks like 1.2.*.* or 1:2::/16
In the case of IPv4, this means that wildcards are used instead of a network prefix when a network prefix has been supplied.
|
java.lang.String |
toUNCHostName()
Generates the Microsoft UNC path component for this address
|
java.net.Inet6Address |
toUpperInetAddress()
Converts the highest value of this address to an InetAddress.
|
IPv6Address |
toZeroHost()
Returns the segment series with a host of zero.
|
IPv6Address |
toZeroHost(int prefixLength)
Produces the series with host values of 0 for the given prefix length.
|
getBitCount, getBitsPerSegment, getBlockMaskPrefixLength, getByteCount, getBytesPerSegment, getIPVersion, getMatchesSQLClause, getMatchesSQLClause, getMaxSegmentValue, getNetworkPrefixLength, getNonZeroHostCount, getSegmentCount, includesMaxHost, includesMaxHost, includesZeroHost, includesZeroHost, isAnyLocal, isIPv4, isIPv6, isSingleNetwork, isUnspecified, matches, matchesWithMask, toAddressString, toAllStrings, toCanonicalHostName, toDelimitedSQLStrs, toHostName, toReverseDNSLookupString, toStandardStrings, toStrings
compareTo, containsPrefixBlock, containsSinglePrefixBlock, defaultIpv4Network, defaultIpv6Network, defaultMACNetwork, equals, getBytes, getBytes, getCount, getDivisionCount, getDivisionStrings, getMinPrefixLengthForBlock, getPrefixCount, getPrefixLength, getPrefixLengthForSingleBlock, getSegments, getSegments, getSegmentStrings, getUpperBytes, getUpperBytes, getUpperValue, getValue, includesMax, includesZero, isFullRange, isMax, isMore, isMultiple, isPrefixBlock, isPrefixed, isSinglePrefixBlock, isZero, toString
getSegments, getSegments, getSegmentStrings
containsPrefixBlock, containsSinglePrefixBlock, getDivisionStrings, getMinPrefixLengthForBlock, getPrefixCount, getPrefixLength, getPrefixLengthForSingleBlock, getUpperValue, getValue, isMore, isPrefixBlock, isPrefixed, isSinglePrefixBlock
getDivisionCount
getBytes, getBytes, getCount, getUpperBytes, getUpperBytes, includesMax, includesZero, isFullRange, isMax, isMultiple, isZero
public static final char SEGMENT_SEPARATOR
public static final char ZONE_SEPARATOR
public static final char ALTERNATIVE_ZONE_SEPARATOR
public static final char UNC_SEGMENT_SEPARATOR
public static final char UNC_ZONE_SEPARATOR
public static final char UNC_RANGE_SEPARATOR
public static final java.lang.String UNC_RANGE_SEPARATOR_STR
public static final java.lang.String UNC_SUFFIX
public static final java.lang.String REVERSE_DNS_SUFFIX
public static final java.lang.String REVERSE_DNS_SUFFIX_DEPRECATED
public static final int BITS_PER_SEGMENT
public static final int BYTES_PER_SEGMENT
public static final int SEGMENT_COUNT
public static final int MIXED_REPLACED_SEGMENT_COUNT
public static final int MIXED_ORIGINAL_SEGMENT_COUNT
public static final int BYTE_COUNT
public static final int BIT_COUNT
public static final int DEFAULT_TEXTUAL_RADIX
public static final int MAX_VALUE_PER_SEGMENT
public IPv6Address(IPv6AddressSection section, java.lang.CharSequence zone) throws AddressValueException
section
- zone
- AddressValueException
- if segment count is not 8 or zone is invalidpublic IPv6Address(IPv6AddressSection section) throws AddressValueException
AddressValueException
public IPv6Address(IPv6AddressSegment[] segments) throws AddressValueException
segments
- the address segmentsAddressValueException
- if segment count is not 8public IPv6Address(IPv6AddressSegment[] segments, java.lang.Integer networkPrefixLength) throws AddressValueException
segments
- the address segmentsnetworkPrefixLength
- AddressValueException
- if segment count is not 8AddressValueException
- if network prefix length invalidpublic IPv6Address(IPv6AddressSegment[] segments, java.lang.CharSequence zone) throws AddressValueException
segments
- the address segmentszone
- the zone or scope idAddressValueException
- if segment count is not 8 or the zone invalidpublic IPv6Address(java.net.Inet6Address inet6Address)
inet6Address
- the java.net address objectpublic IPv6Address(byte[] bytes, java.lang.CharSequence zone) throws AddressValueException
The byte array can be a 16 byte IPv6 address, but may have additional zero-valued bytes, or it may be fewer than 16 bytes.
bytes
- the 16 byte IPv6 address in network byte order - if longer than 16 bytes the additional bytes must be zero (and are ignored), if shorter than 16 bytes then the bytes are sign-extended to 16 bytes.AddressValueException
- if bytes not equivalent to a 16 byte addressAddressValueException
- if byte range invalid or zone invalidpublic IPv6Address(byte[] bytes) throws AddressValueException
The byte array can be a 16 byte IPv6 address, but may have additional zero-valued bytes, or it may be fewer than 16 bytes.
bytes
- the 16 byte IPv6 address in network byte order - if longer than 16 bytes the additional bytes must be zero (and are ignored), if shorter than 16 bytes then the bytes are sign-extended to 16 bytes.AddressValueException
- if bytes not equivalent to a 16 byte addresspublic IPv6Address(byte[] bytes, int byteStartIndex, int byteEndIndex) throws AddressValueException
Similar to IPv6Address(byte[])
except that you can specify the start and end of the address in the given byte array.
AddressValueException
- if byte range invalidpublic IPv6Address(byte[] bytes, java.lang.Integer networkPrefixLength) throws AddressValueException
The byte array can be a 16 byte IPv6 address, but may have additional zero-valued bytes, or it may be fewer than 16 bytes.
When networkPrefixLength is non-null, depending on the prefix configuration (see AddressNetwork.getPrefixConfiguration()
,
this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.
bytes
- the 16 byte IPv6 address in network byte order - if longer than 16 bytes the additional bytes must be zero (and are ignored), if shorter than 16 bytes then the bytes are sign-extended to 16 bytes.networkPrefixLength
- the CIDR prefix, which can be null for no prefix lengthAddressValueException
- if bytes not equivalent to a 16 byte addresspublic IPv6Address(byte[] bytes, int byteStartIndex, int byteEndIndex, java.lang.Integer networkPrefixLength) throws AddressValueException
Similar to IPv6Address(byte[], Integer)
except that you can specify the start and end of the address in the given byte array.
AddressValueException
public IPv6Address(java.math.BigInteger val) throws AddressValueException
The byte representation from BigInteger.toByteArray()
is used, and the byte array follows the rules according to IPv6Address(byte[])
.
Either it must be exactly 16 bytes, or if larger then any extra bytes must be significant leading zeros,
or if smaller it is sign-extended to the required 16 byte length.
This means that you can end up with the same address from two different values of BigInteger, one positive and one negative. For instance, -1 and ffffffffffffffffffffffffffffffff are represented by the two's complement byte arrays [ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff] and [0,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff] respectively. Both create the address ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
In fact, the two's complement byte array [ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff] can be shortened to [ff], the former being the sign-extension of the latter. So the byte array [ff] also creates the address ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff.
When using positive integers you end up with the results you expect, the magnitude of the big integer becomes the address.
When ranging over all 16-byte arrays and constructing BigInteger from those arrays, you range over all possible addresses.
val
- must be an IPv6 address value.AddressValueException
- if value is outside the range of potential valuesAddressValueException
- if val is invalidpublic IPv6Address(java.math.BigInteger val, java.lang.Integer networkPrefixLength) throws AddressValueException
The byte representation from BigInteger.toByteArray()
is used, and the byte array follows the rules according to IPv6Address(byte[])
.
Either it must be exactly 16 bytes, or if larger then any extra bytes must be significant leading zeros,
or if smaller it is sign-extended to the required 16 byte length.
When networkPrefixLength is non-null, depending on the prefix configuration (see AddressNetwork.getPrefixConfiguration()
,
this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.
val
- networkPrefixLength
- AddressValueException
- if val is invalidpublic IPv6Address(java.math.BigInteger val, java.lang.CharSequence zone) throws AddressValueException
The byte representation from BigInteger.toByteArray()
is used, and the byte array follows the rules according to IPv6Address(byte[])
.
Either it must be exactly 16 bytes, or if larger then any extra bytes must be significant leading zeros,
or if smaller it is sign-extended to the required 16 byte length.
val
- zone
- AddressValueException
- if val is invalid or if zone is invalidpublic IPv6Address(java.math.BigInteger val, java.lang.Integer networkPrefixLength, java.lang.CharSequence zone) throws AddressValueException
When networkPrefixLength is non-null, depending on the prefix configuration (see AddressNetwork.getPrefixConfiguration()
,
this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.
val
- must be an IPv6 address valuenetworkPrefixLength
- the CIDR prefix length, which can be null for no prefix lengthzone
- the zone or scope idAddressValueException
- if value is outside the range of potential values, or if zone is invalidpublic IPv6Address(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider, java.lang.Integer networkPrefixLength) throws AddressValueException
When networkPrefixLength is non-null, depending on the prefix configuration (see AddressNetwork.getPrefixConfiguration()
,
this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.
lowerValueProvider
- supplies the 2 byte lower values for each segmentupperValueProvider
- supplies the 2 byte upper values for each segmentnetworkPrefixLength
- the CIDR network prefix length, which can be null for no prefixAddressValueException
public IPv6Address(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider)
lowerValueProvider
- supplies the 2 byte lower values for each segmentupperValueProvider
- supplies the 2 byte upper values for each segmentpublic IPv6Address(Address.SegmentValueProvider valueProvider, java.lang.Integer networkPrefixLength) throws AddressValueException
When networkPrefixLength is non-null, depending on the prefix configuration (see AddressNetwork.getPrefixConfiguration()
,
this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.
valueProvider
- supplies the 2 byte value for each segmentnetworkPrefixLength
- the CIDR network prefix length, which can be null for no prefixAddressValueException
public IPv6Address(Address.SegmentValueProvider valueProvider)
valueProvider
- supplies the 2 byte value for each segmentpublic IPv6Address(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider, java.lang.CharSequence zone) throws AddressValueException
lowerValueProvider
- supplies the 2 byte lower values for each segmentupperValueProvider
- supplies the 2 byte upper values for each segmentAddressValueException
- if zone is invalidpublic IPv6Address(IPv6Address prefix, MACAddress eui) throws IncompatibleAddressException
If the supplied MAC section is an 8 byte EUI-64, then it must match the required EUI-64 format of xx-xx-ff-fe-xx-xx with the ff-fe section in the middle. If the supplied section is a 6 byte MAC-48 or EUI-48, then the ff-fe pattern will be inserted.
If the supplied section neither 6 nor 8 bytes, or if the 8-byte section does not have required EUI-64 format of xx-xx-ff-fe-xx-xx,
IncompatibleAddressException
will be thrown.
The constructor will toggle the MAC U/L (universal/local) bit as required with EUI-64.
Only the first 8 bytes (4 segments) of the IPv6Address are used to construct the address.
Any prefix length in the MAC address is ignored, while a prefix length in the IPv6 address is preserved but only up to the first 4 segments.
prefix
- an address from which the first four segments will be used as the same initial segments in the returned addresseui
- IncompatibleAddressException
- if the MACAddress is an 8 byte MAC address incompatible with EUI-64 IPv6 formatpublic IPv6Address(IPv6AddressSection section, MACAddress eui) throws IncompatibleAddressException, AddressValueException
If the supplied MAC section is an 8 byte EUI-64, then it must match the required EUI-64 format of xx-xx-ff-fe-xx-xx with the ff-fe section in the middle. If the supplied section is a 6 byte MAC-48 or EUI-48, then the ff-fe pattern will be inserted.
If the supplied section neither 6 nor 8 bytes, or if the 8-byte section does not have required EUI-64 format of xx-xx-ff-fe-xx-xx,
IncompatibleAddressException
will be thrown.
The constructor will toggle the MAC U/L (universal/local) bit as required with EUI-64.
The IPv6 address section must be 8 bytes.
Any prefix length in the MAC address is ignored, while a prefix length in the IPv6 address is preserved but only up to the first 4 segments.
section
- eui
- IncompatibleAddressException
- if the MACAddress is an 8 byte MAC address incompatible with EUI-64 IPv6 formatAddressValueException
- if the IPv6 section is the wrong size or structurepublic IPv6Address(IPv6AddressSection section, MACAddressSection eui) throws IncompatibleAddressException, AddressValueException
If the supplied address is an 8 byte EUI-64, then it must match the required EUI-64 format of xx-xx-ff-fe-xx-xx with the ff-fe section in the middle. If the supplied address is a 6 byte MAC-48 or EUI-48, then the ff-fe pattern will be inserted.
The constructor will toggle the MAC U/L (universal/local) bit as required with EUI-64.
The IPv6 address section must be 8 bytes.
Any prefix length in the MAC address is ignored, while a prefix length in the IPv6 address is preserved but only up to the first 4 segments.
section
- eui
- IncompatibleAddressException
- if the MACAddress is an 8 byte MAC address incompatible with EUI-64 IPv6 formatAddressValueException
- if the MACAddress or IPv6 sections are the wrong size or structurepublic IPv6Address(IPv6AddressSection section, MACAddressSection eui, java.lang.CharSequence zone) throws IncompatibleAddressException, AddressValueException
section
- eui
- zone
- IncompatibleAddressException
- if the MACAddress is an 8 byte MAC address incompatible with EUI-64 IPv6 formatAddressValueException
- if the MACAddress or IPv6 sections are the wrong size or structure, or if zone is invalidpublic IPv6AddressNetwork getNetwork()
AddressSegmentSeries
getNetwork
in interface AddressSegmentSeries
getNetwork
in interface IPAddressSegmentSeries
getNetwork
in class IPAddress
public MACAddressNetwork getMACNetwork()
public IPv4AddressNetwork getIPv4Network()
public IPv6AddressSection getSection()
IPAddress
getSection
in interface AddressSegmentSeries
getSection
in interface IPAddressSegmentSeries
getSection
in class IPAddress
public IPv6AddressSection getSection(int index)
AddressSegmentSeries
getSection
in interface AddressSegmentSeries
getSection
in interface IPAddressSegmentSeries
getSection
in class IPAddress
public IPv6AddressSection getSection(int index, int endIndex)
AddressSegmentSeries
getSection
in interface AddressSegmentSeries
getSection
in interface IPAddressSegmentSeries
getSection
in class IPAddress
public IPv6AddressSegment getDivision(int index)
getDivision
in interface AddressDivisionSeries
getDivision
in interface AddressStringDivisionSeries
public IPv6AddressSegment getSegment(int index)
AddressSegmentSeries
getSegment
in interface AddressSegmentSeries
getSegment
in interface IPAddressSegmentSeries
public IPv6AddressSegment[] getSegments()
AddressSegmentSeries
AddressSegmentSeries.getSegment(int)
and AddressSegmentSeries.getSegmentCount()
instead when feasible.getSegments
in interface AddressSegmentSeries
getSegments
in interface IPAddressSegmentSeries
public boolean isEUI64()
public MACAddress toEUI(boolean extended)
public IPAddressStringDivisionSeries[] getParts(IPAddressSection.IPStringBuilderOptions options)
IPAddress
public IPAddressStringDivisionSeries[] getParts(IPv6AddressSection.IPv6StringBuilderOptions options)
public int getSegmentCount()
AddressSegmentSeries
getSegmentCount
in interface AddressSegmentSeries
getSegmentCount
in class Address
public int getByteCount()
AddressComponent
getByteCount
in interface AddressComponent
getByteCount
in class IPAddress
public int getBitCount()
getBitCount
in interface AddressItem
getBitCount
in class Address
public IPv6Address getLowerNonZeroHost()
IPAddressSegmentSeries
IPAddressSegmentSeries.getLower()
, but will not return a series that has a prefix length and whose host value is zero.
If this series has no prefix length, returns the same series as IPAddressSegmentSeries.getLower()
.getLowerNonZeroHost
in interface IPAddressSegmentSeries
getLowerNonZeroHost
in class IPAddress
public IPv6Address getLower()
AddressSegmentSeries
getLower
in interface AddressComponent
getLower
in interface AddressSegmentSeries
getLower
in interface IPAddressSegmentSeries
getLower
in class IPAddress
public IPv6Address getUpper()
AddressSegmentSeries
getUpper
in interface AddressComponent
getUpper
in interface AddressSegmentSeries
getUpper
in interface IPAddressSegmentSeries
getUpper
in class IPAddress
public IPv6Address replace(int startIndex, int endIndex, IPv6Address replacement, int replacementIndex)
startIndex
- endIndex
- replacement
- replacementIndex
- java.lang.IndexOutOfBoundsException
public IPv6Address reverseBits(boolean perByte)
AddressSegmentSeries
reverseBits
in interface AddressComponent
reverseBits
in interface AddressSegmentSeries
reverseBits
in interface IPAddressSegmentSeries
reverseBits
in class IPAddress
perByte
- if true, only the bits in each byte are reversed, if false, then all bits in the component are reversedpublic IPv6Address reverseBytes()
AddressSegmentSeries
reverseBytes
in interface AddressComponent
reverseBytes
in interface AddressSegmentSeries
reverseBytes
in interface IPAddressSegmentSeries
reverseBytes
in class IPAddress
public IPv6Address reverseBytesPerSegment()
AddressSegmentSeries
reverseBytesPerSegment
in interface AddressSegmentSeries
reverseBytesPerSegment
in interface IPAddressSegmentSeries
reverseBytesPerSegment
in class IPAddress
public IPv6Address reverseSegments()
AddressSegmentSeries
IncompatibleAddressException
since all address series can reverse their segments.reverseSegments
in interface AddressSegmentSeries
reverseSegments
in interface IPAddressSegmentSeries
reverseSegments
in class IPAddress
public java.util.Iterator<IPv6AddressSegment[]> segmentsNonZeroHostIterator()
segmentsNonZeroHostIterator
in interface IPAddressSegmentSeries
public java.util.Iterator<IPv6AddressSegment[]> segmentsIterator()
AddressSegmentSeries
segmentsIterator
in interface AddressSegmentSeries
segmentsIterator
in interface IPAddressSegmentSeries
public java.util.Iterator<IPv6Address> prefixBlockIterator()
AddressSegmentSeries
AddressSegmentSeries.iterator()
prefixBlockIterator
in interface AddressSegmentSeries
prefixBlockIterator
in interface IPAddressSegmentSeries
prefixBlockIterator
in class IPAddress
public java.util.Iterator<IPv6Address> iterator()
AddressSegmentSeries
iterator
in interface AddressComponent
iterator
in interface AddressSegmentSeries
iterator
in interface IPAddressSegmentSeries
iterator
in interface java.lang.Iterable<IPv6Address>
iterator
in class IPAddress
public java.util.Iterator<IPv6Address> nonZeroHostIterator()
nonZeroHostIterator
in interface IPAddressSegmentSeries
nonZeroHostIterator
in class IPAddress
public java.lang.Iterable<IPv6Address> getIterable()
AddressComponent
AddressComponent.iterator()
directly.getIterable
in interface AddressComponent
getIterable
in interface AddressSegmentSeries
getIterable
in interface IPAddressSegmentSeries
getIterable
in class IPAddress
public IPv6Address increment(long increment)
AddressSegmentSeries
If the subnet has multiple values and the increment exceeds the subnet size, then the amount by which is exceeds the size is added to the upper series of the range (the final iterator value) or is subtracted from the lower series of the range (the first iterator value) if negative.
If the subnet is just a single address values, the series is simply incremented by the given value, positive or negative.
If a subnet has multiple values, a positive increment value is equivalent to the same number of values from the iterator. For instance, a increment of 1 is value 1 from the iterator, an increment of 2 is the second value from the iterator, and so on. A negative increment is equivalent to the same number of values preceding the upper bound of the iterator. For instance, an increment of -1 is the last value from the iterator, and increment of -2 is the second last value, and so on.
Therefore, to get the series just above the highest series of the subnet, use an increment of size:count > 1 ? count + 1 : 1
where count is the subnet size.
To get the series just below the lowest series of the subnet, use an increment of size:-(count > 1 ? count + 1 : 1)
where count is the subnet size.
increment
in interface AddressSegmentSeries
increment
in interface IPAddressSegmentSeries
increment
in class IPAddress
public IPv4Address toIPv4()
This uses isIPv4Convertible()
to determine convertibility, and that uses an instance of IPAddressConverter.DefaultAddressConverter
which uses IPv4-mapped address mappings from rfc 4038.
Override this method and isIPv4Convertible()
if you wish to map IPv6 to IPv4 according to the mappings defined by
in isIPv4Compatible()
, isIPv4Mapped()
, is6To4()
or by some other mapping.
For the reverse mapping, see IPv4Address.toIPv6()
toIPv4
in class IPAddress
IPAddress.isIPv4Convertible()
public IPv6Address toIPv6()
toIPv6
in class IPAddress
IPv6Address
. Otherwise, returns null.IPAddress.isIPv6Convertible()
public boolean isIPv4Convertible()
toIPv4()
to match the conversion.isIPv4Convertible
in class IPAddress
public boolean isIPv6Convertible()
IPAddress
IPv4Address.getIPv4MappedAddress()
You should also override IPAddress.toIPv6()
to match the conversion.
This method returns true for all IPv6 addresses.isIPv6Convertible
in class IPAddress
public IPv4AddressSection toMappedIPv4Segments()
public IPv4Address get6to4IPv4Address()
IPv4Address
.
This can be used for IPv4 or for IPv6 6to4 addresses convertible to IPv4.public IPv4Address getEmbeddedIPv4Address()
IPv4Address
in the lowest (least-significant) two segments.
This is used by IPv4-mapped, IPv4-compatible, ISATAP addresses and 6over4 addressesIPv4Address
public IPv4Address getEmbeddedIPv4Address(int byteIndex)
byteIndex
- the byte index to startjava.lang.IndexOutOfBoundsException
- if the index is less than zero or bigger than 7public boolean isLocal()
IPAddress
public boolean isLinkLocal()
IPAddress
isLinkLocal
in class IPAddress
InetAddress.isLinkLocalAddress()
public boolean isSiteLocal()
InetAddress.isSiteLocalAddress()
public boolean isUniqueLocal()
public boolean isIPv4Mapped()
public boolean isIPv4Compatible()
Inet6Address.isIPv4CompatibleAddress()
public boolean is6To4()
get6to4IPv4Address()
public boolean is6Over4()
public boolean isTeredo()
public boolean isIsatap()
public boolean isIPv4Translatable()
public boolean isWellKnownIPv4Translatable()
public boolean isMulticast()
Address
isMulticast
in class Address
InetAddress.isMulticastAddress()
public boolean isLoopback()
isLoopback
in class IPAddress
InetAddress.isLoopbackAddress()
public IPv6Address intersect(IPAddress other) throws AddressConversionException
IPAddress
This is also known as the conjunction of the two sets of addresses.
If the address is not the same version, the default conversion will be applied using IPAddress.toIPv4()
or IPAddress.toIPv6()
, and it that fails, AddressConversionException
will be thrown.
intersect
in class IPAddress
AddressConversionException
- if the address argument could not be converted to the same address version as thispublic IPv6Address[] subtract(IPAddress other) throws AddressConversionException
IPAddress
Computes the subnet difference, the set of addresses in this address subnet but not in the provided subnet. This is also known as the relative complement of the given argument in this subnet.
If the address is not the same version, the default conversion will be applied using IPAddress.toIPv4()
or IPAddress.toIPv6()
, and it that fails, AddressConversionException
will be thrown.
subtract
in class IPAddress
AddressConversionException
- if the address argument could not be converted to the same address version as thispublic IPv6Address adjustPrefixBySegment(boolean nextSegment)
AddressSegmentSeries
Follows the same rules as AddressSegmentSeries.adjustPrefixLength(int)
:
When prefix length is increased, the bits moved within the prefix become zero.
When a prefix length is decreased, the bits moved outside the prefix become zero.
adjustPrefixBySegment
in interface AddressSegmentSeries
adjustPrefixBySegment
in interface IPAddressSegmentSeries
adjustPrefixBySegment
in class IPAddress
nextSegment
- whether to move prefix to previous or following segment coundarypublic IPv6Address adjustPrefixBySegment(boolean nextSegment, boolean zeroed)
AddressSegmentSeries
adjustPrefixBySegment
in interface AddressSegmentSeries
adjustPrefixBySegment
in interface IPAddressSegmentSeries
adjustPrefixBySegment
in class IPAddress
nextSegment
- whether to move prefix to previous or following segment coundaryzeroed
- whether the bits that move from one side of the prefix to the other become zero or retain their original valuespublic IPv6Address adjustPrefixLength(int adjustment)
IPAddress
When prefix length is increased, the bits moved within the prefix become zero.
When the prefix is extended beyond the segment series boundary, it is removed.
When a prefix length is decreased, the bits moved outside the prefix become zero,
and if the entire host address contains the zero address,
then the resulting address is determined AddressNetwork.getPrefixConfiguration()
.
For example, 1.2.0.0/16 adjusted by -8 becomes 1.0.0.0/8.
1.2.0.0/16 adjusted by 8 becomes 1.2.0.0/24
adjustPrefixLength
in interface AddressSegmentSeries
adjustPrefixLength
in interface IPAddressSegmentSeries
adjustPrefixLength
in class IPAddress
public IPv6Address adjustPrefixLength(int adjustment, boolean zeroed)
AddressSegmentSeries
adjustPrefixLength
in interface AddressSegmentSeries
adjustPrefixLength
in interface IPAddressSegmentSeries
adjustPrefixLength
in class IPAddress
adjustment
- the incrementzeroed
- whether the bits that move from one side of the prefix to the other become zero or retain their original valuespublic IPv6Address setPrefixLength(int prefixLength) throws PrefixLenException
AddressSegmentSeries
If this series has a prefix length, and the prefix length is increased, the bits moved within the prefix become zero.
When the prefix is extended beyond the segment series boundary, it is removed.
The bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.
setPrefixLength
in interface AddressSegmentSeries
setPrefixLength
in interface IPAddressSegmentSeries
setPrefixLength
in class IPAddress
PrefixLenException
AddressSegmentSeries.applyPrefixLength(int)
public IPv6Address setPrefixLength(int prefixLength, boolean zeroed) throws PrefixLenException
AddressSegmentSeries
When the prefix is extended beyond the segment series boundary, it is removed.
setPrefixLength
in interface AddressSegmentSeries
setPrefixLength
in interface IPAddressSegmentSeries
setPrefixLength
in class IPAddress
zeroed
- whether the bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.PrefixLenException
public IPv6Address applyPrefixLength(int networkPrefixLength) throws PrefixLenException
AddressSegmentSeries
Similar to AddressSegmentSeries.setPrefixLength(int)
except that prefix lengths are never increased.
When this series already has a prefix length that is less than or equal to the requested prefix length, this series is returned.
Otherwise the returned series has the given prefix length.
The bits moved outside the prefix will become zero in the returned series.
applyPrefixLength
in interface AddressSegmentSeries
applyPrefixLength
in interface IPAddressSegmentSeries
applyPrefixLength
in class IPAddress
PrefixLenException
AddressSegmentSeries.setPrefixLength(int)
public IPv6Address removePrefixLength()
AddressSegmentSeries
If the series already has a prefix length, the bits outside the prefix become zero.
removePrefixLength
in interface AddressSegmentSeries
removePrefixLength
in interface IPAddressSegmentSeries
removePrefixLength
in class IPAddress
IPAddressSegmentSeries.removePrefixLength(boolean)
public IPv6Address removePrefixLength(boolean zeroed)
AddressSegmentSeries
removePrefixLength
in interface AddressSegmentSeries
removePrefixLength
in interface IPAddressSegmentSeries
removePrefixLength
in class IPAddress
zeroed
- whether the bits outside the prefix become zeropublic IPv6Address toZeroHost()
IPAddressSegmentSeries
The resultant series will have the same prefix length if AddressNetwork.getPrefixConfiguration()
is not AddressNetwork.PrefixConfiguration.ALL_PREFIXED_ADDRESSES_ARE_SUBNETS
,
otherwise it will no longer have a prefix length.
For instance, you can get the network address for a subnet as follows:
String addrStr = "1.2.3.4/16";
IPAddress address = new IPAddressString(addrStr).getAddress();
IPAddress networkAddress = address.toZeroHost(); //1.2.0.0
toZeroHost
in interface IPAddressSegmentSeries
toZeroHost
in class IPAddress
public IPv6Address toZeroHost(int prefixLength)
IPAddressSegmentSeries
If this series has the same prefix length, then the resulting series will too, otherwise the resulting series will have no prefix length.
This is nearly equivalent to doing the mask (bitwise conjunction) of this address series with the network mask for the given prefix length, but without the possibility of IncompatibleAddressException that can occur when applying a mask to a range of values. Instead, in this case, if the resulting series has a range of values, then the resulting series range boundaries will have host values of 0, but not necessarily the intervening values.
For instance, you can get the network address for a subnet of prefix length 16 as follows:
String addrStr = "1.2.3.4";
IPAddress address = new IPAddressString(addrStr).getAddress();
IPAddress networkAddress = address.toZeroHost(16); //1.2.0.0
toZeroHost
in interface IPAddressSegmentSeries
toZeroHost
in class IPAddress
public IPv6Address toMaxHost()
IPAddressSegmentSeries
The resultant series will have the same prefix length if AddressNetwork.getPrefixConfiguration()
is not AddressNetwork.PrefixConfiguration.ALL_PREFIXED_ADDRESSES_ARE_SUBNETS
,
otherwise it will no longer have a prefix length.
For instance, you can get the broadcast address for a subnet as follows:
String addrStr = "1.2.3.4/16";
IPAddress address = new IPAddressString(addrStr).getAddress();
IPAddress broadcastAddress = address.toMaxHost(); //1.2.255.255
toMaxHost
in interface IPAddressSegmentSeries
toMaxHost
in class IPAddress
public IPv6Address toMaxHost(int prefixLength)
IPAddressSegmentSeries
If this series has the same prefix length, then the resulting series will too, otherwise the resulting series will have no prefix length.
This is nearly equivalent to doing the bitwise or (bitwise disjunction) of this address series with the network mask for the given prefix length, but without the possibility of IncompatibleAddressException that can occur when applying a mask to a range of values. Instead, in this case, if the resulting series has a range of values, then the resulting series range boundaries will have host values of all ones, but not necessarily the intervening values.
For instance, you can get the broadcast address for a subnet of prefix length 16 as follows:
String addrStr = "1.2.3.4";
IPAddress address = new IPAddressString(addrStr).getAddress();
IPAddress broadcastAddress = address.toMaxHost(16); //1.2.255.255
toMaxHost
in interface IPAddressSegmentSeries
toMaxHost
in class IPAddress
public IPv6Address mask(IPAddress mask, boolean retainPrefix) throws IncompatibleAddressException, AddressConversionException
IPAddress
If the mask is a different version than this, then the default conversion is applied first using IPAddress.toIPv4()
or IPAddress.toIPv6()
If this represents multiple addresses, and applying the mask to all addresses creates a set of addresses
that cannot be represented as a contiguous range within each segment, then IncompatibleAddressException
is thrown.
mask
in class IPAddress
IncompatibleAddressException
- if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException
- if the address argument could not be converted to the same address version as thispublic IPv6Address mask(IPAddress mask) throws IncompatibleAddressException, AddressConversionException
IPAddress
IPAddress.mask(IPAddress, boolean)
with the second argument as false.
If the mask is a different version than this, then the default conversion is applied first using IPAddress.toIPv4()
or IPAddress.toIPv6()
mask
in class IPAddress
IncompatibleAddressException
- if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException
- if the address argument could not be converted to the same address version as thispublic IPv6Address maskNetwork(IPAddress mask, int networkPrefixLength) throws IncompatibleAddressException, PrefixLenException, AddressConversionException
IPAddress
Any existing prefix length is removed as the mask and new prefix length is applied to all individual addresses.
If the mask is a different version than this, then the default conversion is applied first using IPAddress.toIPv4()
or IPAddress.toIPv6()
If this represents multiple addresses, and applying the mask to all addresses creates a set of addresses
that cannot be represented as a contiguous range within each segment, then IncompatibleAddressException
is thrown.
maskNetwork
in class IPAddress
IncompatibleAddressException
- if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException
- if the address argument could not be converted to the same address version as thisPrefixLenException
public IPv6Address bitwiseOr(IPAddress mask, boolean retainPrefix) throws IncompatibleAddressException, AddressConversionException
IPAddress
The mask is applied to all individual addresses, similar to how the method IPAddress.mask(IPAddress, boolean)
applies the bitwise conjunction.
Any existing prefix length is removed beforehand. If the retainPrefix argument is true, then the existing prefix length will be applied to the result.
If the mask is a different version than this, then the default conversion is applied first using IPAddress.toIPv4()
or IPAddress.toIPv6()
If you wish to mask a portion of the network, use IPAddress.bitwiseOrNetwork(IPAddress, int)
For instance, you can get the broadcast address for a subnet as follows:
String addrStr = "1.2.3.4/16";
IPAddress address = new IPAddressString(addrStr).getAddress();
IPAddress hostMask = address.getNetwork().getHostMask(address.getNetworkPrefixLength());//0.0.255.255
IPAddress broadcastAddress = address.bitwiseOr(hostMask); //1.2.255.255
bitwiseOr
in class IPAddress
IncompatibleAddressException
- if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException
- if the address argument could not be converted to the same address version as thispublic IPv6Address bitwiseOr(IPAddress mask) throws IncompatibleAddressException, AddressConversionException
IPAddress
IPAddress.bitwiseOr(IPAddress, boolean)
with the second argument as false.
If the mask is a different version than this, then the default conversion is applied first using IPAddress.toIPv4()
or IPAddress.toIPv6()
bitwiseOr
in class IPAddress
IncompatibleAddressException
- if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException
- if the address argument could not be converted to the same address version as thispublic IPv6Address bitwiseOrNetwork(IPAddress mask, int networkPrefixLength) throws IncompatibleAddressException, PrefixLenException, AddressConversionException
IPAddress
If the mask is a different version than this, then the default conversion is applied first using IPAddress.toIPv4()
or IPAddress.toIPv6()
Any existing prefix length is dropped for the new prefix length and the mask is applied up to the end the new prefix length.
It is similar to how the IPAddress.maskNetwork(IPAddress, int)
method does the bitwise conjunction.
bitwiseOrNetwork
in class IPAddress
networkPrefixLength
- the new prefix length for the addressIncompatibleAddressException
- if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException
- if the address argument could not be converted to the same address version as thisPrefixLenException
public IPv6AddressSection getNetworkSection()
IPAddressSegmentSeries
getNetworkSection
in interface IPAddressSegmentSeries
public IPv6AddressSection getNetworkSection(int networkPrefixLength) throws PrefixLenException
IPAddressSegmentSeries
getNetworkSection
in interface IPAddressSegmentSeries
PrefixLenException
public IPv6AddressSection getNetworkSection(int networkPrefixLength, boolean withPrefixLength) throws PrefixLenException
IPAddressSegmentSeries
getNetworkSection
in interface IPAddressSegmentSeries
withPrefixLength
- whether the resulting section will have networkPrefixLength as the associated prefix length or notPrefixLenException
public IPv6AddressSection getHostSection(int networkPrefixLength) throws PrefixLenException
IPAddressSegmentSeries
getHostSection
in interface IPAddressSegmentSeries
PrefixLenException
public IPv6AddressSection getHostSection()
IPAddressSegmentSeries
getHostSection
in interface IPAddressSegmentSeries
public IPv6Address toPrefixBlock()
IPAddress
For example, if the address is 1.2.3.4/16 it returns the subnet 1.2.*.* /16
toPrefixBlock
in interface AddressSegmentSeries
toPrefixBlock
in interface IPAddressSegmentSeries
toPrefixBlock
in class IPAddress
public IPv6Address toPrefixBlock(int networkPrefixLength) throws PrefixLenException
IPAddressSegmentSeries
toPrefixBlock
in interface IPAddressSegmentSeries
toPrefixBlock
in class IPAddress
PrefixLenException
public IPv6Address assignPrefixForSingleBlock()
IPAddress
If no such prefix length exists, returns null.
Examples:
1.2.3.4 returns 1.2.3.4/32
1.2.*.* returns 1.2.0.0/16
1.2.*.0/24 returns 1.2.0.0/16
1.2.*.4 returns null
1.2.252-255.* returns 1.2.252.0/22
1.2.3.4/x returns the same address
assignPrefixForSingleBlock
in interface IPAddressSegmentSeries
assignPrefixForSingleBlock
in class IPAddress
IPAddressSegmentSeries.toPrefixBlock()
,
IPAddressSegmentSeries.assignMinPrefixForBlock()
public IPv6Address assignMinPrefixForBlock()
IPAddress
assignMinPrefixForBlock
in interface IPAddressSegmentSeries
assignMinPrefixForBlock
in class IPAddress
IPAddressSegmentSeries.toPrefixBlock()
,
IPAddressSegmentSeries.assignPrefixForSingleBlock()
public IPv6Address[] spanWithPrefixBlocks(IPAddress other) throws AddressConversionException
IPAddress
If the other address is a different version than this, then the default conversion is applied first using IPAddress.toIPv4()
or IPAddress.toIPv6()
The resulting array is sorted from lowest address value to highest, regardless of the size of each prefix block.
spanWithPrefixBlocks
in class IPAddress
AddressConversionException
public IPv6Address[] mergePrefixBlocks(IPAddress... addresses) throws AddressConversionException
IPAddress
If any other address in the list is a different version than this, then the default conversion is applied first using IPAddress.toIPv4()
or IPAddress.toIPv6()
,
which can result in AddressConversionException
The result is sorted from single address to smallest blocks to largest blocks.
mergePrefixBlocks
in class IPAddress
addresses
- the addresses to merge with thisAddressConversionException
public boolean hasZone()
public java.lang.String getZone()
public IPv6Address removeZone()
public java.net.Inet6Address toInetAddress()
IPAddress
toInetAddress
in class IPAddress
public java.net.Inet6Address toUpperInetAddress()
IPAddress
IPAddress.toInetAddress()
toUpperInetAddress
in class IPAddress
public boolean isSameAddress(Address other)
isSameAddress
in class Address
public boolean isSameAddress(IPAddress other)
isSameAddress
in class IPAddress
public boolean contains(Address other)
public java.lang.String toMixedString()
public java.lang.String toCanonicalString()
toCanonicalString
in interface AddressSegmentSeries
toCanonicalString
in class Address
public java.lang.String toFullString()
IPAddress
toFullString
in interface IPAddressSegmentSeries
toFullString
in class IPAddress
public static java.lang.String toNormalizedString(IPv6AddressNetwork network, Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider, java.lang.Integer prefixLength, java.lang.CharSequence zone)
lowerValueProvider
- upperValueProvider
- prefixLength
- zone
- public java.lang.String toNormalizedString()
toNormalizedString
in interface AddressComponent
toNormalizedString
in class Address
public java.lang.String toCompressedString()
toCompressedString
in interface AddressSegmentSeries
toCompressedString
in class Address
public java.lang.String toSubnetString()
IPAddress
toSubnetString
in interface IPAddressSegmentSeries
toSubnetString
in class IPAddress
public java.lang.String toNormalizedWildcardString()
IPAddress
toNormalizedWildcardString
in interface IPAddressSegmentSeries
toNormalizedWildcardString
in class IPAddress
public java.lang.String toBase85String()
public java.lang.String toCanonicalWildcardString()
IPAddress
toCanonicalWildcardString
in interface IPAddressSegmentSeries
toCanonicalWildcardString
in class IPAddress
public java.lang.String toCompressedWildcardString()
IPAddress
toCompressedWildcardString
in interface IPAddressSegmentSeries
toCompressedWildcardString
in class IPAddress
public java.lang.String toSQLWildcardString()
IPAddress
Address.SEGMENT_SQL_WILDCARD
instead of Address.SEGMENT_WILDCARD
and also uses Address.SEGMENT_SQL_SINGLE_WILDCARD
toSQLWildcardString
in interface IPAddressSegmentSeries
toSQLWildcardString
in class IPAddress
public java.lang.String toHexString(boolean with0xPrefix)
Address
toHexString
in interface AddressComponent
toHexString
in class Address
public java.lang.String toBinaryString()
IPAddress
If this section represents a range of values not corresponding to a prefix, then this is printed as a range of two hex values.
toBinaryString
in interface IPAddressSegmentSeries
toBinaryString
in class IPAddress
public java.lang.String toOctalString(boolean with0Prefix)
IPAddress
If this section represents a range of values not corresponding to a prefix, then this is printed as a range of two hex values.
toOctalString
in interface IPAddressSegmentSeries
toOctalString
in class IPAddress
public java.lang.String toPrefixLengthString()
IPAddress
toPrefixLengthString
in interface IPAddressSegmentSeries
toPrefixLengthString
in class IPAddress
public java.lang.String toConvertedString()
IPAddress
toConvertedString
in class IPAddress
public java.lang.String toNormalizedString(IPAddressSection.IPStringOptions params)
IPAddress
toNormalizedString
in interface IPAddressSegmentSeries
toNormalizedString
in class IPAddress
params
- the parameters for the address stringpublic java.lang.String toNormalizedString(IPv6AddressSection.IPv6StringOptions params)
public java.lang.String toNormalizedString(boolean keepMixed, IPv6AddressSection.IPv6StringOptions params)
keepMixed
- if this address was constructed from a string with mixed representation (a:b:c:d:e:f:1.2.3.4), whether to keep it that way (ignored if makeMixed is true in the params argument)params
- the parameters for the address stringpublic java.lang.String toUNCHostName()
IPAddress
toUNCHostName
in class IPAddress
public IPAddressPartStringCollection toStandardStringCollection()
toStandardStringCollection
in class IPAddress
public IPAddressPartStringCollection toAllStringCollection()
toAllStringCollection
in class IPAddress
public IPAddressPartStringCollection toStringCollection(IPAddressSection.IPStringBuilderOptions opts)
toStringCollection
in interface IPAddressSegmentSeries
toStringCollection
in class IPAddress
public IPAddressPartStringCollection toStringCollection(IPv6AddressSection.IPv6StringBuilderOptions opts)