473,786 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validate IPv6 Address

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

Feb 7 '06 #1
8 9942
<pr*********@gm ail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Can anybody know how to validate IPV4 and IPV6 address in C++


Define "validate"
Feb 7 '06 #2
<pr*********@gm ail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.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*********@gma il.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*********@gm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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_ma tch(). You will need only to define regex for IPv6
address.
http://boost.org/libs/regex/doc/regex_match.html

Feb 9 '06 #7
pr*********@gma il.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*********@gm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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
5953
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 two computers are connected in an IPv6-network. No matter if I give the hostname (defined in /etc/hosts), the IPv6-address ("fec0::4") or the IPv6-address in square brackets ("") the function mysql_connect always prints "Unknown MYSQL-Server "....
8
2546
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 that if I create the listening socket with sock = socket(AF_INET, SOCK_STREAM) it will accept connections on ipv4 (only) and if I create it with sock = socket(AF_INET6, SOCK_STREAM) it will accept connections with ipv6 (only)
3
5872
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( localName ); foreach (IPAddress curAdd in hostEntry.AddressList) { if(curAdd.AddressFamily.ToString() ==
2
6397
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: 0xC0000005: Access violation reading location 0x00000000. Unhandled exception at 0x76d641e8 in mping2.exe: 0xC0000005: Access violation reading location 0x00000000. I have been unable to pinpoint the cause of the access violation so far, so I...
0
1419
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 addresses and IPv6 address though the same conversion function. However, i am having a hard time finding a simple way to this. I do not want to communicate with the addresses so i would like to avoid setting up anything extra. So does anyone...
2
5819
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
6246
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
8949
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 company provides me a common IPv4 address. I'd like to set up my workstation (Windows XP or Linux Debian, doesn't really matter) to temporarily use IPv6 for trying to add such feature to my library (I work on both Windows XP and Linux). Could...
14
9298
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 in some/most cases. For example, 127.0.0.1, (IPv4 localhost), does not convert ::1, (IPv6 localhost)
0
9650
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.