Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

MACAddress Class Reference

#include <MACAddress.h>

Inheritance diagram for MACAddress:

MACAddress_Base cPolymorphic List of all members.

Public Methods

 MACAddress ()
 MACAddress (const char *hexstr)
 MACAddress (const MACAddress &other)
MACAddress & operator= (const MACAddress &other)
virtual unsigned int getAddressArraySize () const
virtual unsigned char getAddress (unsigned int k) const
virtual 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 isEmpty () const
const char * toHexString (char *buf) const
bool equals (const MACAddress &other) const
int compareTo (const MACAddress &other) const

Private Attributes

unsigned char address [6]

Detailed Description

Stores an IEEE 802 MAC address (6 octets = 48 bits).

Definition at line 32 of file MACAddress.h.


Constructor & Destructor Documentation

MACAddress::MACAddress  
 

Default constructor initializes address bytes to zero.

Definition at line 66 of file MACAddress.cc.

References address.

00066                        : MACAddress_Base()
00067 {
00068     address[0]=address[1]=address[2]=address[3]=address[4]=address[5]=0;
00069 }

MACAddress::MACAddress const char *    hexstr
 

Constructor which accepts hex string or the string "auto".

Definition at line 71 of file MACAddress.cc.

References setAddress().

00071                                          : MACAddress_Base()
00072 {
00073     setAddress(hexstr);
00074 }

MACAddress::MACAddress const MACAddress &    other [inline]
 

Copy constructor.

Definition at line 49 of file MACAddress.h.

References operator=().

00049 : MACAddress_Base() {operator=(other);}


Member Function Documentation

int MACAddress::compareTo const MACAddress &    other const
 

Returns -1, 0 or 1 as result of comparison of 2 addresses.

Definition at line 143 of file MACAddress.cc.

References address, and MAC_ADDRESS_BYTES.

Referenced by MACRelayUnitBase::MAC_compare::operator()().

00144 {
00145     return memcmp(address, other.address, MAC_ADDRESS_BYTES);
00146 }

bool MACAddress::equals const MACAddress &    other const
 

Returns true if 2 addresses are equal.

Definition at line 138 of file MACAddress.cc.

References address, and MAC_ADDRESS_BYTES.

Referenced by EtherMAC::processFrameFromUpperLayer(), and EtherMAC::processReceivedDataFrame().

00139 {
00140     return memcmp(address, other.address, MAC_ADDRESS_BYTES)==0;
00141 }

unsigned char MACAddress::getAddress unsigned int    k const [virtual]
 

Returns the kth byte of the address.

Implements MACAddress_Base.

Definition at line 88 of file MACAddress.cc.

References address.

00089 {
00090     if (k>=6) throw new cException("Array of size 6 indexed with %d", k);
00091     return address[k];
00092 }

unsigned int MACAddress::getAddressArraySize   const [virtual]
 

Returns 6.

Implements MACAddress_Base.

Definition at line 83 of file MACAddress.cc.

00084 {
00085     return 6;
00086 }

unsigned char* MACAddress::getAddressBytes   [inline]
 

Returns pointer to internal binary representation of address (array of 6 unsigned chars).

Definition at line 74 of file MACAddress.h.

References address.

00074 {return address;}

bool MACAddress::isBroadcast   const
 

Returns true this is the broadcast address (hex ff:ff:ff:ff:ff:ff).

Definition at line 118 of file MACAddress.cc.

References address.

Referenced by MACRelayUnitBase::handleAndDispatchFrame(), and EtherMAC::processReceivedDataFrame().

00119 {
00120     return address[0]==0xff && address[1]==0xff && address[2]==0xff && address[3]==0xff &&
00121            address[4]==0xff && address[5]==0xff;
00122 }

bool MACAddress::isEmpty   const
 

Returns true if all address bytes are zero.

Definition at line 124 of file MACAddress.cc.

References address.

Referenced by EtherAppCli::initialize(), and EtherMAC::processFrameFromUpperLayer().

00125 {
00126     return !(address[0] || address[1] || address[2] || address[3] || address[4] || address[5]);
00127 }

bool MACAddress::isMulticast   const [inline]
 

Returns true this is a multicast logical address (starts with bit 1).

Definition at line 90 of file MACAddress.h.

References address.

00090 {return address[0]&0x80;};

MACAddress & MACAddress::operator= const MACAddress &    other
 

Assignment.

Definition at line 76 of file MACAddress.cc.

References address, MAC_ADDRESS_BYTES, and MACAddress_Base::operator=().

Referenced by MACAddress().

00077 {
00078     MACAddress_Base::operator=(other);
00079     memcpy(address, other.address, MAC_ADDRESS_BYTES);
00080     return *this;
00081 }

void MACAddress::setAddress const char *    hexstr
 

Converts address value from hex string. The string "auto" is also accepted, it'll generate a unique address starting with "A0 00".

Definition at line 100 of file MACAddress.cc.

References address, and MAC_ADDRESS_BYTES.

00101 {
00102     if (!hexstr)
00103         throw new cException("MACAddress::setAddress(const char *): got null pointer");
00104     if (hextobin(hexstr, address, MAC_ADDRESS_BYTES)!=MAC_ADDRESS_BYTES)
00105         throw new cException("MACAddress::setAddress(const char *): hex string \"%s\" too short, should be 12 hex digits", hexstr);
00106 }

void MACAddress::setAddress unsigned int    k,
unsigned char    addrbyte
[virtual]
 

Sets the kth byte of the address.

Implements MACAddress_Base.

Definition at line 94 of file MACAddress.cc.

References address.

Referenced by EtherMAC::initialize(), and MACAddress().

00095 {
00096     if (k>=6) throw new cException("Array of size 6 indexed with %d", k);
00097     address[k] = addrbyte;
00098 }

void MACAddress::setAddressBytes unsigned char *    addrbytes
 

Sets address bytes. The argument should point to an array of 6 unsigned chars.

Definition at line 108 of file MACAddress.cc.

References address, and MAC_ADDRESS_BYTES.

Referenced by EtherMAC::initialize().

00109 {
00110     memcpy(address, addrbytes, MAC_ADDRESS_BYTES);
00111 }

void MACAddress::setBroadcast  
 

Sets the address to the broadcast address (hex ff:ff:ff:ff:ff:ff).

Definition at line 113 of file MACAddress.cc.

References address.

00114 {
00115     address[0]=address[1]=address[2]=address[3]=address[4]=address[5]=0xff;
00116 }

const char * MACAddress::toHexString char *    buf const
 

Converts address to hext string and places result into passed buffer.

Definition at line 129 of file MACAddress.cc.

References address, and MAC_ADDRESS_BYTES.

Referenced by EtherMAC::initialize(), and EtherMAC::processFrameFromUpperLayer().

00130 {
00131     char *s = buf;
00132     for (int i=0; i<MAC_ADDRESS_BYTES; i++, s+=3)
00133         sprintf(s,"%2.2X:",address[i]);
00134     *(s-1)='\0';
00135     return buf;
00136 }


Member Data Documentation

unsigned char MACAddress::address[6] [private]
 

Definition at line 35 of file MACAddress.h.

Referenced by compareTo(), equals(), getAddress(), getAddressBytes(), isBroadcast(), isEmpty(), isMulticast(), MACAddress(), operator=(), setAddress(), setAddressBytes(), setBroadcast(), and toHexString().


The documentation for this class was generated from the following files:
Generated on Sat May 15 20:30:48 2004 for Ethernet by doxygen1.2.17