iFun Engine API  1.0.0-b6053
Great Technology for Great Games
hardware_info.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2020 iFunFactory Inc. All Rights Reserved.
2 //
3 // This work is confidential and proprietary to iFunFactory Inc. and
4 // must not be used, disclosed, copied, or distributed without the prior
5 // consent of iFunFactory Inc.
6 
9 #ifndef INCLUDE_FUNAPI_SYSTEM_HARDWARE_INFO_H_
10 #define INCLUDE_FUNAPI_SYSTEM_HARDWARE_INFO_H_
11 
12 #include <boost/array.hpp>
13 #include <boost/asio.hpp>
14 #include <boost/noncopyable.hpp>
16 #include <funapi/types.h>
17 
18 #include <map>
19 #include <vector>
20 
21 
22 namespace fun {
23 
25 class FUNAPI_DLL_VISIBILITY HardwareInfo : private boost::noncopyable {
26  public:
28  struct FUNAPI_DLL_VISIBILITY NicInfo {
29  string name_;
30  boost::asio::ip::address address_;
31  boost::asio::ip::address netmask_;
32  boost::array<uint8_t, 6> hw_address_;
33 
34  // For the case where the NIC has multiple IP addresses.
35  // address_ is always the same as addresses_[0].
36  typedef std::pair<boost::asio::ip::address /*addr*/,
37  boost::asio::ip::address /*mask*/> AddressMaskPair;
38  std::vector<AddressMaskPair> addresses_;
39  };
40 
41  enum FunapiProtocol {
42  kTcpPbuf = 0,
43  kTcpJson,
44  kUdpPbuf,
45  kUdpJson,
46  kHttpPbuf,
47  kHttpJson,
48  kWebSocketPbuf,
49  kWebSocketJson,
50  };
51 
53  typedef std::map<string, const NicInfo> NicInfoMap;
54 
55  // Protocol name to port mapping.
56  typedef std::map<FunapiProtocol, uint16_t> ProtocolPortMap;
57 
60  static const NicInfoMap &GetNicInfo();
61 
65  static boost::asio::ip::address GetExternalIp();
66 
69  static std::string GetExternalHostname();
70 
73  static ProtocolPortMap GetExternalPorts();
74 
78  DEPRECATED(static boost::asio::ip::address_v4 GetAwsPublicIpv4());
79 
81  static const std::vector<NicInfo::AddressMaskPair> &
82  GetAddressList(const std::string &nic_name);
83 };
84 
85 
86 FUNAPI_DLL_VISIBILITY bool ResolveIpFromHostname(
87  const std::string &hostname, boost::asio::ip::address *addr);
88 
89 } // namespace fun
90 
91 #endif // INCLUDE_FUNAPI_SYSTEM_HARDWARE_INFO_H_
boost::asio::ip::address netmask_
Netmask applying to the NIC.
Definition: hardware_info.h:31
std::map< string, const NicInfo > NicInfoMap
NIC name to NIC information mapping.
Definition: hardware_info.h:53
Definition: json.h:18
Datastructure to hold IP-capable Network Interface Card (NIC) information.
Definition: hardware_info.h:28
std::pair< boost::asio::ip::address, boost::asio::ip::address > AddressMaskPair
NIC&#39;s hardware address.
Definition: hardware_info.h:37
string name_
NIC name.
Definition: hardware_info.h:29
boost::asio::ip::address address_
IP address associated with the NIC.
Definition: hardware_info.h:30
Class to access hardware information.
Definition: hardware_info.h:25