inet.ipaddr.mac

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

      • isExtended

        public boolean isExtended()
      • isAllAddresses

        public boolean isAllAddresses()
      • maxSegmentValue

        public static int maxSegmentValue()
      • getMaxSegmentValue

        public int getMaxSegmentValue()
        Specified by:
        getMaxSegmentValue in class Address
        Returns:
        the maximum possible segment value for this type of address. Note this is not the maximum value of the segments in this specific address.
      • 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:
      • 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, or if the given increment is negative the given increment downwards into the subnet range, or if this is just an individual series, it simply adds the increment to this. If the increment is 0, then this series is returned.

        If the subnet has multiple values and the increment exceeds the subnet size, then the amount by which is exceeds the size is added to the upper series of the range (the final iterator value) or is subtracted from the lower series of the range (the first iterator value) if negative.

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

        Therefore, to get the series just above the highest series of the subnet, use an increment of size:count > 1 ? count + 1 : 1 where count is the subnet size. To get the series just below the lowest series of the subnet, use an increment of size:-(count > 1 ? count + 1 : 1) where count is the subnet size.

        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 coundary
        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)
        Description copied from interface: AddressSegmentSeries
        Increases or decreases prefix length by the given increment.

        When prefix length is increased, the bits moved within the prefix become zero. When the prefix is extended beyond the segment series boundary, it is removed. When a prefix length is decreased, the bits moved outside the prefix become zero.

        Specified by:
        adjustPrefixLength in interface AddressSegmentSeries
        Specified by:
        adjustPrefixLength in class Address
        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.

        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:
        See Also:
        AddressSegmentSeries.applyPrefixLength(int)
      • 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:
      • 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
      • 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:
      • toDottedString

        public java.lang.String toDottedString()
      • 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: