3 This file is part of libmspnet
4 Copyright © 2008 Mikkosoft Productions, Mikko Rasa
5 Distributed under the LGPL
9 #define _WIN32_WINNT 0x0501
14 #include <msp/strings/formatter.h>
23 SockAddr *resolve(const string &s, Family family)
26 unsigned colon=s.find(':');
27 if(colon!=string::npos)
29 host=s.substr(0, colon);
30 serv=s.substr(colon+1);
35 addrinfo hints={0, family, 0, 0, 0, 0, 0, 0};
37 const char *chost=(host.empty() ? 0 : host.c_str());
38 const char *cserv=(serv.empty() ? 0 : serv.c_str());
39 int err=getaddrinfo(chost, cserv, &hints, &res);
42 SockAddr *addr=SockAddr::create(*res->ai_addr);
48 throw Exception(format("Can't resolve '%s': %d", host, err));
50 throw Exception(format("Can't resolve '%s': %s", host, gai_strerror(err)));
55 unsigned size=fill_sockaddr(sa);
58 int err=getnameinfo(&sa, size, hst, 128, srv, 128, 0);