hwsd  2.0.0
Local and remote ZeroConf service discovery for hardware resources
netInfo.h
1 
2 /* Copyright (c) 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
3  * 2013, Stefan.Eilemann@epfl.ch
4  *
5  * This library is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License version 2.1 as published
7  * by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef HWSD_NETINFO_H
20 #define HWSD_NETINFO_H
21 
22 #include <hwsd/api.h>
23 #include <hwsd/nodeInfo.h> // base class
24 
25 #include <climits>
26 #include <lunchbox/debug.h>
27 #include <ostream>
28 
29 namespace hwsd
30 {
32 struct NetInfo : public NodeInfo
33 {
34  enum Type
35  {
36  TYPE_ETHERNET = LB_BIT1,
37  TYPE_INFINIBAND = LB_BIT2,
38  TYPE_LOOPBACK = LB_BIT3,
40  TYPE_TUNNEL_6TO4 = LB_BIT5,
41  TYPE_UNKNOWN = LB_BIT31,
42  TYPE_ALL = LB_BIT_ALL_32
43  };
44 
46  static const unsigned defaultValue = UINT_MAX;
47 
49  HWSD_API NetInfo();
50 
52  HWSD_API bool operator==(const NetInfo& rhs) const;
53 
55  HWSD_API bool operator!=(const NetInfo& rhs) const;
56 
57  HWSD_API std::string getType() const;
58 
59  HWSD_API void setType(const std::string& strType);
60 
63 
65  std::string name;
66 
68  std::string hostname;
69 
71  std::string hwAddress;
72 
74  std::string inetAddress;
75 
77  std::string inet6Address;
78 
80  unsigned int linkspeed;
81 
83  bool up;
84 };
85 
86 inline std::ostream& operator<<(std::ostream& os, const NetInfo& info)
87 {
88  os << "NetInfo\n"
89  << static_cast<const NodeInfo&>(info) << " Type " << info.getType()
90  << std::endl
91  << " Status " << (info.up ? "UP" : "DOWN") << std::endl;
92  if (!info.name.empty())
93  os << " Name " << info.name << std::endl;
94  if (!info.hostname.empty())
95  os << " Hostname " << info.hostname << std::endl;
96  if (!info.hwAddress.empty())
97  os << " HWaddr " << info.hwAddress << std::endl;
98  if (!info.inetAddress.empty())
99  os << " IPv4 " << info.inetAddress << std::endl;
100  if (!info.inet6Address.empty())
101  os << " IPv6 " << info.inet6Address << std::endl;
102  if (info.linkspeed != NetInfo::defaultValue)
103  os << " Linkspeed " << info.linkspeed << "Mbps" << std::endl;
104  return os;
105 }
106 }
107 
108 #endif // HWSD_NETINFO_H
std::string hostname
The hostname assigned to this interface.
Definition: netInfo.h:68
Defines export visibility macros for library hwsd.
static const unsigned defaultValue
A non-enumerated value.
Definition: netInfo.h:46
gif interface on Darwin
Definition: netInfo.h:39
unsigned int linkspeed
The interface link speed in Megabits per second.
Definition: netInfo.h:80
bool operator!=(const NetInfo &rhs) const
A structure containing node-specific information.
Definition: nodeInfo.h:30
std::string name
The name of the interface (e.g.
Definition: netInfo.h:65
Definition: filter.h:27
std::string inet6Address
The IPv6 address (&#39;:&#39; as separator) of the interface.
Definition: netInfo.h:77
stf interface on Darwin
Definition: netInfo.h:40
A structure containing network-specific information.
Definition: netInfo.h:32
Type type
The type of the network interface.
Definition: netInfo.h:62
bool up
Whether the interface is up or down.
Definition: netInfo.h:83
bool operator==(const NetInfo &rhs) const
NetInfo()
Default constructor pointing to the default display.
std::string hwAddress
The MAC address (&#39;:&#39; as separator) of the interface.
Definition: netInfo.h:71
std::string inetAddress
The IPv4 address (&#39;:&#39; as separator) of the interface.
Definition: netInfo.h:74