473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 9907
<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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.