472,965 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,965 software developers and data experts.

Validate IPv6 Address

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

Feb 7 '06 #1
8 9863
<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
<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
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
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

<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
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
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
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Torsten Schmidt | last post by:
Hi, I'm trying to connect to a mysql-Server using PHP's mysql-function mysql_connect. The host on which the mysql-server is running is not the same as the host apache and php are running on. The...
8
by: John Burton | last post by:
I'm not sure if this is a question about python socket support or sockets in general ... I have a socket server with which I want to accept incoming connections on ipv4 and ipv6. I've found...
3
by: Frank Jiao | last post by:
I can get my local IPv6 address in Win2003 use the source code as below: string localName = Dns.GetHostName(); string address = ""; string scopeId = ""; IPHostEntry hostEntry = Dns.Resolve(...
2
by: PaulH | last post by:
I am attempting to write a functon that can perform IPv6 compliant pings. But, Icmp6SendEcho2 causes an access violation whenever it is called: First-chance exception at 0x76d641e8 in mping2.exe:...
0
by: Addam | last post by:
Anyone, I am writting a server that accepts a list of IPv4 and IPv6 address. The IPv4 address are padded with leading zeros. I belive this allows me to just point to the beging and run both IPv4...
2
by: prabhuram.k | last post by:
Can anybody know how to validate IPV4 and IPV6 address in PHP. I am using PHP 4.2.3 for some compatiability reason.
3
by: jiri.juranek | last post by:
Hello, is there any common function for validation if string contains valid ip address(both ipv4 and ipv6)? Or does sb wrote some regular expression for this? thanks J
8
by: Giampaolo Rodola' | last post by:
I'm not sure if this is a question about python programming, system administration or sockets in general... I have the FTP server in my signature to which I'd want to add IPv6 support. My hosting...
14
by: Simon | last post by:
Hi, is there a straight forward way of converting IPv4 to IPv6? I thought that it was just a matter of converting 32 bits to 128 bits, (by adding 96 leading 0s), but that does not seem right...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.