|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.dellroad.stuff.net.IPv4Util
public final class IPv4Util
Utility methods for working with IPv4 addresses and netmasks.
| Field Summary | |
|---|---|
static int |
MAX_VALID_NETMASK_WIDTH
|
static int |
MIN_VALID_NETMASK_WIDTH
|
| Method Summary | |
|---|---|
static Inet4Address |
fromString(String string)
Convert from string representation. |
static Inet4Address |
getBaseAddress(Inet4Address address,
Inet4Address netmask)
Get the base address (all host bits zero) of the given IP network. |
static Inet4Address |
getBroadcastAddress(Inet4Address address,
Inet4Address netmask)
Get the broadcast address (all host bits one) of the given IP network. |
static Inet4Address |
getNetmaskForWidth(int width)
Get netmask with the given width. |
static int |
getWidth(Inet4Address netmask)
Get netmask width. |
static boolean |
isOnNetwork(Inet4Address address,
Inet4Address network,
Inet4Address netmask)
Determine if the given address lives on the given network. |
static boolean |
isValidHostOnNetwork(Inet4Address address,
Inet4Address network,
Inet4Address netmask)
Determine if the given address is a valid host address on the given network. |
static boolean |
isValidNetmask(Inet4Address netmask)
Determine if the given address is a valid CIDR netmask. |
static Inet4Address |
toAddress(byte[] bytes)
Convert raw bytes to an Inet4Address. |
static Inet4Address |
toAddress(int address)
Convert from 32-bit integer representation. |
static int |
toInt32(Inet4Address address)
Convert to 32-bit integer representation. |
static String |
toString(Inet4Address address)
Convert an IPv4 address to string representation. |
static String |
toString(Inet4Address address,
Inet4Address netmask)
Convert a network address (IPv4 base address and netmask) to string representation. |
static long |
toUInt32(Inet4Address address)
Convert to an unsigned 32-bit integer representation within a 64-bit long. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int MIN_VALID_NETMASK_WIDTH
public static final int MAX_VALID_NETMASK_WIDTH
| Method Detail |
|---|
public static Inet4Address toAddress(int address)
public static int toInt32(Inet4Address address)
public static long toUInt32(Inet4Address address)
public static Inet4Address toAddress(byte[] bytes)
Inet4Address.
IllegalArgumentException - if array does not have length fourpublic static String toString(Inet4Address address)
IllegalArgumentException - if array does not have length four
public static String toString(Inet4Address address,
Inet4Address netmask)
IllegalArgumentException - if array does not have length fourpublic static Inet4Address fromString(String string)
IllegalArgumentException - if string is not an IP addresspublic static int getWidth(Inet4Address netmask)
IllegalArgumentException - if the value is not a valid CIDR netmaskpublic static boolean isValidNetmask(Inet4Address netmask)
public static Inet4Address getNetmaskForWidth(int width)
IllegalArgumentException - if width is less than zero or greater than 32
public static Inet4Address getBaseAddress(Inet4Address address,
Inet4Address netmask)
address - any IP address on the networknetmask - the netmask of the network
IllegalArgumentException - if netmask is not a valid netmask
public static Inet4Address getBroadcastAddress(Inet4Address address,
Inet4Address netmask)
address - any IP address on the networknetmask - the netmask of the network
IllegalArgumentException - if netmask is not a valid netmask
public static boolean isOnNetwork(Inet4Address address,
Inet4Address network,
Inet4Address netmask)
address - IP address in questionnetwork - network addressnetmask - network netmask
IllegalArgumentException - if netmask is not a valid netmask
public static boolean isValidHostOnNetwork(Inet4Address address,
Inet4Address network,
Inet4Address netmask)
address - IP address in questionnetwork - network addressnetmask - network netmask
IllegalArgumentException - if netmask is not a valid netmask
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||