27import org.jau.util.BasicTypes;
28import java.nio.ByteOrder;
44 public static final EUI48 ANY_DEVICE =
new EUI48(
new byte[] { (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00 }, ByteOrder.LITTLE_ENDIAN );
46 public static final EUI48 ALL_DEVICE =
new EUI48(
new byte[] { (byte)0xff, (
byte)0xff, (byte)0xff, (
byte)0xff, (byte)0xff, (
byte)0xff }, ByteOrder.LITTLE_ENDIAN );
48 public static final EUI48 LOCAL_DEVICE =
new EUI48(
new byte[] { (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0xff, (byte)0xff, (
byte)0xff }, ByteOrder.LITTLE_ENDIAN );
57 public final byte b[];
59 private volatile int hash;
65 static final int byte_size = 6;
79 public static boolean scanEUI48(
final String str,
final EUI48 dest,
final StringBuilder errmsg) {
80 if( 17 != str.length() ) {
81 errmsg.append(
"EUI48 string not of length 17 but "+str.length()+
": "+str);
85 if( ByteOrder.LITTLE_ENDIAN == ByteOrder.nativeOrder() ) {
86 for(
int i=0; i<byte_size; i++) {
87 dest.
b[byte_size-1-i] = Integer.valueOf(str.substring(i*2+i, i*2+i+2), 16).byteValue();
90 for(
int i=0; i<byte_size; i++) {
91 dest.
b[i] = Integer.valueOf(str.substring(i*2+i, i*2+i+2), 16).byteValue();
94 }
catch (
final NumberFormatException e) {
95 errmsg.append(
"EUI48 string not in format '01:02:03:0A:0B:0C' but "+str+
"; "+e.getMessage());
111 public EUI48(
final String str)
throws IllegalArgumentException {
112 final StringBuilder errmsg =
new StringBuilder();
113 b =
new byte[byte_size];
115 throw new IllegalArgumentException(errmsg.toString());
127 public EUI48(
final byte stream[],
final int pos,
final ByteOrder byte_order) {
128 if( byte_size > ( stream.length - pos ) ) {
129 throw new IllegalArgumentException(
"EUI48 stream ( "+stream.length+
" - "+pos+
" ) < "+byte_size+
" bytes");
131 b =
new byte[byte_size];
132 if( byte_order == ByteOrder.nativeOrder() ) {
133 System.arraycopy(stream, pos,
b, 0, byte_size);
146 public EUI48(
final byte address[],
final ByteOrder byte_order) {
147 this(address, 0, byte_order);
152 b =
new byte[byte_size];
156 public final boolean equals(
final Object obj) {
160 if (obj ==
null || !(obj instanceof
EUI48)) {
163 final byte[] b2 = ((
EUI48)obj).b;
164 return b[0] == b2[0] &&
195 h = ( ( h << 5 ) - h ) +
b[1];
196 h = ( ( h << 5 ) - h ) +
b[2];
197 h = ( ( h << 5 ) - h ) +
b[3];
198 h = ( ( h << 5 ) - h ) +
b[4];
199 h = ( ( h << 5 ) - h ) +
b[5];
217 b[0] = 0;
b[1] = 0;
b[2] = 0;
218 b[3] = 0;
b[4] = 0;
b[5] = 0;
233 public final void put(
final byte[] sink,
final int sink_pos,
final ByteOrder byte_order) {
234 if( byte_size > ( sink.length - sink_pos ) ) {
235 throw new IllegalArgumentException(
"Stream ( "+sink.length+
" - "+sink_pos+
" ) < "+byte_size+
" bytes");
237 if( byte_order == ByteOrder.nativeOrder() ) {
238 System.arraycopy(
b, 0, sink, sink_pos, byte_size);
267 return 0 <=
indexOf(needle, ByteOrder.nativeOrder());
280 final StringBuilder sb =
new StringBuilder(17);
281 if( ByteOrder.LITTLE_ENDIAN == ByteOrder.nativeOrder() ) {
306 return sb.toString();
A 48 bit EUI-48 sub-identifier, see EUI48.
final byte b[]
The EUI48 sub-address, always 6 bytes reserved.
static int indexOf(final byte haystack_b[], final int haystack_length, final byte needle_b[], final int needle_length, final ByteOrder byte_order)
Find index of needle within haystack in the given byte order.
int length
The actual length in bytes of the EUI48 sub-address, less or equal 6 bytes.
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
void clearHash()
Method clears the cached hash value.
static boolean scanEUI48(final String str, final EUI48 dest, final StringBuilder errmsg)
Fills given EUI48 instance via given string representation.
EUI48()
Construct empty unset instance.
static final EUI48 LOCAL_DEVICE
EUI48 MAC address matching local device, i.e.
final byte b[]
The 6 byte EUI48 address.
static final EUI48 ANY_DEVICE
EUI48 MAC address matching any device, i.e.
static final EUI48 ALL_DEVICE
EUI48 MAC address matching all device, i.e.
EUI48(final String str)
Construct instance via given string representation.
EUI48(final byte address[], final ByteOrder byte_order)
Copy address bytes from given source and byte order, while converting them to ByteOrder#nativeOrder()...
boolean contains(final EUI48Sub needle)
Returns true, if given EUI48Sub is contained in here.
final void put(final byte[] sink, final int sink_pos, final ByteOrder byte_order)
Method transfers all bytes representing this instance into the given destination array at the given p...
void clear()
Method clears the underlying byte array b and cached hash value.
int indexOf(final EUI48Sub needle, final ByteOrder byte_order)
Finds the index of given EUI48Sub needle within this instance haystack in the given byte order.
EUI48(final byte stream[], final int pos, final ByteOrder byte_order)
Copy address bytes from given source and byte order, while converting them to ByteOrder#nativeOrder()...
final boolean equals(final Object obj)
static void bswap_6bytes(final byte[] source, final int source_pos, final byte[] sink, final int sink_pos)
static StringBuilder byteHexString(final StringBuilder sb, final byte value, final boolean lowerCase)
Produce a hexadecimal string representation of the given byte value.