#include <MACAddress.h>
Public Member Functions | |
| MACAddress () | |
| MACAddress (const char *hexstr) | |
| MACAddress (const MACAddress &other) | |
| MACAddress & | operator= (const MACAddress &other) |
| unsigned int | getAddressArraySize () const |
| unsigned char | getAddress (unsigned int k) const |
| void | setAddress (unsigned int k, unsigned char addrbyte) |
| 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 |
| 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 |
|
|
Default constructor initializes address bytes to zero.
|
|
|
Constructor which accepts hex string or the string "auto". 00075 {
00076 setAddress(hexstr);
00077 }
|
|
|
Copy constructor. 00061 {operator=(other);}
|
|
|
Returns -1, 0 or 1 as result of comparison of 2 addresses. 00146 {
00147 return memcmp(address, other.address, MAC_ADDRESS_BYTES);
00148 }
|
|
|
Returns true if the two addresses are equal. 00141 {
00142 return memcmp(address, other.address, MAC_ADDRESS_BYTES)==0;
00143 }
|
|
|
Create interface identifier (IEEE EUI-64) which can be used by IPv6 stateless address autoconfiguration. 00151 {
00152 const unsigned char *b = address;
00153 uint32 high = (b[0]<<24) | (b[1]<<16) | (b[2]<<8) | 0xff;
00154 uint32 low = (0xfe<<24) | (b[3]<<16) | (b[4]<<8) | b[5];
00155 return InterfaceToken(low, high, 64);
00156 }
|
|
|
Generates a unique address which begins with 0a:aa and ends in a unique suffix. 00159 {
00160 ++autoAddressCtr;
00161
00162 unsigned char addrbytes[6];
00163 addrbytes[0] = 0x0A;
00164 addrbytes[1] = 0xAA;
00165 addrbytes[2] = (autoAddressCtr>>24)&0xff;
00166 addrbytes[3] = (autoAddressCtr>>16)&0xff;
00167 addrbytes[4] = (autoAddressCtr>>8)&0xff;
00168 addrbytes[5] = (autoAddressCtr)&0xff;
00169
00170 MACAddress addr;
00171 addr.setAddressBytes(addrbytes);
00172 return addr;
00173 }
|
|
|
Returns the kth byte of the address. 00091 {
00092 if (k>=6) throw new cException("Array of size 6 indexed with %d", k);
00093 return address[k];
00094 }
|
|
|
Returns 6. 00086 {
00087 return 6;
00088 }
|
|
|
Returns pointer to internal binary representation of address (array of 6 unsigned chars). 00092 {return address;}
|
|
|
Returns true this is the broadcast address (hex ff:ff:ff:ff:ff:ff). 00121 {
00122 return (address[0]&address[1]&address[2]&address[3]&address[4]&address[5])==0xff;
00123 }
|
|
|
Returns true this is a multicast logical address (starts with bit 1). 00112 {return address[0]&0x80;};
|
|
|
Returns true if all address bytes are zero. 00126 {
00127 return !(address[0] || address[1] || address[2] || address[3] || address[4] || address[5]);
00128 }
|
|
|
Assignment. 00080 {
00081 memcpy(address, other.address, MAC_ADDRESS_BYTES);
00082 return *this;
00083 }
|
|
|
Returns true if the two addresses are equal. 00132 {return (*this).equals(other);}
|
|
|
Converts address value from hex string. The string "auto" is also accepted, it'll generate a unique address starting with "A0 00". 00103 {
00104 if (!hexstr)
00105 throw new cException("MACAddress::setAddress(const char *): got null pointer");
00106 if (hextobin(hexstr, address, MAC_ADDRESS_BYTES)!=MAC_ADDRESS_BYTES)
00107 throw new cException("MACAddress::setAddress(const char *): hex string \"%s\" too short, should be 12 hex digits", hexstr);
00108 }
|
|
||||||||||||
|
Sets the kth byte of the address. 00097 {
00098 if (k>=6) throw new cException("Array of size 6 indexed with %d", k);
00099 address[k] = addrbyte;
00100 }
|
|
|
Sets address bytes. The argument should point to an array of 6 unsigned chars. 00111 {
00112 memcpy(address, addrbytes, MAC_ADDRESS_BYTES);
00113 }
|
|
|
Sets the address to the broadcast address (hex ff:ff:ff:ff:ff:ff).
|
|
|
Converts address to a hex string. 00131 {
00132 char buf[20];
00133 char *s = buf;
00134 for (int i=0; i<MAC_ADDRESS_BYTES; i++, s+=3)
00135 sprintf(s,"%2.2X-",address[i]);
00136 *(s-1)='\0';
00137 return std::string(buf);
00138 }
|
|
|
|
|
|
|
|
|
Returns the broadcast (ff:ff:ff:ff:ff:ff) MAC address |
|
|
Returns the unspecified (null) MAC address |
1.4.1