By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,124 Members | 1,566 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,124 IT Pros & Developers. It's quick & easy.

Validate IPv6 Address

P: n/a
Can anybody know how to validate IPV4 and IPV6 address in C++

Feb 7 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
<pr*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Can anybody know how to validate IPV4 and IPV6 address in C++


Define "validate"
Feb 7 '06 #2

P: n/a
<pr*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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
Feb 7 '06 #3

P: n/a
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

Feb 8 '06 #4

P: n/a
pr*********@gmail.com wrote:
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
--
I'm not just a number. To many, I'm known as a string...
Feb 8 '06 #5

P: n/a

<pr*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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
Feb 8 '06 #6

P: n/a
Try boost::regex_match(). You will need only to define regex for IPv6
address.
http://boost.org/libs/regex/doc/regex_match.html

Feb 9 '06 #7

P: n/a
pr*********@gmail.com wrote:
Can anybody know how to validate IPV4 and IPV6 address in C++


[OT]
Under linux you have inet_pton.
[/OT]

Stephan

Feb 9 '06 #8

P: n/a
<pr*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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?
Feb 9 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.