Open Lighting Architecture  0.9.0
 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * NetworkUtils.h
17  * Abstract various network functions.
18  * Copyright (C) 2005-2014 Simon Newton
19  */
20 
21 #ifndef INCLUDE_OLA_NETWORK_NETWORKUTILS_H_
22 #define INCLUDE_OLA_NETWORK_NETWORKUTILS_H_
23 
24 #ifdef WIN32
25 #include <winsock2.h>
26 #else
27 #include <arpa/inet.h>
28 #endif
29 
30 #include <ola/network/Interface.h>
32 #include <string>
33 #include <vector>
34 
35 
36 namespace ola {
37 namespace network {
38 
42 unsigned int SockAddrLen(const struct sockaddr &sa);
43 
47 bool StringToAddress(const std::string &address, struct in_addr *addr);
48 
49 std::string AddressToString(const struct in_addr &addr);
50 
54 bool IsBigEndian();
55 
56 // we define uint8_t versions of these so we can call them with any type.
57 uint8_t NetworkToHost(uint8_t value);
58 
62 uint16_t NetworkToHost(uint16_t value);
63 
67 uint32_t NetworkToHost(uint32_t value);
68 int8_t NetworkToHost(int8_t value);
69 
73 int16_t NetworkToHost(int16_t value);
74 
75 /*
76  * Convert a int32_t from network to host byte order
77  */
78 int32_t NetworkToHost(int32_t value);
79 uint8_t HostToNetwork(uint8_t value);
80 
84 uint16_t HostToNetwork(uint16_t value);
85 
89 uint32_t HostToNetwork(uint32_t value);
90 int8_t HostToNetwork(int8_t value);
91 int16_t HostToNetwork(int16_t value);
92 int32_t HostToNetwork(int32_t value);
93 
94 uint8_t HostToLittleEndian(uint8_t value);
95 uint16_t HostToLittleEndian(uint16_t value);
96 uint32_t HostToLittleEndian(uint32_t value);
97 int8_t HostToLittleEndian(int8_t value);
98 int16_t HostToLittleEndian(int16_t value);
99 int32_t HostToLittleEndian(int32_t value);
100 uint8_t LittleEndianToHost(uint8_t value);
101 uint16_t LittleEndianToHost(uint16_t value);
102 uint32_t LittleEndianToHost(uint32_t value);
103 int8_t LittleEndianToHost(int8_t value);
104 int16_t LittleEndianToHost(int16_t value);
105 int32_t LittleEndianToHost(int32_t value);
106 
112 std::string HostnameFromFQDN(const std::string &fqdn);
113 
119 std::string DomainNameFromFQDN(const std::string &fqdn);
120 
124 std::string DomainName();
125 
126 
130 std::string FQDN();
131 
132 
137 std::string FullHostname();
138 
142 std::string Hostname();
143 
149 bool NameServers(std::vector<ola::network::IPV4Address> *name_servers);
150 
164 bool DefaultRoute(int32_t *if_index,
165  ola::network::IPV4Address *default_gateway);
166 } // namespace network
167 } // namespace ola
168 #endif // INCLUDE_OLA_NETWORK_NETWORKUTILS_H_
169