Class NetUtil
java.lang.Object
org.jboss.netty.util.NetUtil
A class that holds a number of network-related constants.
This class borrowed some of its methods from a modified fork of the
Inet6Util class which was part of Apache Harmony.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intNumber of bytes needed to represent and IPV4 valueprivate static final intMaximum amount of value adding characters in between IPV4 separatorsprivate static final intNumber of separators that must be present in an IPv4 stringprivate static final intNumber of bytes needed to represent and IPV6 valueprivate static final intMaximum amount of value adding characters in between IPV6 separatorsprivate static final intThe maximum number of characters for an IPV6 string with no scopeprivate static final intMaximum number of separators that must be present in an IPv6 stringprivate static final intMinimum number of separators that must be present in an IPv6 stringprivate static final intThis defines how many words (represented as ints) are needed to represent an IPv6 addressprivate static final InternalLoggerThe logger being used by this class -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateNetUtil()A constructor to stop this class being constructed. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidconvertToBytes(String hexWord, byte[] ipByteArray, int byteIndex) Converts a 4 character hex word into a 2 byte word equivalentstatic byte[]createByteArrayFromIpAddressString(String ipAddressString) Creates an byte[] based on an ipAddressString.static Inet6AddressReturns theInet6Addressrepresentation of aCharSequenceIP address.static Inet6AddressgetByName(CharSequence ip, boolean ipv4Mapped) Returns theInet6Addressrepresentation of aCharSequenceIP address.(package private) static intgetIntValue(char c) private static booleaninRangeEndExclusive(int value, int start, int end) Does a range check onvalueif is withinstart(inclusive) andend(exclusive).private static booleanisValidHexChar(char c) static booleanisValidIp4Word(String word) static booleanisValidIpV4Address(String value) Takes a string and parses it to see if it is a valid IPV4 address.static booleanisValidIpV6Address(String ipAddress) private static booleanisValidNumericChar(char c) static StringReturns theStringrepresentation of anInetAddress.static StringtoAddressString(InetAddress ip, boolean ipv4Mapped) Returns theStringrepresentation of anInetAddress.
-
Field Details
-
IPV6_WORD_COUNT
private static final int IPV6_WORD_COUNTThis defines how many words (represented as ints) are needed to represent an IPv6 address- See Also:
-
IPV6_MAX_CHAR_COUNT
private static final int IPV6_MAX_CHAR_COUNTThe maximum number of characters for an IPV6 string with no scope- See Also:
-
IPV6_BYTE_COUNT
private static final int IPV6_BYTE_COUNTNumber of bytes needed to represent and IPV6 value- See Also:
-
IPV6_MAX_CHAR_BETWEEN_SEPARATOR
private static final int IPV6_MAX_CHAR_BETWEEN_SEPARATORMaximum amount of value adding characters in between IPV6 separators- See Also:
-
IPV6_MIN_SEPARATORS
private static final int IPV6_MIN_SEPARATORSMinimum number of separators that must be present in an IPv6 string- See Also:
-
IPV6_MAX_SEPARATORS
private static final int IPV6_MAX_SEPARATORSMaximum number of separators that must be present in an IPv6 string- See Also:
-
IPV4_BYTE_COUNT
private static final int IPV4_BYTE_COUNTNumber of bytes needed to represent and IPV4 value- See Also:
-
IPV4_MAX_CHAR_BETWEEN_SEPARATOR
private static final int IPV4_MAX_CHAR_BETWEEN_SEPARATORMaximum amount of value adding characters in between IPV4 separators- See Also:
-
IPV4_SEPARATORS
private static final int IPV4_SEPARATORSNumber of separators that must be present in an IPv4 string- See Also:
-
logger
The logger being used by this class
-
-
Constructor Details
-
NetUtil
private NetUtil()A constructor to stop this class being constructed.
-
-
Method Details
-
createByteArrayFromIpAddressString
Creates an byte[] based on an ipAddressString. No error handling is performed here. -
convertToBytes
Converts a 4 character hex word into a 2 byte word equivalent -
getIntValue
static int getIntValue(char c) -
isValidIpV6Address
-
isValidIp4Word
-
isValidHexChar
private static boolean isValidHexChar(char c) -
isValidNumericChar
private static boolean isValidNumericChar(char c) -
isValidIpV4Address
Takes a string and parses it to see if it is a valid IPV4 address.- Returns:
- true, if the string represents an IPV4 address in dotted notation, false otherwise
-
getByName
Returns theInet6Addressrepresentation of aCharSequenceIP address.This method will treat all IPv4 type addresses as "IPv4 mapped" (see
getByName(CharSequence, boolean))- Parameters:
ip-CharSequenceIP address to be converted to aInet6Address- Returns:
Inet6Addressrepresentation of theipornullif not a valid IP address.
-
getByName
Returns theInet6Addressrepresentation of aCharSequenceIP address.The
ipv4Mappedparameter specifies how IPv4 addresses should be treated. "IPv4 mapped" format as defined in rfc 4291 section 2 is supported.- Parameters:
ip-CharSequenceIP address to be converted to aInet6Addressipv4Mapped-trueTo allow IPv4 mapped inputs to be translated intoInet6AddressfalseDon't turn IPv4 addressed to mapped addresses
- Returns:
Inet6Addressrepresentation of theipornullif not a valid IP address.
-
toAddressString
Returns theStringrepresentation of anInetAddress.- Inet4Address results are identical to
InetAddress.getHostAddress() - Inet6Address results adhere to rfc 5952 section 4
The output does not include Scope ID.
- Parameters:
ip-InetAddressto be converted to an address string- Returns:
Stringcontaining the text-formatted IP address
- Inet4Address results are identical to
-
toAddressString
Returns theStringrepresentation of anInetAddress.- Inet4Address results are identical to
InetAddress.getHostAddress() - Inet6Address results adhere to
rfc 5952 section 4 if
ipv4Mappedis false. Ifipv4Mappedis true then "IPv4 mapped" format from rfc 4291 section 2 will be supported. The compressed result will always obey the compression rules defined in rfc 5952 section 4
The output does not include Scope ID.
- Parameters:
ip-InetAddressto be converted to an address stringipv4Mapped-trueto stray from strict rfc 5952 and support the "IPv4 mapped" format defined in rfc 4291 section 2 while still following the updated guidelines in rfc 5952 section 4falseto strictly follow rfc 5952
- Returns:
Stringcontaining the text-formatted IP address
- Inet4Address results are identical to
-
inRangeEndExclusive
private static boolean inRangeEndExclusive(int value, int start, int end) Does a range check onvalueif is withinstart(inclusive) andend(exclusive).- Parameters:
value- The value to checked if is withinstart(inclusive) andend(exclusive)start- The start of the range (inclusive)end- The end of the range (exclusive)- Returns:
trueifvalueif is withinstart(inclusive) andend(exclusive)falseotherwise
-