Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef MACADDRESS_H_
00019 #define MACADDRESS_H_
00020
00021 #include <string>
00022 #include <omnetpp.h>
00023 #include "INETDefs.h"
00024
00025
00026 #define MAC_ADDRESS_BYTES 6
00027
00028 class InterfaceToken;
00029
00030
00034 class INET_API MACAddress
00035 {
00036 private:
00037 unsigned char address[6];
00038 static unsigned int autoAddressCtr;
00039
00040 public:
00042 static const MACAddress UNSPECIFIED_ADDRESS;
00043
00045 static const MACAddress BROADCAST_ADDRESS;
00046
00050 MACAddress();
00051
00056 MACAddress(const char *hexstr);
00057
00061 MACAddress(const MACAddress& other) {operator=(other);}
00062
00066 MACAddress& operator=(const MACAddress& other);
00067
00071 unsigned int getAddressSize() const;
00072
00076 unsigned char getAddressByte(unsigned int k) const;
00077
00081 void setAddressByte(unsigned int k, unsigned char addrbyte);
00082
00087 bool tryParse(const char *hexstr);
00088
00093 void setAddress(const char *hexstr);
00094
00099 unsigned char *getAddressBytes() {return address;}
00100
00104 void setAddressBytes(unsigned char *addrbytes);
00105
00109 void setBroadcast();
00110
00114 bool isBroadcast() const;
00115
00119 bool isMulticast() const {return address[0]&0x80;};
00120
00124 bool isUnspecified() const;
00125
00129 std::string str() const;
00130
00134 bool equals(const MACAddress& other) const;
00135
00139 bool operator==(const MACAddress& other) const {return (*this).equals(other);}
00140
00144 bool operator!=(const MACAddress& other) const {return !(*this).equals(other);}
00145
00149 int compareTo(const MACAddress& other) const;
00150
00155 InterfaceToken formInterfaceIdentifier() const;
00156
00161 static MACAddress generateAutoAddress();
00162
00163 };
00164
00165 inline std::ostream& operator<<(std::ostream& os, const MACAddress& mac)
00166 {
00167 return os << mac.str();
00168 }
00169
00170 #endif
00171
00172