/** * @param name name * @return a new MacAddress object. */ public static MacAddress getByName(String name) { Matcher m = HEX_SEPARATOR_PATTERN.matcher(name); m.find(); return getByName(name, m.group(1)); }
/** * @return true if the MAC address represented by this object is a globally unique address; * otherwise false. */ public boolean isGloballyUnique() { return (getAddress()[0] & 2) == 0; } }
/** @return a MacAddress object */ public MacAddress getLinkLayerAddressAsMacAddress() { return MacAddress.getByAddress(linkLayerAddress); }
public static byte[] convertToEui64(MacAddress macAddr) { byte[] eui64 = new byte[8]; byte[] oui = macAddr.getOui().valueAsByteArray(); oui[0] = (byte)(oui[0] ^ 0x02); System.arraycopy(oui, 0, eui64, 0, 3); eui64[3] = (byte)0xFF; eui64[4] = (byte)0xFE; System.arraycopy(macAddr.getAddress(), 3, eui64, 5, 3); return eui64; }
/** * @param address address * @return a new MacAddress object. */ public static MacAddress getByAddress(byte[] address) { if (address.length != SIZE_IN_BYTES) { throw new IllegalArgumentException( ByteArrays.toHexString(address, ":") + " is invalid for address. The length must be " + SIZE_IN_BYTES); } return new MacAddress(ByteArrays.clone(address)); }
public boolean isVirtualMacAddress(MacAddress macAddress) { return macAddress.getOui().equals(VIRTUAL_MACADDRESS_OUI); }
/** @return a MacAddress object */ public MacAddress getLinkLayerAddressAsMacAddress() { return MacAddress.getByAddress(linkLayerAddress); }
@Override protected int calcHashCode() { final int prime = 31; int result = 17; result = prime * result + address1.hashCode(); result = prime * result + address2.hashCode(); result = prime * result + address3.hashCode(); result = prime * result + duration; result = prime * result + frameControl.hashCode(); result = prime * result + (htControl != null ? htControl.hashCode() : 0); result = prime * result + sequenceControl.hashCode(); return result; }
/** * @param address address * @return a new MacAddress object. */ public static MacAddress getByAddress(byte[] address) { if (address.length != SIZE_IN_BYTES) { throw new IllegalArgumentException( ByteArrays.toHexString(address, ":") + " is invalid for address. The length must be " + SIZE_IN_BYTES); } return new MacAddress(ByteArrays.clone(address)); }
@Override protected Packet getWholePacket() { EthernetPacket.Builder eb = new EthernetPacket.Builder(); eb.dstAddr(MacAddress.getByName("aa:bb:cc:dd:ee:ff")) .srcAddr(MacAddress.getByName("11:22:33:44:55:66")) .type(EtherType.getInstance((short) packet.length())) .payloadBuilder(new SimpleBuilder(packet)) .paddingAtBuild(true); return eb.build(); }
/** * @return true if the MAC address represented by this object is a unicast address; otherwise * false. */ public boolean isUnicast() { return (getAddress()[0] & 1) == 0; }
/** * @param name name * @param separator separator * @return a new MacAddress object. */ public static MacAddress getByName(String name, String separator) { return getByAddress(ByteArrays.parseByteArray(name, separator)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (getClass() != obj.getClass()) return false; Dot11ManagementHeader other = (Dot11ManagementHeader) obj; if (!address1.equals(other.address1)) return false; if (!address2.equals(other.address2)) return false; if (!address3.equals(other.address3)) return false; if (duration != other.duration) return false; if (!frameControl.equals(other.frameControl)) return false; if (htControl == null) { if (other.htControl != null) { return false; } } else if (!htControl.equals(other.htControl)) return false; if (!sequenceControl.equals(other.sequenceControl)) return false; return true; } }
@Override protected int calcHashCode() { int result = 17; result = 31 * result + hardwareType.hashCode(); result = 31 * result + protocolType.hashCode(); result = 31 * result + hardwareAddrLength; result = 31 * result + protocolAddrLength; result = 31 * result + operation.hashCode(); result = 31 * result + srcHardwareAddr.hashCode(); result = 31 * result + srcProtocolAddr.hashCode(); result = 31 * result + dstHardwareAddr.hashCode(); result = 31 * result + dstProtocolAddr.hashCode(); return result; } }
@Override protected Packet getWholePacket() { EthernetPacket.Builder eb = new EthernetPacket.Builder(); eb.dstAddr(MacAddress.getByName("aa:bb:cc:dd:ee:ff")) .srcAddr(MacAddress.getByName("11:22:33:44:55:66")) .type(EtherType.getInstance((short) packet.length())) .payloadBuilder(new SimpleBuilder(packet)) .paddingAtBuild(true); return eb.build(); }
/** * @param value value * @param bo bo * @return byte array */ public static byte[] toByteArray(MacAddress value, ByteOrder bo) { if (bo.equals(LITTLE_ENDIAN)) { return reverse(value.getAddress()); } else { return value.getAddress(); } }
/** * @param array array * @param offset offset * @param bo bo * @return a new MacAddress object. */ public static MacAddress getMacAddress(byte[] array, int offset, ByteOrder bo) { validateBounds(array, offset, MacAddress.SIZE_IN_BYTES); if (bo == null) { throw new NullPointerException(" bo: " + bo); } if (bo.equals(LITTLE_ENDIAN)) { return MacAddress.getByAddress(reverse(getSubArray(array, offset, MacAddress.SIZE_IN_BYTES))); } else { return MacAddress.getByAddress(getSubArray(array, offset, MacAddress.SIZE_IN_BYTES)); } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } ArpHeader other = (ArpHeader) obj; return operation.equals(other.getOperation()) && srcHardwareAddr.equals(other.srcHardwareAddr) && srcProtocolAddr.equals(other.srcProtocolAddr) && dstHardwareAddr.equals(other.dstHardwareAddr) && dstProtocolAddr.equals(other.dstProtocolAddr) && hardwareType.equals(other.hardwareType) && protocolType.equals(other.protocolType) && hardwareAddrLength == other.hardwareAddrLength && protocolAddrLength == other.protocolAddrLength; }