2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_NETWORK_H_
18 #define incl_HPHP_NETWORK_H_
23 #include <folly/IPAddress.h>
24 #include <folly/portability/Sockets.h>
27 * Network utility functions.
30 ///////////////////////////////////////////////////////////////////////////////
31 // thread-safe network functions
34 HostEnt() : tmphstbuf(nullptr) {}
35 ~HostEnt() { if (tmphstbuf
) free(tmphstbuf
);}
37 struct hostent hostbuf
;
42 // Extract out the scheme, host and port from a URL
43 // http://192.168.1.0:80
44 // http, 192.168.1.0, 80
45 // http://[2a03:2880::1]:80
46 // http, 2a03:2880::1, 80
47 // ssl://192.168.1.0:443
48 // ssl, 192.168.1.0, 80
49 // ssl://[2a03:2880::1]:443
50 // ssl, 2a03:2880::1, 443
52 explicit HostURL(const std::string
&hosturl
, int port
= 0);
54 bool isIPv6() const {return m_ipv6
;}
55 bool isValid() const {return m_valid
;}
56 uint16_t getPort() const {return m_port
;}
57 std::string
getScheme() const {return m_scheme
;}
58 std::string
getHost() const {return m_host
;}
59 std::string
getHostURL() const {return m_hosturl
;}
67 std::string m_hosturl
;
70 bool safe_gethostbyname(const char *address
, HostEnt
&result
);
72 ///////////////////////////////////////////////////////////////////////////////
74 * Get local machine's primary IP address.
76 std::string
GetPrimaryIP();
77 std::string
GetPrimaryIPv4();
78 std::string
GetPrimaryIPv6();
80 ///////////////////////////////////////////////////////////////////////////////
83 #endif // incl_HPHP_NETWORK_H_