Package org.jruby.ext.socket
Class SocketUtilsIPV6.IPv6Address
java.lang.Object
org.jruby.ext.socket.SocketUtilsIPV6.IPv6Address
- Enclosing class:
- SocketUtilsIPV6
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(int value) Addition.private intcountConsecutiveZeroes(short[] shorts, int offset) private intcountOccurrences(String haystack, char needle) private StringexpandShortNotation(String string) fromString(String string) Create an IPv6 address from its String representation.private StringgenerateZeroes(int number) longlongprivate booleaninHighRange(int shortNumber) booleanReturns true if the address is an IPv4-mapped IPv6 address.private booleanisLessThanUnsigned(long a, long b) maskWithNetworkMask(SocketUtilsIPV6.IPv6NetworkMask networkMask) Mask the address with the given network mask.Calculate the maximum address with the given network mask.private SocketUtilsIPV6.IPv6AddressmergeLongArrayIntoIPv6Address(long[] longs) intintintintprivate long[]parseStringArrayIntoLongArray(String[] strings) private StringremoveScope(String string) private StringrewriteIPv4MappedNotation(String string) (package private) int[]subtract(int value) Subtraction.private String[]private Stringprivate short[]private StringtoString()Returns a string representation of the IPv6 address.private long[]tryParseStringArrayIntoLongArray(String string, String longNotation)
-
Field Details
-
N_SHORTS
private static final int N_SHORTS- See Also:
-
highBits
private long highBits -
lowBits
private long lowBits
-
-
Constructor Details
-
IPv6Address
IPv6Address(long highBits, long lowBits) -
IPv6Address
private IPv6Address()
-
-
Method Details
-
fromString
Create an IPv6 address from its String representation. For example "1234:5678:abcd:0000:9876:3210:ffff:ffff" or "2001::ff" or even "::". IPv4-Mapped IPv6 addresses such as "::ffff:123.456.123.456" are also supported.- Parameters:
string- string representation- Returns:
- IPv6 address
-
toInetAddress
- Throws:
UnknownHostException
-
mergeLongArrayIntoIPv6Address
-
rewriteIPv4MappedNotation
-
tryParseStringArrayIntoLongArray
-
parseStringArrayIntoLongArray
-
expandShortNotation
-
countOccurrences
-
generateZeroes
-
removeScope
-
add
Addition. Will never overflow, but wraps around when the highest ip address has been reached.- Parameters:
value- value to add- Returns:
- new IPv6 address
-
subtract
Subtraction. Will never underflow, but wraps around when the lowest ip address has been reached.- Parameters:
value- value to subtract- Returns:
- new IPv6 address
-
isLessThanUnsigned
private boolean isLessThanUnsigned(long a, long b) -
maskWithNetworkMask
Mask the address with the given network mask.- Parameters:
networkMask- network mask- Returns:
- an address of which the last 128 - networkMask.asPrefixLength() bits are zero
-
maximumAddressWithNetworkMask
public SocketUtilsIPV6.IPv6Address maximumAddressWithNetworkMask(SocketUtilsIPV6.IPv6NetworkMask networkMask) Calculate the maximum address with the given network mask.- Parameters:
networkMask- network mask- Returns:
- an address of which the last 128 - networkMask.asPrefixLength() bits are one
-
isIPv4Mapped
public boolean isIPv4Mapped()Returns true if the address is an IPv4-mapped IPv6 address. In these addresses, the first 80 bits are zero, the next 16 bits are one, and the remaining 32 bits are the IPv4 address.- Returns:
- true if the address is an IPv4-mapped IPv6 addresses.
-
toString
Returns a string representation of the IPv6 address. It will use shorthand notation and special notation for IPv4-mapped IPv6 addresses whenever possible. -
toIPv4MappedAddressString
-
toShortHandNotationString
-
toArrayOfShortStrings
-
toShortArray
private short[] toShortArray() -
inHighRange
private boolean inHighRange(int shortNumber) -
startAndLengthOfLongestRunOfZeroes
int[] startAndLengthOfLongestRunOfZeroes() -
countConsecutiveZeroes
private int countConsecutiveZeroes(short[] shorts, int offset) -
getHighBits
public long getHighBits() -
getLowBits
public long getLowBits() -
numberOfTrailingZeroes
public int numberOfTrailingZeroes() -
numberOfTrailingOnes
public int numberOfTrailingOnes() -
numberOfLeadingZeroes
public int numberOfLeadingZeroes() -
numberOfLeadingOnes
public int numberOfLeadingOnes()
-