How to determine if a string is a valid IPv6 address in C++? [duplicate]
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Possible Duplicate:
IPv6 parsing in C
I need to check strings if they are valid IPv6 addresses in C++.
There are elegant solutions for C# here and rather ugly regex here.
Is there a good way to do this in C++ ?
开发者_C百科I'm currently using this, but it doesn't work on Windows XP (inet_pton() is missing):
unsigned char buf[sizeof(struct in6_addr)];
bool isvalid= inet_pton(PF_INET6, (const char *)addr, buf);
You can use getaddrinfo
in Linux, or in Windows since Windows 2000. (See the section of that document page entitled "Example code using AI_NUMERICHOST")
You can use WSAStringToAddress
, available since Windows 2000.
精彩评论