Module inet.ipaddr

Class MACAddress

    • Field Detail

      • COLON_SEGMENT_SEPARATOR

        public static final char COLON_SEGMENT_SEPARATOR
        See Also:
        Constant Field Values
      • DASH_SEGMENT_SEPARATOR

        public static final char DASH_SEGMENT_SEPARATOR
        See Also:
        Constant Field Values
      • SPACE_SEGMENT_SEPARATOR

        public static final char SPACE_SEGMENT_SEPARATOR
        See Also:
        Constant Field Values
      • DOTTED_SEGMENT_SEPARATOR

        public static final char DOTTED_SEGMENT_SEPARATOR
        See Also:
        Constant Field Values
      • DASHED_SEGMENT_RANGE_SEPARATOR

        public static final char DASHED_SEGMENT_RANGE_SEPARATOR
        See Also:
        Constant Field Values
      • DASHED_SEGMENT_RANGE_SEPARATOR_STR

        public static final java.lang.String DASHED_SEGMENT_RANGE_SEPARATOR_STR
      • MEDIA_ACCESS_CONTROL_SEGMENT_COUNT

        public static final int MEDIA_ACCESS_CONTROL_SEGMENT_COUNT
        See Also:
        Constant Field Values
      • MEDIA_ACCESS_CONTROL_BIT_COUNT

        public static final int MEDIA_ACCESS_CONTROL_BIT_COUNT
        See Also:
        Constant Field Values
      • MEDIA_ACCESS_CONTROL_DOTTED_SEGMENT_COUNT

        public static final int MEDIA_ACCESS_CONTROL_DOTTED_SEGMENT_COUNT
        See Also:
        Constant Field Values
      • MEDIA_ACCESS_CONTROL_DOTTED_64_SEGMENT_COUNT

        public static final int MEDIA_ACCESS_CONTROL_DOTTED_64_SEGMENT_COUNT
        See Also:
        Constant Field Values
      • MEDIA_ACCESS_CONTROL_DOTTED_BITS_PER_SEGMENT

        public static final int MEDIA_ACCESS_CONTROL_DOTTED_BITS_PER_SEGMENT
        See Also:
        Constant Field Values
      • MEDIA_ACCESS_CONTROL_SINGLE_DASHED_SEGMENT_COUNT

        public static final int MEDIA_ACCESS_CONTROL_SINGLE_DASHED_SEGMENT_COUNT
        See Also:
        Constant Field Values
      • EXTENDED_UNIQUE_IDENTIFIER_48_SEGMENT_COUNT

        public static final int EXTENDED_UNIQUE_IDENTIFIER_48_SEGMENT_COUNT
        See Also:
        Constant Field Values
      • EXTENDED_UNIQUE_IDENTIFIER_64_SEGMENT_COUNT

        public static final int EXTENDED_UNIQUE_IDENTIFIER_64_SEGMENT_COUNT
        See Also:
        Constant Field Values
      • EXTENDED_UNIQUE_IDENTIFIER_48_BIT_COUNT

        public static final int EXTENDED_UNIQUE_IDENTIFIER_48_BIT_COUNT
        See Also:
        Constant Field Values
      • EXTENDED_UNIQUE_IDENTIFIER_64_BIT_COUNT

        public static final int EXTENDED_UNIQUE_IDENTIFIER_64_BIT_COUNT
        See Also:
        Constant Field Values
      • MAX_VALUE_PER_DOTTED_SEGMENT

        public static final int MAX_VALUE_PER_DOTTED_SEGMENT
        See Also:
        Constant Field Values
      • ORGANIZATIONAL_UNIQUE_IDENTIFIER_SEGMENT_COUNT

        public static final int ORGANIZATIONAL_UNIQUE_IDENTIFIER_SEGMENT_COUNT
        See Also:
        Constant Field Values
      • ORGANIZATIONAL_UNIQUE_IDENTIFIER_BIT_COUNT

        public static final int ORGANIZATIONAL_UNIQUE_IDENTIFIER_BIT_COUNT
        See Also:
        Constant Field Values
    • Method Detail

      • enumerate

        public java.math.BigInteger enumerate​(Address other)
        Description copied from class: Address
        Indicates where an address sits relative to the subnet ordering.

        Determines how many address elements of a subnet precede the given address element, if the address is in the subnet. If above the subnet range, it is the distance to the upper boundary added to the subnet address count less one, and if below the subnet range, the distance to the lower boundary.

        In other words, if the given address is not in the subnet but above it, returns the number of addresses preceding the address from the upper subnet boundary, added to one less than the total number of subnet addresses. If the given address is not in the subnet but below it, returns the number of addresses following the address to the lower subnet boundary.

        enumerate returns null when the argument is a multi-valued subnet. The argument must be an individual address.

        When this address is also single-valued, the returned value is the distance (difference) between this address and the argument address.

        enumerate is the inverse of the increment method:

        • subnet.enumerate(subnet.increment(inc)) = inc
        • subnet.increment(subnet.enumerate(newAddr)) = newAddr

        If the given address does not have the same version or type as this subnet or address, then null is returned.

        Specified by:
        enumerate in class Address
      • isExtended

        public boolean isExtended()
      • isMACAddress

        public boolean isMACAddress()
        Description copied from class: Address
        Returns whether this address is a MAC address
        Overrides:
        isMACAddress in class Address
        Returns:
        whether this address is a MAC address
      • toMACAddress

        public MACAddress toMACAddress()
        Description copied from class: Address
        If this address is a MAC address, returns that MACAddress. Otherwise, returns null.
        Overrides:
        toMACAddress in class Address
        Returns:
        the MAC address
      • isAllAddresses

        public boolean isAllAddresses()
      • maxSegmentValue

        public static int maxSegmentValue()
      • getMaxSegmentValue

        public int getMaxSegmentValue()
        Description copied from interface: AddressSegmentSeries
        Returns the maximum possible segment value for this type of address. Note this is not the maximum value of the range of segment values in this specific address, this is the maximum value of any segment for this address type, and is usually determined by the number of bits per segment.
        Specified by:
        getMaxSegmentValue in interface AddressSegmentSeries
        Returns:
        the maximum possible segment value for a series of the same type
      • getByteCount

        public int getByteCount()
        Description copied from interface: AddressItem
        Provides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8
        Specified by:
        getByteCount in interface AddressItem
        Overrides:
        getByteCount in class Address
        Returns:
        the number of bytes
      • getBytesPerSegment

        public int getBytesPerSegment()
        Description copied from interface: AddressSegmentSeries
        Returns the number of bytes comprising each segment in this series. Segments in the same series are equal length.
        Specified by:
        getBytesPerSegment in interface AddressSegmentSeries
        Returns:
      • getBitsPerSegment

        public int getBitsPerSegment()
        Description copied from interface: AddressSegmentSeries
        Returns the number of bits comprising each segment in this series. Segments in the same series are equal length.
        Specified by:
        getBitsPerSegment in interface AddressSegmentSeries
        Returns:
      • prefixStream

        public java.util.stream.Stream<MACAddress> prefixStream()
        Description copied from interface: AddressSegmentSeries
        Returns a sequential stream of the individual prefixes for the prefix length of this series. For a parallel stream, call BaseStream.parallel() on the returned stream.
        Specified by:
        prefixStream in interface AddressSegmentSeries
        Specified by:
        prefixStream in class Address
        Returns:
      • increment

        public MACAddress increment​(long increment)
        Description copied from interface: AddressSegmentSeries
        Returns the series from the subnet that is the given increment upwards into the subnet range, with the increment of 0 returning the first address in the range.

        If the subnet has multiple values and the increment exceeds the subnet size, then the amount by which it exceeds the size - 1 is added to the upper series of the range (the final iterator value).

        If the increment is negative, it is added to the lower series of the range (the first iterator value).

        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 AddressSegmentSeries.iterator() For instance, a increment of 0 is the first value from the iterator, an increment of 1 is the second value from the iterator, and so on. A negative increment added to the subnet count is equivalent to the same number of values preceding the upper bound of the iterator. For instance, an increment of count - 1 is the last value from the iterator, an increment of count - 2 is the second last value, and so on.

        An increment of size count gives you the series just above the highest series of the subnet. To get the series just below the lowest series of the subnet, use the increment -1.

        Specified by:
        increment in interface AddressSegmentSeries
        Specified by:
        increment in class Address
        Returns:
      • longValue

        public long longValue()
      • upperLongValue

        public long upperLongValue()
      • reverseBits

        public MACAddress reverseBits​(boolean perByte)
        Use to produce: "MSB format", "IBM format", "Token-Ring format", and "non-canonical form" See RFC 2469 section 2 Also see https://en.wikipedia.org/wiki/MAC_address
        Specified by:
        reverseBits in interface AddressComponent
        Specified by:
        reverseBits in interface AddressSegmentSeries
        Specified by:
        reverseBits in class Address
        Parameters:
        perByte - if true, only the bits in each byte are reversed, if false, then all bits in the component are reversed
        Returns:
      • adjustPrefixBySegment

        public MACAddress adjustPrefixBySegment​(boolean nextSegment,
                                                boolean zeroed)
        Description copied from interface: AddressSegmentSeries
        Increases or decreases prefix length to the next segment boundary.
        Specified by:
        adjustPrefixBySegment in interface AddressSegmentSeries
        Specified by:
        adjustPrefixBySegment in class Address
        Parameters:
        nextSegment - whether to move prefix to previous or following segment boundary
        zeroed - whether the bits that move from one side of the prefix to the other become zero or retain their original values
        Returns:
      • adjustPrefixLength

        public MACAddress adjustPrefixLength​(int adjustment,
                                             boolean zeroed)
        Description copied from interface: AddressSegmentSeries
        Increases or decreases prefix length by the given increment.
        Specified by:
        adjustPrefixLength in interface AddressSegmentSeries
        Specified by:
        adjustPrefixLength in class Address
        Parameters:
        adjustment - the increment
        zeroed - whether the bits that move from one side of the prefix to the other become zero or retain their original values
        Returns:
      • setPrefixLength

        public MACAddress setPrefixLength​(int prefixLength)
        Description copied from interface: AddressSegmentSeries
        Sets the prefix length.

        If this series has a prefix length, and the prefix length is increased, the bits moved within the prefix become zero. For an alternative that does not set bits to zero, use AddressSegmentSeries.setPrefixLength(int, boolean) with the second argument as false.

        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.

        Specified by:
        setPrefixLength in interface AddressSegmentSeries
        Specified by:
        setPrefixLength in class Address
        Returns:
      • setPrefixLength

        public MACAddress setPrefixLength​(int prefixLength,
                                          boolean zeroed)
        Description copied from interface: AddressSegmentSeries
        Sets the prefix length.

        When the prefix is extended beyond the segment series boundary, it is removed.

        Specified by:
        setPrefixLength in interface AddressSegmentSeries
        Specified by:
        setPrefixLength in class Address
        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.
        Returns:
      • getSection

        public MACAddressSection getSection​(int index,
                                            int endIndex)
        Description copied from interface: AddressSegmentSeries
        Gets the subsection from the series starting from the given index and ending just before the give endIndex The first segment is at index 0.
        Specified by:
        getSection in interface AddressSegmentSeries
        Returns:
      • toOUIPrefixBlock

        public MACAddress toOUIPrefixBlock()
        Returns an address in which the range of values match the block for the OUI (organizationally unique identifier)
        Returns:
      • toLinkLocalIPv6

        public IPv6Address toLinkLocalIPv6()
        Converts to a link-local Ipv6 address. Any MAC prefix length is ignored. Other elements of this address section are incorporated into the conversion. This will provide the latter 4 segments of an IPv6 address, to be paired with the link-local IPv6 prefix of 4 segments.
        Returns:
      • toEUI64IPv6

        public IPv6AddressSection toEUI64IPv6()
        Converts to an Ipv6 address section. Any MAC prefix length is ignored. Other elements of this address section are incorporated into the conversion. This will provide the latter 4 segments of an IPv6 address, to be paired with an IPv6 prefix of 4 segments.
        Returns:
      • isEUI64

        public boolean isEUI64​(boolean asMAC)
        Whether this section is consistent with an IPv6 EUI64 section, which means it came from an extended 8 byte address, and the corresponding segments in the middle match 0xff and 0xff/fe for MAC/not-MAC
        Parameters:
        asMAC -
        Returns:
      • toEUI64

        public MACAddress toEUI64​(boolean asMAC)
        Convert to IPv6 EUI-64 section http://standards.ieee.org/develop/regauth/tut/eui64.pdf
        Parameters:
        asMAC - if true, this address is considered MAC and the EUI-64 is extended using ff-ff, otherwise this address is considered EUI-48 and extended using ff-fe Note that IPv6 treats MAC as EUI-48 and extends MAC to IPv6 addresses using ff-fe
        Returns:
      • replace

        public MACAddress replace​(int startIndex,
                                  int endIndex,
                                  MACAddress 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
        Parameters:
        startIndex -
        endIndex -
        replacement -
        replacementIndex -
        Returns:
        Throws:
        java.lang.IndexOutOfBoundsException
      • replace

        public MACAddress replace​(int startIndex,
                                  MACAddressSection replacement)
        Replaces segments starting from startIndex with as many segments as possible from the replacement section
        Parameters:
        startIndex -
        replacement -
        Returns:
        Throws:
        java.lang.IndexOutOfBoundsException
      • toAddressString

        public MACAddressString toAddressString()
        Description copied from class: Address
        Returns a host identifier string representation for this address, which will be already validated.
        Overrides:
        toAddressString in class Address
        Returns:
      • toDashedString

        public java.lang.String toDashedString()
      • toColonDelimitedString

        public java.lang.String toColonDelimitedString()
      • toSpaceDelimitedString

        public java.lang.String toSpaceDelimitedString()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class Address
      • isUnicast

        public boolean isUnicast()
      • isMulticast

        public boolean isMulticast()
        Multicast MAC addresses have the least significant bit of the first octet set to 1.
        Specified by:
        isMulticast in class Address
        See Also:
        InetAddress.isMulticastAddress()
      • isUniversal

        public boolean isUniversal()
        Universal MAC addresses have second the least significant bit of the first octet set to 0.
      • isLocal

        public boolean isLocal()
        Local MAC addresses have the second least significant bit of the first octet set to 1.
        Specified by:
        isLocal in class Address
        Returns: