public static enum AddressNetwork.PrefixConfiguration extends Enum<AddressNetwork.PrefixConfiguration>
1. All prefixes are subnets. This was the legacy behaviour for version earlier than version 4. All prefixed addresses are converted to the block of addresses that share the same prefix. For addresses in which prefixes are derived from the address ranges, such as MAC, prefix lengths are implicitly calculated from the range, so 1:2:3:*:*:* implicitly has the prefix length of 24. This is also the case for any address derived from the original.
2. Addresses with zero-values hosts are treated as subnets. More precisely, addresses whose hosts are entirely zero, or addresses whose hosts start with zeros and end with the full range of values are treated as subnets. So, for example, 1.2.0.0/16 is converted to 1.2.*.* which is the block of addresses with with prefix 1.2. Also, 1.2.0.* /16 or 1.2.*.* /16 are also equivalent to the block of 65535 addresses 1.2.*.* associated with prefix length 16. Addresses with non-zero hosts, such as 1.2.0.1/16 are treated differently. 1.2.0.1/16 is equivalent to the single address 1.2.0.1 and is not a treated as a subnet block of multiple addresses. The new behaviour is akin to the typical convention used by network administrators in which the address with a host of zero is known as the network address. The all-zero address 0.0.0.0 is conventionally known as INADDR_ANY (any address on the local machine), and when paired with prefix zero it is known as the default route (the route for all addresses).
The same is true on the IPv6 side, where 1:2:3:4::/64 is treated as the subnet of all addresses with prefix 1:2:3:4. With IPv6 it is a common convention to depict a prefixed network as a:b:c:d::/64, with the host shown as all zeros. This is also known as the subnet router anycast address in IPv6. The all-zero address '::' is the value of IN6ADDR_ANY_INIT, the analog to the IPv4 INADDR_ANY.
In summary:
So for example, 1.2.0.0/16 will give you the subnet block 1.2.*.* /16, and once you have it, if you want just the single address 1.2.0.0/16, you can get it using IPAddress.getLower()
.
This option has less meaning for other address types in which ranges are explicit, such as MAC addresses. However, this option does allow you, using the appropriate constructor, to assign a prefix length to any address. So there is no automatic fixed mapping between the range of the address values and the associated prefix length.
Additionally, when starting with an address whose prefix was calculated from its range, you can derive additionally addresses from the original, and those addresses will have the same prefix. For instance, 1:2:3:*:*:* implicitly has the prefix length of 24 regardless of the prefix configuration. But with this prefix configuration, you can then construct a derived address with the same prefix, for example with new MACAddressString("1:2:3:*:*:*").getAddress().replace(MACAddressString("1:2:3:4:5:6").getSection(2));
3. The third option is the setting for which prefixes are never automatically converted to subnets. Any subnet must be explicitly defined, such as 1.2.*.* /16
For addresses in which ranges are explicit, such as MAC addresses, this option is no different than the second option.
In summary:
Note that when setting a non-default prefix configuration, indeterminate behaviour can result from the same addresses using different prefix configuration settings at different times, so this method must be used carefully.
Should you wish to use two different prefix configurations in the same app, it can be done safely using classloaders, and it can also be done using different network instances. To used different networks, you can override the virtual methods for getting network instances in your address component classes.
Enum Constant and Description |
---|
ALL_PREFIXED_ADDRESSES_ARE_SUBNETS |
EXPLICIT_SUBNETS |
PREFIXED_ZERO_HOSTS_ARE_SUBNETS |
Modifier and Type | Method and Description |
---|---|
boolean |
allPrefixedAddressesAreSubnets() |
boolean |
prefixedSubnetsAreExplicit() |
static AddressNetwork.PrefixConfiguration |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static AddressNetwork.PrefixConfiguration[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
boolean |
zeroHostsAreSubnets() |
public static final AddressNetwork.PrefixConfiguration ALL_PREFIXED_ADDRESSES_ARE_SUBNETS
public static final AddressNetwork.PrefixConfiguration PREFIXED_ZERO_HOSTS_ARE_SUBNETS
public static final AddressNetwork.PrefixConfiguration EXPLICIT_SUBNETS
public static AddressNetwork.PrefixConfiguration[] values()
for (AddressNetwork.PrefixConfiguration c : AddressNetwork.PrefixConfiguration.values()) System.out.println(c);
public static AddressNetwork.PrefixConfiguration valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic boolean allPrefixedAddressesAreSubnets()
public boolean zeroHostsAreSubnets()
public boolean prefixedSubnetsAreExplicit()