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 +----------------------------------------------------------------------+
22 #include <folly/IPAddress.h>
23 #include <folly/portability/Sockets.h>
26 * Network utility functions.
29 ///////////////////////////////////////////////////////////////////////////////
30 // thread-safe network functions
33 HostEnt() : tmphstbuf(nullptr) {}
34 ~HostEnt() { if (tmphstbuf
) free(tmphstbuf
);}
36 struct hostent hostbuf
;
41 // Extract out the scheme, host and port from a URL
42 // http://192.168.1.0:80
43 // http, 192.168.1.0, 80
44 // http://[2a03:2880::1]:80
45 // http, 2a03:2880::1, 80
46 // ssl://192.168.1.0:443
47 // ssl, 192.168.1.0, 80
48 // ssl://[2a03:2880::1]:443
49 // ssl, 2a03:2880::1, 443
51 explicit HostURL(const std::string
&hosturl
, int port
= 0);
53 bool isIPv6() const {return m_ipv6
;}
54 bool isValid() const {return m_valid
;}
55 uint16_t getPort() const {return m_port
;}
56 std::string
getScheme() const {return m_scheme
;}
57 std::string
getHost() const {return m_host
;}
58 std::string
getHostURL() const {return m_hosturl
;}
66 std::string m_hosturl
;
69 bool safe_gethostbyname(const char *address
, HostEnt
&result
);
71 ///////////////////////////////////////////////////////////////////////////////
73 * Get local machine's primary IP address.
75 std::string
GetPrimaryIP();
76 std::string
GetPrimaryIPv4();
77 std::string
GetPrimaryIPv6();
79 ///////////////////////////////////////////////////////////////////////////////