1
1
// -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
3
// Copyright (c) 2001-2007 International Computer Science Institute
3
// Copyright (c) 2001-2008 International Computer Science Institute
5
5
// Permission is hereby granted, free of charge, to any person obtaining a
6
6
// copy of this software and associated documentation files (the "Software")
12
12
// notice is a summary of the XORP LICENSE file; the license in that file is
13
13
// legally binding.
15
#ident "$XORP: xorp/libxorp/mac.cc,v 1.19 2007/06/27 01:08:44 pavlin Exp $"
15
#ident "$XORP: xorp/libxorp/mac.cc,v 1.24 2008/01/04 03:16:37 pavlin Exp $"
25
25
/* ------------------------------------------------------------------------- */
26
26
/* Base Mac methods */
28
Mac::Mac(const uint8_t* from_uint8, size_t len) throw (BadMac)
30
copy_in(from_uint8, len);
28
33
Mac::Mac(const string& from_string) throw (InvalidString)
30
35
copy_in(from_string);
39
Mac::copy_out(uint8_t* to_uint8) const
42
return (0); // XXX: the empty string is valid, so don't copy it
44
// ------------------------------------------------------------------------
45
// I M P O R T A N T !
47
// Check all known MAC instance classes for whether string is valid
48
// and use the corresponding copy_out() method.
50
// Add new MyMac::valid() and MyMac::normalize() methods here
51
// ------------------------------------------------------------------------
52
if (EtherMac::valid(_srep)) {
53
EtherMac ether_mac(_srep);
54
return (ether_mac.copy_out(to_uint8));
58
return (static_cast<size_t>(-1));
62
Mac::copy_in(const uint8_t* from_uint8, size_t len) throw (BadMac)
64
size_t ret_value = static_cast<size_t>(-1);
66
// ------------------------------------------------------------------------
67
// I M P O R T A N T !
69
// Check all known MAC instance classes for whether address length is valid
71
// Add new address length checks here
72
// ------------------------------------------------------------------------
74
if (len == EtherMac::ADDR_BYTELEN) {
75
EtherMac ether_mac(from_uint8);
76
_srep = ether_mac.str();
82
c_format("Unknown Mac representation: length = %u",
83
XORP_UINT_CAST(len)));
84
return (static_cast<size_t>(-1));
34
91
Mac::copy_in(const string& from_string) throw (InvalidString)
36
93
size_t ret_value = static_cast<size_t>(-1);
41
98
// Check all known MAC instance classes for whether string is valid
43
// Add new MyMac::valid methods here
100
// Add new MyMac::valid() methods here
44
101
// ------------------------------------------------------------------------
46
103
if (from_string.empty()) {
74
131
// Check all known MAC instance classes for whether string is valid
75
132
// and return the corresponding normalized string.
77
// Add new MyMac::valid and MyMac::normalize() methods here
134
// Add new MyMac::valid() and MyMac::normalize() methods here
78
135
// ------------------------------------------------------------------------
79
136
if (EtherMac::valid(_srep)) {
80
137
return EtherMac::normalize(_srep);
145
Mac::addr_bytelen() const
148
return (0); // XXX: the empty string is valid, so just return 0
150
// ------------------------------------------------------------------------
151
// I M P O R T A N T !
153
// Check all known MAC instance classes for whether string is valid
154
// and return the corresponding size.
156
// Add new MyMac::valid() and MyMac::addr_bytelen() methods here
157
// ------------------------------------------------------------------------
158
if (EtherMac::valid(_srep)) {
159
return EtherMac::addr_bytelen();
167
Mac::addr_bitlen() const
170
return (0); // XXX: the empty string is valid, so just return 0
172
// ------------------------------------------------------------------------
173
// I M P O R T A N T !
175
// Check all known MAC instance classes for whether string is valid
176
// and return the corresponding size.
178
// Add new MyMac::valid() and MyMac::addr_bitlen() methods here
179
// ------------------------------------------------------------------------
180
if (EtherMac::valid(_srep)) {
181
return EtherMac::addr_bitlen();
191
return (*this == ZERO());
88
195
Mac::is_multicast() const
93
200
// Check all known MAC instance classes for whether string is valid
95
// Add new MyMac::valid methods here
202
// Add new MyMac::valid() methods here
96
203
// ------------------------------------------------------------------------
97
204
if (EtherMac::valid(_srep)) {
98
205
EtherMac ether_mac(_srep);
327
434
return (addr[0] & MULTICAST_BIT);
437
const Mac MacConstants::zero(Mac("00:00:00:00:00:00"));
438
const Mac MacConstants::all_ones(Mac("ff:ff:ff:ff:ff:ff"));
439
const Mac MacConstants::lldp_multicast(Mac("01:80:c2:00:00:0e"));