Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Interface.h
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Interface.h
17  * Represents a network interface.
18  * Copyright (C) 2010 Simon Newton
19  */
20 
21 #ifndef INCLUDE_OLA_NETWORK_INTERFACE_H_
22 #define INCLUDE_OLA_NETWORK_INTERFACE_H_
23 
24 #include <ola/network/IPV4Address.h>
25 #include <string>
26 
27 namespace ola {
28 namespace network {
29 
30 enum { MAC_LENGTH = 6 };
31 
32 using std::string;
33 
34 /*
35  * Represents an interface.
36  */
37 class Interface {
38  public:
39  Interface();
40  Interface(const string &name,
41  const IPV4Address &ip_address,
42  const IPV4Address &broadcast_address,
43  const IPV4Address &subnet_mask,
44  const uint8_t *hw_address,
45  bool loopback);
46  Interface(const Interface &other);
47  Interface& operator=(const Interface &other);
48  bool operator==(const Interface &other);
49 
50  std::string name;
51  IPV4Address ip_address;
52  IPV4Address bcast_address;
53  IPV4Address subnet_mask;
54  uint8_t hw_address[MAC_LENGTH];
55  bool loopback;
56 };
57 
58 
63  public:
65  ~InterfaceBuilder() {}
66 
67  void SetName(const string &name) { m_name = name; }
68 
69  bool SetAddress(const string &ip_address);
70  void SetAddress(const IPV4Address &ip_address) {
71  m_ip_address = ip_address;
72  }
73 
74  bool SetBroadcast(const string &broadcast_address);
75  void SetBroadcast(const IPV4Address &broadcast_address) {
76  m_broadcast_address = broadcast_address;
77  }
78 
79  bool SetSubnetMask(const string &mask);
80  void SetSubnetMask(const IPV4Address &mask) {
81  m_subnet_mask = mask;
82  }
83 
84  bool SetHardwareAddress(const string &mac_address);
85 
86  void SetLoopback(bool loopback);
87 
88  void Reset();
90 
91  private:
92  std::string m_name;
93  IPV4Address m_ip_address;
94  IPV4Address m_broadcast_address;
95  IPV4Address m_subnet_mask;
96  uint8_t m_hw_address[MAC_LENGTH];
97  bool m_loopback;
98 
99  bool SetAddress(const string &str, IPV4Address *target);
100 };
101 } // namespace network
102 } // namespace ola
103 #endif // INCLUDE_OLA_NETWORK_INTERFACE_H_