Validate IPv6 Address

M

Mike Wahler

Can anybody know how to validate IPV4 and IPV6 address in C++

Yes.

1. Determine what 'valid' means.

2. Write code to enforce 1.

3. You probably want different execution
paths for 'valid' and 'invalid' data.

I don't see a question about the C++ language here.

-Mike
 
P

prabhuram.k

i am sorry, i have an application which will take the ipv6 address as
input from the user. I just want to know if the user enters the proper
ipv6 address or not. I am validating this for ipv4 and now i want to do
the same for ipv6 address. Thanks for the time
 
B

Ben Pope

i am sorry, i have an application which will take the ipv6 address as
input from the user. I just want to know if the user enters the proper
ipv6 address or not. I am validating this for ipv4 and now i want to do
the same for ipv6 address. Thanks for the time

You still haven't defined valid or proper.

Does the IP address have to point to a working machine?

Should it be entered in decimal or hex? Should there be separators for
each 8 bits? What is that separator? Is it optional? Is leading or
trailing whitespace acceptable?

We don't know.

Ben Pope
 
M

Mike Wahler

i am sorry, i have an application which will take the ipv6 address as
input from the user. I just want to know if the user enters the proper
ipv6 address or not.

The answer is the same. First define what 'proper'
means, then write the code to ensure that the input
is proper.

For example suppose I define a certain type of string
value, where it's only 'valid' if its first character
is the character 'a'. A function to validate it might
look like this;

bool is_valid(const std::string& s)
{
return s.size() != 0 && s[0] == 'a';
}

I am validating this for ipv4 and now i want to do
the same for ipv6 address. Thanks for the time

I suspect the method for ipv6 would be similar to
that for ipv4, just change the 'rules' to match
those of ipv6.

Again, this isn't really a C++ question. Try to come
up with a definition (in English) of what makes an
'ipv6 address' valid or not, then we can help with
translating that definition to C++ (it would be best
if you first tried to write the code yourself, then if
you get stuck, post the code and ask specific questions
about it.

-Mike
 
J

Jim Langston

i am sorry, i have an application which will take the ipv6 address as
input from the user. I just want to know if the user enters the proper
ipv6 address or not. I am validating this for ipv4 and now i want to do
the same for ipv6 address. Thanks for the time

Okay, so how are you validating them for ipv4? Are you ensuring that they
point to a valid machine or not? Are you checking to see what type of
address it is (broadcast with last byte being 255, the other special case
with the last being 0)? Are you checking to see if it's Class A, Class B,
Class C? Are you checking to see if it's withing your network? Are you
checking to see if they aren't in the local ip ranges? (192.168.x.x, etc..).
Are you checking to make sure they don't point to NSA servers?

A simple validation would be to see if you get 6 bytes between 0 and 255.
A more complex validation would be to ensure they aren't broadcast or 0
terminated.
A more complex validation would attempt to ping the address and see if you
get a reply.
A more complex validation would have all known valid IP addresses in a
lookup table and only ping those you don't know as valid, and update the
table if they are.

So, again, what is your definition of valid?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top