| 290 | } |
| 291 | |
| 292 | static IPv6Address* Parse(Exception& ex,const char* address) { |
| 293 | if (!address || *address==0 || !Net::InitializeNetwork(ex)) |
| 294 | return 0; |
| 295 | #if defined(_WIN32) |
| 296 | if (String::ICompare(address, "localhost") == 0) |
| 297 | address = LocalhostV6; |
| 298 | struct addrinfo* pAI; |
| 299 | struct addrinfo hints; |
| 300 | memset(&hints, 0, sizeof(hints)); |
| 301 | hints.ai_flags = AI_NUMERICHOST; |
| 302 | int rc = getaddrinfo(address, NULL, &hints, &pAI); |
| 303 | if (rc == 0) { |
| 304 | IPv6Address* pResult = new IPv6Address(reinterpret_cast<struct sockaddr_in6*>(pAI->ai_addr)->sin6_addr, static_cast<int>(reinterpret_cast<struct sockaddr_in6*>(pAI->ai_addr)->sin6_scope_id)); |
| 305 | freeaddrinfo(pAI); |
| 306 | return pResult; |
| 307 | } |
| 308 | #else |
| 309 | struct in6_addr ia; |
| 310 | const char* scoped(strchr(address,'%')); |
| 311 | if (scoped) { |
| 312 | UInt32 scopeId(0); |
| 313 | if (!(scopeId = if_nametoindex(scoped+1))) |
| 314 | return 0; |
| 315 | if(*address=='[') |
| 316 | ++address; |
| 317 | auto result(inet_pton(AF_INET6,string(address,scoped - address).c_str(), &ia)); |
| 318 | if (result == 1) |
| 319 | return new IPv6Address(ia, scopeId); |
| 320 | } else { |
| 321 | if (String::ICompare(address, "localhost") == 0) |
| 322 | address = LocalhostV4; |
| 323 | if(*address=='[') { |
| 324 | if (inet_pton(AF_INET6,string(address+1,strlen(address)-2).c_str(), &ia) == 1) |
| 325 | return new IPv6Address(ia); |
| 326 | } else if (inet_pton(AF_INET6,address, &ia) == 1) |
| 327 | return new IPv6Address(ia); |
| 328 | } |
| 329 | #endif |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | private: |
| 334 | struct in6_addr _addr; |
nothing calls this directly
no outgoing calls
no test coverage detected