MCPcopy Create free account
hub / github.com/NetSys/bess / Address

Class Address

core/utils/ether.h:46–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44
45struct [[gnu::packed]] Ethernet {
46 struct [[gnu::packed]] Address {
47 Address() = default;
48 Address(const uint8_t *addr) { bess::utils::Copy(bytes, addr, kSize); }
49 Address(const std::string &str);
50
51 static const size_t kSize = 6;
52
53 // Parses str in "aA:Bb:00:11:22:33" format and saves the address in parsed
54 // Returns false if the format is incorrect.
55 // (in that case, the content of parsed is undefined.)
56 bool FromString(const std::string &str);
57
58 // Returns "aa:bb:00:11:22:33" (all in lower case)
59 std::string ToString() const;
60
61 void Randomize();
62
63 bool IsBroadcast() const {
64 return bytes[0] == 0xff && bytes[1] == 0xff && bytes[2] == 0xff &&
65 bytes[3] == 0xff && bytes[4] == 0xff && bytes[5] == 0xff;
66 }
67
68 bool IsZero() const {
69 return bytes[0] == 0x00 && bytes[1] == 0x00 && bytes[2] == 0x00 &&
70 bytes[3] == 0x00 && bytes[4] == 0x00 && bytes[5] == 0x00;
71 }
72
73 bool operator<(const Address &o) const {
74 for (size_t i = 0; i < kSize; i++) {
75 if (bytes[i] < o.bytes[i]) {
76 return true;
77 }
78 }
79 return false;
80 }
81
82 bool operator==(const Address &o) const {
83 for (size_t i = 0; i < kSize; i++) {
84 if (bytes[i] != o.bytes[i]) {
85 return false;
86 }
87 }
88 return true;
89 }
90
91 bool operator!=(const Address &o) const {
92 for (size_t i = 0; i < kSize; i++) {
93 if (bytes[i] != o.bytes[i]) {
94 return true;
95 }
96 }
97 return false;
98 }
99
100 uint8_t bytes[kSize];
101 };
102
103 enum Type : uint16_t {

Callers 1

PacketTemplateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected