inet.ipaddr.mac

Class MACAddressSection

    • Field Detail

      • addressSegmentIndex

        public final int addressSegmentIndex
      • extended

        public final boolean extended
    • Constructor Detail

      • MACAddressSection

        public MACAddressSection(MACAddressSegment segment)
        Constructs a single segment section, the segment being the leading segment.
        Parameters:
        segment -
      • MACAddressSection

        public MACAddressSection(MACAddressSegment segment,
                                 int startIndex,
                                 boolean extended)
        Constructs a single segment section with the segment at the given index in the address.
        Parameters:
        segment -
      • MACAddressSection

        public MACAddressSection(MACAddressSegment[] segments)
        Use this constructor for any address section that includes the leading segment of a MAC address
      • MACAddressSection

        public MACAddressSection(MACAddressSegment[] segments,
                                 int startIndex,
                                 boolean extended)
      • MACAddressSection

        public MACAddressSection(byte[] bytes,
                                 int startIndex,
                                 boolean extended)
      • MACAddressSection

        public MACAddressSection(byte[] bytes)
      • MACAddressSection

        public MACAddressSection(long value,
                                 int startIndex,
                                 boolean extended)
      • MACAddressSection

        public MACAddressSection(long value)
    • Method Detail

      • getSegments

        public void getSegments(int start,
                                int end,
                                AddressSegment[] segs,
                                int destIndex)
        Description copied from interface: AddressSegmentSeries
        get the segments from start to end and insert into the segs array at the the given index
        Specified by:
        getSegments in interface AddressSegmentSeries
        Parameters:
        start - the first segment index from this series to be included
        end - the first segment index to be excluded
        segs - the target array
        destIndex - where to insert the segments in the segs array
      • isExtended

        public boolean isExtended()
        Returns:
        whether this section is part of a larger EUI-64 address.
      • isEntireAddress

        public boolean isEntireAddress(boolean extended)
      • getSegments

        public void getSegments(java.util.Collection<? super MACAddressSegment> segs)
      • getSegments

        public void getSegments(int start,
                                int end,
                                java.util.Collection<? super MACAddressSegment> segs)
      • 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:
      • 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:
      • getByteCount

        public int getByteCount()
        Description copied from interface: AddressComponent
        returns the number of bytes in each of the address components represented by this instance
        Specified by:
        getByteCount in interface AddressComponent
        Returns:
      • getOUISegmentCount

        public int getOUISegmentCount()
      • getODISegmentCount

        public int getODISegmentCount()
      • getPrefixLength

        public java.lang.Integer getPrefixLength()
        Description copied from interface: AddressDivisionSeries
        The bit-length of the portion of the address that is not specific to an individual address but common amongst a group of addresses.

        Typically this is the largest number of bits in the upper-most portion of the section for which the remaining bits assume all possible values.

        For IP addresses, this must be explicitly defined when the address is created. For example, 1.2.0.0/16 has a prefix length of 16, while 1.2.*.* has no prefix length, even though they both represent the same set of addresses and are considered equal. Prefixes can be considered variable for any given IP addresses and can depend on the routing table.

        The methods AddressDivisionSeries.getMinPrefixLengthForBlock() and AddressDivisionSeries.getPrefixLengthForSingleBlock() can help you to obtain or define a prefix length if one does not exist already. 1.2.0.0/16 and 1.2.*.* both the same equivalent and minimum prefix length of 16.

        For MAC addresses, the prefix is initially defined by the range, so 1:2:3:*:*:* has a prefix length of 24 by definition. Addresses derived from the original may retain the original prefix length regardless of their range.

        Specified by:
        getPrefixLength in interface AddressDivisionSeries
        Overrides:
        getPrefixLength in class AddressDivisionGrouping
        Returns:
        the number of bits in the prefix. The prefix is the smallest bit length x for which all possible values with the same first x bits are included in this range of sections, unless that value x matches the bit count of this section, in which case the prefix is null. If the prefix is the OUI bit length (24) then the ODI segments cover all possibly values.
      • toOUIPrefixBlock

        public MACAddressSection toOUIPrefixBlock()
        Returns a section in which the range of values match the block for the OUI (organizationally unique identifier) bytes
        Returns:
      • toEUI64IPv6

        public IPv6AddressSection toEUI64IPv6()
        Converts to Ipv6. Any MAC prefix length is ignored. Other elements of this address section are incorporated into the conversion.
        Returns:
      • isEUI64

        public boolean isEUI64(boolean asMAC)
        Equivalent to isEUI64(asMAC, false)
        Returns:
      • isEUI64

        public boolean isEUI64(boolean asMAC,
                               boolean partial)
        Whether this section is consistent with an 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:
        partial - whether missing segments are considered a match (this only has an effect if this section came from an extended 8 byte address), or in other words, we don't consider 6 byte addresses to be "missing" the bytes that would make it 8 byte.
        asMAC - whether to search for the ffff or fffe pattern
        Returns:
      • toEUI64

        public MACAddressSection toEUI64(boolean asMAC)
        If this section is part of a shorter 48 bit MAC or EUI-48 address see isExtended(), then the required sections are inserted (FF-FF for MAC, FF-FE for EUI-48) to extend it to EUI-64. However, if the section does not encompass the parts of the address where the new sections should be placed, then the section is unchanged. If the section is already part of an EUI-64 address, then it is checked to see if it has the segments that identify it as extended to EUI-64 (FF-FF for MAC, FF-FE for EUI-48), and if not, IncompatibleAddressException is thrown.
        Parameters:
        asMAC -
        Returns:
      • replace

        public MACAddressSection replace(int index,
                                         MACAddressSection replacement)
        Replace the segments of this section starting at the given index with the given replacement segments
        Parameters:
        index -
        replacement -
        Returns:
      • replace

        public MACAddressSection replace(int startIndex,
                                         int endIndex,
                                         MACAddressSection replacement,
                                         int replacementStartIndex,
                                         int replacementEndIndex)
        Replaces segments starting from startIndex and ending before endIndex with the segments starting at replacementStartIndex and ending before replacementEndIndex from the replacement section
        Parameters:
        startIndex -
        endIndex -
        replacement -
        replacementStartIndex -
        replacementEndIndex -
        Returns:
        Throws:
        java.lang.IndexOutOfBoundsException
        AddressValueException - if the resulting section would exceed the maximum segment count for this address type and version
      • contains

        public boolean contains(MACAddressSection other)
        Parameters:
        other -
        Returns:
        whether this section contains the given address section
      • longValue

        public long longValue()
      • upperLongValue

        public long upperLongValue()
      • adjustPrefixBySegment

        public MACAddressSection 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 AddressSection
        Specified by:
        adjustPrefixBySegment in interface AddressSegmentSeries
        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 MACAddressSection 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 AddressSection
        Specified by:
        adjustPrefixLength in interface AddressSegmentSeries
        Returns:
      • setPrefixLength

        public MACAddressSection 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 AddressSection
        Specified by:
        setPrefixLength in interface AddressSegmentSeries
        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:
      • increment

        public MACAddressSection 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 AddressSection
        Specified by:
        increment in interface AddressSegmentSeries
        Returns:
      • toHexString

        public java.lang.String toHexString(boolean with0xPrefix)
        Writes this address as a single hexadecimal value with always the exact same number of characters, with or without a preceding 0x prefix.
        Specified by:
        toHexString in interface AddressComponent
      • toNormalizedString

        public java.lang.String toNormalizedString()
        The normalized string returned by this method is the most common representation of MAC addresses: xx:xx:xx:xx:xx:xx
        Specified by:
        toNormalizedString in interface AddressComponent
        Returns:
      • toCanonicalString

        public java.lang.String toCanonicalString()
        This produces a canonical string using the canonical standardized IEEE 802 MAC address representation of xx-xx-xx-xx-xx-xx For range segments, '..' is used: 11-22-33..44-55-66
        Specified by:
        toCanonicalString in interface AddressSegmentSeries
        Returns:
      • toCompressedString

        public java.lang.String toCompressedString()
        This produces a shorter string for the address that uses the canonical representation but not using leading zeroes. Each address has a unique compressed string.
        Specified by:
        toCompressedString in interface AddressSegmentSeries
        Returns:
      • toDottedString

        public java.lang.String toDottedString()
        This produces the dotted hexadecimal format aaaa.bbbb.cccc
      • toSpaceDelimitedString

        public java.lang.String toSpaceDelimitedString()
        This produces a string delimited by spaces: aa bb cc dd ee ff
      • toDashedString

        public java.lang.String toDashedString()
      • toColonDelimitedString

        public java.lang.String toColonDelimitedString()
      • getSegmentStrings

        public java.lang.String[] getSegmentStrings()
        Description copied from interface: AddressSegmentSeries
        Returns the an array with the values of each segment as they would appear in the normalized with wildcards string.
        Specified by:
        getSegmentStrings in interface AddressSegmentSeries
        Returns:
      • contains

        public boolean contains(AddressSection other)
        Description copied from interface: AddressSection
        Determines if one section contains another. Sections must have the same number of segments to be comparable. For sections which are aware of their position in an address (IPv6 and MAC), their respective positions must match to be comparable.
        Specified by:
        contains in interface AddressSection
        Returns:
        whether this section contains the given address section