libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
Net.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef HOMEGEARNET_H_
32 #define HOMEGEARNET_H_
33 
34 #include "../Exception.h"
35 
36 #include <string>
37 #include <vector>
38 #include <memory>
39 
40 namespace BaseLib
41 {
47 class NetException : public Exception
48 {
49 public:
50  NetException(std::string message) : Exception(message) {}
51 };
52 
56 class Net
57 {
58 public:
59  struct RouteInfo
60  {
61  bool ipv6 = false;
62  std::array<uint8_t, 16> destinationAddress{};
63  uint8_t sourceNetmask = 0;
64  std::array<uint8_t, 16> sourceAddress{};
65  uint8_t destinationNetmask = 0;
66  std::array<uint8_t, 16> gateway{};
67  std::string interfaceName;
68  };
69 
70  typedef std::vector<std::shared_ptr<RouteInfo>> RouteInfoList;
71 
72  Net();
73 
78  virtual ~Net();
79 
85  static bool isIp(const std::string& ipAddress);
86 
93  static std::string getMyIpAddress(const std::string& interfaceName = "");
94 
101  static std::string getMyIp6Address(std::string interfaceName = "");
102 
109  static std::string resolveHostname(std::string& hostname);
110 
116  static RouteInfoList getRoutes();
117 
118  static std::vector<uint8_t> getMacAddress(bool allowLocallyAdministered, const std::string &interface = "");
119 private:
120  static int32_t readNlSocket(int32_t sockFd, std::vector<char>& buffer, uint32_t messageIndex, uint32_t pid);
121 };
122 
123 }
124 
125 #endif
std::string interfaceName
Definition: Net.h:67
Exception class for the HTTP client.
Definition: Net.h:47
Definition: BaseLib.cpp:34
Class with network related helper functions.
Definition: Net.h:56
std::vector< std::shared_ptr< RouteInfo > > RouteInfoList
Definition: Net.h:70
Base class for all exceptions defined in Homegear.
Definition: Exception.h:41
Definition: Net.h:59
NetException(std::string message)
Definition: Net.h:50