Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NetworkUtils.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * NetworkUtils.h
17  * Abstract various network functions.
18  * Copyright (C) 2005 Simon Newton
19  */
20 
21 #ifndef INCLUDE_OLA_NETWORK_NETWORKUTILS_H_
22 #define INCLUDE_OLA_NETWORK_NETWORKUTILS_H_
23 
24 #include <ola/network/Interface.h>
26 #include <string>
27 #include <vector>
28 
29 
30 namespace ola {
31 namespace network {
32 
33 // We define uint8_t versions of these so we can call them with any type.
37 inline uint8_t NetworkToHost(uint8_t value) { return value; }
38 
42 uint16_t NetworkToHost(uint16_t value);
43 
47 uint32_t NetworkToHost(uint32_t value);
48 
52 inline int8_t NetworkToHost(int8_t value) { return value; }
53 
57 int16_t NetworkToHost(int16_t value);
58 
62 int32_t NetworkToHost(int32_t value);
63 
67 inline uint8_t HostToNetwork(uint8_t value) { return value; }
68 
72 uint16_t HostToNetwork(uint16_t value);
73 
77 uint32_t HostToNetwork(uint32_t value);
78 
82 inline int8_t HostToNetwork(int8_t value) { return value; }
83 
87 int16_t HostToNetwork(int16_t value);
88 
92 int32_t HostToNetwork(int32_t value);
93 
97 inline uint8_t HostToLittleEndian(uint8_t value) { return value; }
98 
102 uint16_t HostToLittleEndian(uint16_t value);
103 
107 uint32_t HostToLittleEndian(uint32_t value);
108 
112 inline int8_t HostToLittleEndian(int8_t value) { return value; }
113 
117 int16_t HostToLittleEndian(int16_t value);
118 
122 int32_t HostToLittleEndian(int32_t value);
123 
127 inline uint8_t LittleEndianToHost(uint8_t value) { return value; }
128 
132 uint16_t LittleEndianToHost(uint16_t value);
133 
137 uint32_t LittleEndianToHost(uint32_t value);
138 
142 inline int8_t LittleEndianToHost(int8_t value) { return value; }
143 
147 int16_t LittleEndianToHost(int16_t value);
148 
152 int32_t LittleEndianToHost(int32_t value);
153 
159 std::string HostnameFromFQDN(const std::string &fqdn);
160 
166 std::string DomainNameFromFQDN(const std::string &fqdn);
167 
171 std::string DomainName();
172 
173 
177 std::string FQDN();
178 
179 
184 std::string FullHostname();
185 
189 std::string Hostname();
190 
196 bool NameServers(std::vector<ola::network::IPV4Address> *name_servers);
197 
211 bool DefaultRoute(int32_t *if_index,
212  ola::network::IPV4Address *default_gateway);
213 } // namespace network
214 } // namespace ola
215 #endif // INCLUDE_OLA_NETWORK_NETWORKUTILS_H_
216 
string DomainNameFromFQDN(const string &fqdn)
Definition: NetworkUtils.cpp:249
uint16_t HostToNetwork(uint16_t value)
16-bit unsigned host to network conversion.
Definition: NetworkUtils.cpp:158
string FullHostname()
Definition: NetworkUtils.cpp:280
uint16_t NetworkToHost(uint16_t value)
16-bit unsigned network to host conversion.
Definition: NetworkUtils.cpp:142
Represents a IPv4 Address.
Definition: IPV4Address.h:55
uint16_t LittleEndianToHost(uint16_t value)
16-bit unsigned little endian to host conversion.
Definition: NetworkUtils.cpp:206
string FQDN()
Definition: NetworkUtils.cpp:264
string DomainName()
Definition: NetworkUtils.cpp:259
bool NameServers(vector< IPV4Address > *name_servers)
Definition: NetworkUtils.cpp:290
bool DefaultRoute(int32_t *if_index, IPV4Address *default_gateway)
Definition: NetworkUtils.cpp:603
Represents an IPv4 Address.
string Hostname()
Definition: NetworkUtils.cpp:285
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
string HostnameFromFQDN(const string &fqdn)
Definition: NetworkUtils.cpp:241
uint16_t HostToLittleEndian(uint16_t value)
16-bit unsigned host to little endian conversion.
Definition: NetworkUtils.cpp:174