~ubuntu-branches/ubuntu/jaunty/xorp/jaunty

« back to all changes in this revision

Viewing changes to libxorp/mac.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jose Calhariz, Javier Fernandez-Sanguino, Jose Calhariz
  • Date: 2008-01-23 01:24:37 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080123012437-7l2u9r0k8e7op8st
Tags: 1.5~cvs.20080128-1
[ Javier Fernandez-Sanguino ]
* Update to latest CVS contents
* Modify debian/rules to prevent autobuilders from building 
  the binary-independent components: (Closes: #441121)
  - Create a new Build-Depends-Indep with all the TeX
  components used to build documentation
  - Since autobuilders call build, which in turns calls build-indep, hack
    the debian rules file so that the documentation is only built if ps2pdf,
    dvips and pslatex are available. 
* Modify the init.d script:
  - restart action: Do not attempt to stop xorp if not running
  - stop function: fix errors in the script
  - add a try-restart action
  - restructure the init.d script, move the restart code to a function
  - review the use of echo calls and exit values
* Use, as examples, the new boot files at rtrmgr/config/

[ Jose Calhariz ]
* Add depends on ncurses-dev, I don't know why xorp use tigetstr
  function from curses.  This way the depends field change less between
  build environments.
* Removed pushd and popd commands from Makefile and replaced with cd
  commands, was a bashism and FTBFS (closes: #453637)
* debian/control converted to utf-8 (closes: #454026) (closes: #453485)
* init.d/xorp now returns 0 if disabled.
* Added Vcs-Browser and Vcs-Svn fields pointing to the repository of the
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
2
2
 
3
 
// Copyright (c) 2001-2007 International Computer Science Institute
 
3
// Copyright (c) 2001-2008 International Computer Science Institute
4
4
//
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.
14
14
 
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 $"
16
16
 
17
17
#include <vector>
18
18
 
25
25
/* ------------------------------------------------------------------------- */
26
26
/* Base Mac methods */
27
27
 
 
28
Mac::Mac(const uint8_t* from_uint8, size_t len) throw (BadMac)
 
29
{
 
30
    copy_in(from_uint8, len);
 
31
}
 
32
 
28
33
Mac::Mac(const string& from_string) throw (InvalidString)
29
34
{
30
35
    copy_in(from_string);
31
36
}
32
37
 
33
38
size_t
 
39
Mac::copy_out(uint8_t* to_uint8) const
 
40
{
 
41
    if (_srep.empty())
 
42
        return (0);     // XXX: the empty string is valid, so don't copy it
 
43
 
 
44
    // ------------------------------------------------------------------------
 
45
    // I M P O R T A N T !
 
46
    //
 
47
    // Check all known MAC instance classes for whether string is valid
 
48
    // and use the corresponding copy_out() method.
 
49
    //
 
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));
 
55
    }
 
56
 
 
57
    XLOG_UNREACHABLE();
 
58
    return (static_cast<size_t>(-1));
 
59
}
 
60
 
 
61
size_t
 
62
Mac::copy_in(const uint8_t* from_uint8, size_t len) throw (BadMac)
 
63
{
 
64
    size_t ret_value = static_cast<size_t>(-1);
 
65
 
 
66
    // ------------------------------------------------------------------------
 
67
    // I M P O R T A N T !
 
68
    //
 
69
    // Check all known MAC instance classes for whether address length is valid
 
70
    //
 
71
    // Add new address length checks here
 
72
    // ------------------------------------------------------------------------
 
73
    do {
 
74
        if (len == EtherMac::ADDR_BYTELEN) {
 
75
            EtherMac ether_mac(from_uint8);
 
76
            _srep = ether_mac.str();
 
77
            ret_value = len;
 
78
            break;
 
79
        }
 
80
 
 
81
        xorp_throw(BadMac,
 
82
                   c_format("Unknown Mac representation: length = %u",
 
83
                            XORP_UINT_CAST(len)));
 
84
        return (static_cast<size_t>(-1));
 
85
    } while (false);
 
86
 
 
87
    return (ret_value);
 
88
}
 
89
 
 
90
size_t
34
91
Mac::copy_in(const string& from_string) throw (InvalidString)
35
92
{
36
93
    size_t ret_value = static_cast<size_t>(-1);
40
97
    //
41
98
    // Check all known MAC instance classes for whether string is valid
42
99
    //
43
 
    // Add new MyMac::valid methods here
 
100
    // Add new MyMac::valid() methods here
44
101
    // ------------------------------------------------------------------------
45
102
    do {
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.
76
133
    //
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);
84
141
    return (_srep);
85
142
}
86
143
 
 
144
size_t
 
145
Mac::addr_bytelen() const
 
146
{
 
147
    if (_srep.empty())
 
148
        return (0);     // XXX: the empty string is valid, so just return 0
 
149
 
 
150
    // ------------------------------------------------------------------------
 
151
    // I M P O R T A N T !
 
152
    //
 
153
    // Check all known MAC instance classes for whether string is valid
 
154
    // and return the corresponding size.
 
155
    //
 
156
    // Add new MyMac::valid() and MyMac::addr_bytelen() methods here
 
157
    // ------------------------------------------------------------------------
 
158
    if (EtherMac::valid(_srep)) {
 
159
        return EtherMac::addr_bytelen();
 
160
    }
 
161
 
 
162
    XLOG_UNREACHABLE();
 
163
    return (0);
 
164
}
 
165
 
 
166
uint32_t
 
167
Mac::addr_bitlen() const
 
168
{
 
169
    if (_srep.empty())
 
170
        return (0);     // XXX: the empty string is valid, so just return 0
 
171
 
 
172
    // ------------------------------------------------------------------------
 
173
    // I M P O R T A N T !
 
174
    //
 
175
    // Check all known MAC instance classes for whether string is valid
 
176
    // and return the corresponding size.
 
177
    //
 
178
    // Add new MyMac::valid() and MyMac::addr_bitlen() methods here
 
179
    // ------------------------------------------------------------------------
 
180
    if (EtherMac::valid(_srep)) {
 
181
        return EtherMac::addr_bitlen();
 
182
    }
 
183
 
 
184
    XLOG_UNREACHABLE();
 
185
    return (0);
 
186
}
 
187
 
 
188
bool
 
189
Mac::is_zero() const
 
190
{
 
191
    return (*this == ZERO());
 
192
}
 
193
 
87
194
bool
88
195
Mac::is_multicast() const
89
196
{
92
199
    //
93
200
    // Check all known MAC instance classes for whether string is valid
94
201
    //
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);
326
433
 
327
434
    return (addr[0] & MULTICAST_BIT);
328
435
}
 
436
 
 
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"));