1

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++ ?

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);
Community
  • 1
  • 1
Gene Vincent
  • 5,237
  • 9
  • 50
  • 86
  • `getaddrinfo()` (from duplicate question) looks to be available in XP if you don't have `inet_pton()` – CharlesB Jun 06 '11 at 14:52
  • Vote to reopen, since the linked question explicitly tags C, while this question tags C++. The linked C question may lack some answers, which requires C++ libraries, like boost. Actually, there is at least one [option](https://wandbox.org/permlink/1gT45B8BaN64dnSr), which uses boost::asio. – Alex Che Nov 04 '21 at 14:23

2 Answers2

2

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")

Ken Bloom
  • 57,498
  • 14
  • 111
  • 168
0

You can use WSAStringToAddress, available since Windows 2000.

Ken Bloom
  • 57,498
  • 14
  • 111
  • 168