Open Lighting Architecture
 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-2009 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>
31 #include <string>
32 
33 
34 namespace ola {
35 namespace network {
36 
37 bool StringToAddress(const std::string &address, struct in_addr &addr);
38 std::string AddressToString(const struct in_addr &addr);
39 
40 std::string HardwareAddressToString(uint8_t hw_address[MAC_LENGTH]);
41 
42 bool IsBigEndian();
43 
44 // we define uint8_t versions of these so we can call them with any type.
45 uint8_t NetworkToHost(uint8_t value);
46 uint16_t NetworkToHost(uint16_t value);
47 uint32_t NetworkToHost(uint32_t value);
48 int8_t NetworkToHost(int8_t value);
49 int16_t NetworkToHost(int16_t value);
50 int32_t NetworkToHost(int32_t value);
51 uint8_t HostToNetwork(uint8_t value);
52 uint16_t HostToNetwork(uint16_t value);
53 uint32_t HostToNetwork(uint32_t value);
54 int8_t HostToNetwork(int8_t value);
55 int16_t HostToNetwork(int16_t value);
56 int32_t HostToNetwork(int32_t value);
57 
58 uint8_t HostToLittleEndian(uint8_t value);
59 uint16_t HostToLittleEndian(uint16_t value);
60 uint32_t HostToLittleEndian(uint32_t value);
61 int8_t HostToLittleEndian(int8_t value);
62 int16_t HostToLittleEndian(int16_t value);
63 int32_t HostToLittleEndian(int32_t value);
64 uint8_t LittleEndianToHost(uint8_t value);
65 uint16_t LittleEndianToHost(uint16_t value);
66 uint32_t LittleEndianToHost(uint32_t value);
67 int8_t LittleEndianToHost(int8_t value);
68 int16_t LittleEndianToHost(int16_t value);
69 int32_t LittleEndianToHost(int32_t value);
70 
71 std::string FullHostname();
72 std::string Hostname();
73 } // namespace network
74 } // namespace ola
75 #endif // INCLUDE_OLA_NETWORK_NETWORKUTILS_H_
76