开发者

How to determine if a string is a valid IPv6 address in C++? [duplicate]

开发者 https://www.devze.com 2023-03-10 23:27 出处:网络
This question already has answers here: Closed 11 years ago. The community reviewed whether to reopen this question 1 year ago and left it closed:
This question already has answers here: Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消