Open Lighting Architecture  0.9.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
36 bool IsBigEndian();
37 
38 // we define uint8_t versions of these so we can call them with any type.
39 uint8_t NetworkToHost(uint8_t value);
40 
44 uint16_t NetworkToHost(uint16_t value);
45 
49 uint32_t NetworkToHost(uint32_t value);
50 int8_t NetworkToHost(int8_t value);
51 
55 int16_t NetworkToHost(int16_t value);
56 
57 /*
58  * Convert a int32_t from network to host byte order
59  */
60 int32_t NetworkToHost(int32_t value);
61 uint8_t HostToNetwork(uint8_t value);
62 
66 uint16_t HostToNetwork(uint16_t value);
67 
71 uint32_t HostToNetwork(uint32_t value);
72 int8_t HostToNetwork(int8_t value);
73 int16_t HostToNetwork(int16_t value);
74 int32_t HostToNetwork(int32_t value);
75 
76 uint8_t HostToLittleEndian(uint8_t value);
77 uint16_t HostToLittleEndian(uint16_t value);
78 uint32_t HostToLittleEndian(uint32_t value);
79 int8_t HostToLittleEndian(int8_t value);
80 int16_t HostToLittleEndian(int16_t value);
81 int32_t HostToLittleEndian(int32_t value);
82 uint8_t LittleEndianToHost(uint8_t value);
83 uint16_t LittleEndianToHost(uint16_t value);
84 uint32_t LittleEndianToHost(uint32_t value);
85 int8_t LittleEndianToHost(int8_t value);
86 int16_t LittleEndianToHost(int16_t value);
87 int32_t LittleEndianToHost(int32_t value);
88 
94 std::string HostnameFromFQDN(const std::string &fqdn);
95 
101 std::string DomainNameFromFQDN(const std::string &fqdn);
102 
106 std::string DomainName();
107 
108 
112 std::string FQDN();
113 
114 
119 std::string FullHostname();
120 
124 std::string Hostname();
125 
131 bool NameServers(std::vector<ola::network::IPV4Address> *name_servers);
132 
146 bool DefaultRoute(int32_t *if_index,
147  ola::network::IPV4Address *default_gateway);
148 } // namespace network
149 } // namespace ola
150 #endif // INCLUDE_OLA_NETWORK_NETWORKUTILS_H_
151