IBR-DTNSuite  0.10
vinterface.cpp
Go to the documentation of this file.
1 /*
2  * vinterface.cpp
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #include "ibrcommon/config.h"
24 #include "ibrcommon/net/vsocket.h"
25 #include <net/if.h>
26 
27 namespace ibrcommon
28 {
29  const std::string vinterface::LOOPBACK = "loopback";
30  const std::string vinterface::ANY = "any";
31 
33  : _name()
34  {
35  }
36 
37  vinterface::vinterface(std::string name)
38  : _name(name)
39  {
40  }
41 
43  {
44  }
45 
46  const std::string vinterface::toString() const
47  {
48  if (_name.length() == 0) return "<any>";
49  return _name;
50  }
51 
53  {
54  return (_name == LOOPBACK);
55  }
56 
57  bool vinterface::isAny() const
58  {
59  return (_name == ANY);
60  }
61 
62  uint32_t vinterface::getIndex() const
63  {
64  return ::if_nametoindex(_name.c_str());
65  }
66 
67  const std::list<vaddress> vinterface::getAddresses(const std::string &scope) const
68  {
69  if (empty()) throw interface_not_set();
71  }
72 
73  bool vinterface::up() const {
74  return !getAddresses().empty();
75  }
76 
77  bool vinterface::operator<(const vinterface &obj) const
78  {
79  return (_name < obj._name);
80  }
81 
82  bool vinterface::operator==(const vinterface &obj) const
83  {
84  return (obj._name == _name);
85  }
86 
87  bool vinterface::operator!=(const vinterface &obj) const
88  {
89  return (obj._name != _name);
90  }
91 
92  bool vinterface::empty() const
93  {
94  return (_name.length() == 0);
95  }
96 }