sources/network/ipaddress.cpp

changeset 81
a18aaf460648
parent 73
07dda51a7a8e
child 88
08ccaf26cffd
equal deleted inserted replaced
77:32ef969adeed 81:a18aaf460648
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "ipaddress.h"
32
33 #ifndef _WIN32
34 # include <netinet/in.h>
35 # include <netdb.h>
36 #else
37 # include <winsock2.h>
38 # include <ws2tcpip.h>
39 #endif
40
31 #include <stdio.h> 41 #include <stdio.h>
32 #include <stdlib.h> 42 #include <stdlib.h>
33 #include <string.h> 43 #include <string.h>
34 #include <time.h> 44 #include <time.h>
35 #include <netinet/in.h> 45
36 #include <netdb.h> 46 #ifdef _WIN32
37 #include "ipaddress.h" 47 using AddrInfo = ADDRINFOA;
48 #else
49 using AddrInfo = struct addrinfo;
50 #endif
38 51
39 // ----------------------------------------------------------------------------- 52 // -----------------------------------------------------------------------------
40 // 53 //
41 IPAddress::IPAddress() : 54 IPAddress::IPAddress() :
42 host (0), 55 host (0),
166 // ----------------------------------------------------------------------------- 179 // -----------------------------------------------------------------------------
167 // 180 //
168 STATIC METHOD 181 STATIC METHOD
169 IPAddress::resolve (String node) -> IPAddress 182 IPAddress::resolve (String node) -> IPAddress
170 { 183 {
171 addrinfo hints; 184 AddrInfo hints;
172 addrinfo* lookup; 185 AddrInfo* lookup;
173 memset (&hints, 0, sizeof hints); 186 memset (&hints, 0, sizeof hints);
174 hints.ai_family = AF_INET; 187 hints.ai_family = AF_INET;
175 188
176 if (getaddrinfo (node, nullptr, &hints, &lookup) != 0) 189 if (getaddrinfo (node, nullptr, &hints, &lookup) != 0)
177 throw StringParseError ("unknown host " + node); 190 throw StringParseError ("unknown host " + node);

mercurial