|
INET Framework for OMNeT++/OMNEST
|
#include <MACAddress.h>
Public Member Functions | |
| MACAddress () | |
| MACAddress (const char *hexstr) | |
| MACAddress (const MACAddress &other) | |
| MACAddress & | operator= (const MACAddress &other) |
| unsigned int | getAddressSize () const |
| unsigned char | getAddressByte (unsigned int k) const |
| void | setAddressByte (unsigned int k, unsigned char addrbyte) |
| bool | tryParse (const char *hexstr) |
| void | setAddress (const char *hexstr) |
| unsigned char * | getAddressBytes () |
| void | setAddressBytes (unsigned char *addrbytes) |
| void | setBroadcast () |
| bool | isBroadcast () const |
| bool | isMulticast () const |
| bool | isUnspecified () const |
| std::string | str () const |
| bool | equals (const MACAddress &other) const |
| bool | operator== (const MACAddress &other) const |
| bool | operator!= (const MACAddress &other) const |
| int | compareTo (const MACAddress &other) const |
| InterfaceToken | formInterfaceIdentifier () const |
Static Public Member Functions | |
| static MACAddress | generateAutoAddress () |
Static Public Attributes | |
| static const MACAddress | UNSPECIFIED_ADDRESS |
| static const MACAddress | BROADCAST_ADDRESS |
Private Attributes | |
| unsigned char | address [6] |
Static Private Attributes | |
| static unsigned int | autoAddressCtr |
Stores an IEEE 802 MAC address (6 octets = 48 bits).
Definition at line 34 of file MACAddress.h.
| MACAddress::MACAddress | ( | const char * | hexstr | ) |
Constructor which accepts a hex string (12 hex digits, may also contain spaces, hyphens and colons)
Definition at line 69 of file MACAddress.cc.
{
setAddress(hexstr);
}
| MACAddress::MACAddress | ( | const MACAddress & | other | ) | [inline] |
| int MACAddress::compareTo | ( | const MACAddress & | other | ) | const |
Returns -1, 0 or 1 as result of comparison of 2 addresses.
Definition at line 159 of file MACAddress.cc.
Referenced by ISIS::electL1DesignatedIS(), Ieee80211MgmtAP::MAC_compare::operator()(), MACRelayUnitBase::MAC_compare::operator()(), MACTable::MAC_compare::operator()(), operator<(), ISISadj::operator<(), operator<=(), operator>(), and operator>=().
{
return memcmp(address, other.address, MAC_ADDRESS_BYTES);
}
| bool MACAddress::equals | ( | const MACAddress & | other | ) | const |
Returns true if the two addresses are equal.
Definition at line 154 of file MACAddress.cc.
Referenced by EtherMACBase::checkDestinationAddress(), AnsaEtherMACBase::checkDestinationAddress(), EtherMACBase::processFrameFromUpperLayer(), AnsaEtherMACBase::processFrameFromUpperLayer(), IPv6NeighbourDiscovery::processNAForOtherNCEStates(), IPv6NeighbourDiscovery::processNSWithSpecifiedSrcAddr(), and IPv6NeighbourDiscovery::processRAForRouterUpdates().
{
return memcmp(address, other.address, MAC_ADDRESS_BYTES)==0;
}
Create interface identifier (IEEE EUI-64) which can be used by IPv6 stateless address autoconfiguration.
Definition at line 164 of file MACAddress.cc.
Referenced by Mac80211::registerInterface(), CSMAMacLayer::registerInterface(), EtherMACBase::registerInterface(), AnsaEtherMACBase::registerInterface(), and Ieee80211Mac::registerInterface().
{
const unsigned char *b = address;
uint32 high = (b[0]<<24) | (b[1]<<16) | (b[2]<<8) | 0xff;
uint32 low = (0xfe<<24) | (b[3]<<16) | (b[4]<<8) | b[5];
return InterfaceToken(low, high, 64);
}
| MACAddress MACAddress::generateAutoAddress | ( | ) | [static] |
Generates a unique address which begins with 0a:aa and ends in a unique suffix.
Definition at line 172 of file MACAddress.cc.
Referenced by ANSASwitchCore::initialize(), Ieee80211Mac::initialize(), EtherMACBase::initializeMACAddress(), AnsaEtherMACBase::initializeMACAddress(), Mac80211::registerInterface(), and CSMAMacLayer::registerInterface().
{
++autoAddressCtr;
unsigned char addrbytes[6];
addrbytes[0] = 0x0A;
addrbytes[1] = 0xAA;
addrbytes[2] = (autoAddressCtr>>24)&0xff;
addrbytes[3] = (autoAddressCtr>>16)&0xff;
addrbytes[4] = (autoAddressCtr>>8)&0xff;
addrbytes[5] = (autoAddressCtr)&0xff;
MACAddress addr;
addr.setAddressBytes(addrbytes);
return addr;
}
| unsigned char MACAddress::getAddressByte | ( | unsigned int | k | ) | const |
Returns the kth byte of the address.
Definition at line 85 of file MACAddress.cc.
{
if (k>=6) throw cRuntimeError("Array of size 6 indexed with %d", k);
return address[k];
}
| unsigned char* MACAddress::getAddressBytes | ( | ) | [inline] |
Returns pointer to internal binary representation of address (array of 6 unsigned chars).
Definition at line 99 of file MACAddress.h.
Referenced by ISIS::handleL1HelloMsg(), and ISIS::handleL2HelloMsg().
{return address;}
| unsigned int MACAddress::getAddressSize | ( | ) | const |
| bool MACAddress::isBroadcast | ( | ) | const |
Returns true this is the broadcast address (hex ff:ff:ff:ff:ff:ff).
Definition at line 134 of file MACAddress.cc.
Referenced by EtherMACBase::checkDestinationAddress(), AnsaEtherMACBase::checkDestinationAddress(), MACRelayUnitBase::handleAndDispatchFrame(), ANSASwitchCore::handleAndDispatchFrame(), Ieee80211MgmtAP::handleDataFrame(), CSMAMacLayer::handleLowerMsg(), Ieee80211Mac::isBroadcast(), and ANSASwitchCore::relay().
| bool MACAddress::isMulticast | ( | ) | const [inline] |
Returns true this is a multicast logical address (starts with bit 1).
Definition at line 119 of file MACAddress.h.
{return address[0]&0x80;};
| bool MACAddress::isUnspecified | ( | ) | const |
Returns true if all address bytes are zero.
Definition at line 139 of file MACAddress.cc.
Referenced by Ieee80211MgmtAPBase::distributeReceivedDataFrame(), Ieee80211MgmtSTASimplified::encapsulate(), Ieee80211Mac::handleUpperMsg(), EtherAppCli::initialize(), ARP::processARPPacket(), EtherMACBase::processFrameFromUpperLayer(), AnsaEtherMACBase::processFrameFromUpperLayer(), IPv6NeighbourDiscovery::processIPv6Datagram(), IPv6NeighbourDiscovery::processNAForIncompleteNCEState(), IPv6NeighbourDiscovery::processNAForOtherNCEStates(), IPv6NeighbourDiscovery::processNSWithSpecifiedSrcAddr(), IPv6NeighbourDiscovery::processRAForRouterUpdates(), Ieee80211MgmtSTA::processScanCommand(), ARP::sendARPRequest(), IPv6::sendDatagramToOutput(), IPv6NeighbourDiscovery::sendSolicitedNA(), EtherMAC2::startFrameTransmission(), IPv6NeighbourDiscovery::validateNSPacket(), and IPv6NeighbourDiscovery::validateRSPacket().
| bool MACAddress::operator!= | ( | const MACAddress & | other | ) | const [inline] |
Returns true if the two addresses are not equal.
Definition at line 144 of file MACAddress.h.
{return !(*this).equals(other);}
| MACAddress & MACAddress::operator= | ( | const MACAddress & | other | ) |
Assignment.
Definition at line 74 of file MACAddress.cc.
{
memcpy(address, other.address, MAC_ADDRESS_BYTES);
return *this;
}
| bool MACAddress::operator== | ( | const MACAddress & | other | ) | const [inline] |
Returns true if the two addresses are equal.
Definition at line 139 of file MACAddress.h.
{return (*this).equals(other);}
| void MACAddress::setAddress | ( | const char * | hexstr | ) |
Converts address value from hex string (12 hex digits, may also contain spaces, hyphens and colons)
Definition at line 118 of file MACAddress.cc.
Referenced by Ieee80211MgmtSTASimplified::initialize(), Ieee80211MgmtBase::initialize(), Ieee80211Mac::initialize(), EtherMACBase::initializeMACAddress(), AnsaEtherMACBase::initializeMACAddress(), MACAddress(), Mac80211::registerInterface(), CSMAMacLayer::registerInterface(), EtherAppCli::resolveDestMACAddress(), ISIS::sendBroadcastHelloMsg(), ISIS::sendL1Csnp(), ISIS::sendL1CSNP(), ISIS::sendL1Psnp(), ISIS::sendL1PSNP(), ISIS::sendLSP(), ISIS::sendMyL1LSPs(), ISIS::sendPTPHelloMsg(), and ISIS::sendSpecificL1LSP().
{
if (!tryParse(hexstr))
throw cRuntimeError("MACAddress: wrong address syntax '%s': 12 hex digits expected, with optional embedded spaces, hyphens or colons", hexstr);
}
| void MACAddress::setAddressByte | ( | unsigned int | k, |
| unsigned char | addrbyte | ||
| ) |
Sets the kth byte of the address.
Definition at line 91 of file MACAddress.cc.
{
if (k>=6) throw cRuntimeError("Array of size 6 indexed with %d", k);
address[k] = addrbyte;
}
| void MACAddress::setAddressBytes | ( | unsigned char * | addrbytes | ) |
Sets address bytes. The argument should point to an array of 6 unsigned chars.
Definition at line 124 of file MACAddress.cc.
Referenced by generateAutoAddress(), and ARP::processOutboundPacket().
{
memcpy(address, addrbytes, MAC_ADDRESS_BYTES);
}
| void MACAddress::setBroadcast | ( | ) |
| std::string MACAddress::str | ( | ) | const |
Converts address to a hex string.
Definition at line 144 of file MACAddress.cc.
Referenced by Ieee80211MgmtSTA::handleAssociationResponseFrame(), Ieee80211Mac::initialize(), EtherMACBase::initializeMACAddress(), AnsaEtherMACBase::initializeMACAddress(), operator<<(), Ieee80211MgmtSTA::processAssociateCommand(), Ieee80211MgmtSTA::processAuthenticateCommand(), Ieee80211MgmtSTA::processDeauthenticateCommand(), EtherMACBase::processFrameFromUpperLayer(), AnsaEtherMACBase::processFrameFromUpperLayer(), Mac80211::registerInterface(), CSMAMacLayer::registerInterface(), Ieee80211MgmtSTA::startAssociation(), and Ieee80211MgmtSTA::startAuthentication().
| bool MACAddress::tryParse | ( | const char * | hexstr | ) |
Sets the address and returns true if the syntax of the string is correct. (See setAddress() for the syntax.)
Definition at line 97 of file MACAddress.cc.
Referenced by EtherAppCli::resolveDestMACAddress(), and setAddress().
{
if (!hexstr)
return false;
// check syntax
int numHexDigits = 0;
for (const char *s = hexstr; *s; s++) {
if (isxdigit(*s))
numHexDigits++;
else if (*s!=' ' && *s!=':' && *s!='-')
return false; // wrong syntax
}
if (numHexDigits != 2*MAC_ADDRESS_BYTES)
return false;
// convert
hextobin(hexstr, address, MAC_ADDRESS_BYTES);
return true;
}
unsigned char MACAddress::address[6] [private] |
Definition at line 37 of file MACAddress.h.
Referenced by compareTo(), equals(), formInterfaceIdentifier(), getAddressByte(), isBroadcast(), isUnspecified(), MACAddress(), operator=(), setAddressByte(), setAddressBytes(), setBroadcast(), str(), and tryParse().
unsigned int MACAddress::autoAddressCtr [static, private] |
Definition at line 38 of file MACAddress.h.
Referenced by generateAutoAddress().
const MACAddress MACAddress::BROADCAST_ADDRESS [static] |
Returns the broadcast (ff:ff:ff:ff:ff:ff) MAC address
Definition at line 45 of file MACAddress.h.
Referenced by IPv6::fragmentAndRoute(), Ieee80211MgmtSTA::processScanCommand(), IPv6::routeMulticastPacket(), and Ieee80211MgmtAP::sendBeacon().
const MACAddress MACAddress::UNSPECIFIED_ADDRESS [static] |
Returns the unspecified (null) MAC address
Definition at line 42 of file MACAddress.h.
Referenced by IPv6NeighbourDiscovery::resolveNeighbour().