| 237 | } |
| 238 | |
| 239 | static bool GetHost(bool need_intranet_ip, const std::string& host, bool& is_ip_v6, std::string& ip) |
| 240 | { |
| 241 | bool ret = InitSocket(); |
| 242 | if (!ret) |
| 243 | { |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | #ifdef ARK_PLATFORM_WIN |
| 248 | |
| 249 | if (need_intranet_ip) |
| 250 | { |
| 251 | static char intranet_ip[256] = {0}; |
| 252 | memset(intranet_ip, 0x00, sizeof(intranet_ip)); |
| 253 | ret = GetIntranetIP(intranet_ip); |
| 254 | if (ret) |
| 255 | { |
| 256 | ip = intranet_ip; |
| 257 | if (IsIPV4Address(ip)) |
| 258 | { |
| 259 | is_ip_v6 = false; |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | is_ip_v6 = true; |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | else |
| 268 | { |
| 269 | ip = host; |
| 270 | if (IsIPV4Address(ip)) |
| 271 | { |
| 272 | is_ip_v6 = false; |
| 273 | } |
| 274 | else |
| 275 | { |
| 276 | is_ip_v6 = true; |
| 277 | } |
| 278 | } |
| 279 | #else |
| 280 | struct addrinfo hints; |
| 281 | struct addrinfo* answer; |
| 282 | struct addrinfo* curr; |
| 283 | |
| 284 | memset(&hints, 0, sizeof(struct addrinfo)); |
| 285 | hints.ai_family = AF_UNSPEC; |
| 286 | hints.ai_socktype = SOCK_STREAM; |
| 287 | hints.ai_flags = AI_CANONNAME; |
| 288 | hints.ai_protocol = 0; /* any protocol */ |
| 289 | |
| 290 | char ip_v4[16] = {0}; |
| 291 | char ip_v6[128] = {0}; |
| 292 | int result = getaddrinfo(host.c_str(), NULL, &hints, &answer); |
| 293 | if (result != 0) |
| 294 | { |
| 295 | return false; |
| 296 | } |