How do you validate that a string is a valid IPv4 address in C++?

I don't need to validate that the IP address is reachable or anything like that. I just want to validate that the string is in dotted-quad (xxx.xxx.xxx.xxx) IPv4 format, where xxx is between 0 and 255.

Answers


You probably want the inet_pton - which returns -1 on failure, and supports both the IPv4 and future IPv6 addresses. If you still need to write your own IP address system, remember that a standard 32-bit hex number is a valid IP address but not in dotted-decimal notation.

This function both verifies the address, and also allows you to use the same address in related socket calls.


Need Your Help

In ASP.Net, during which page lifecycle event does viewstate get loaded?

asp.net viewstate page-lifecycle

I know it happens sometime before Load, but during what event exactly?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.