Validate IPv6 Address

Discussion in 'C++' started by prabhuram.k@gmail.com, Feb 7, 2006.

  1. Guest

    Can anybody know how to validate IPV4 and IPV6 address in C++
    , Feb 7, 2006
    #1
    1. Advertising

  2. Jim Langston Guest

    <> wrote in message
    news:...
    > Can anybody know how to validate IPV4 and IPV6 address in C++
    >


    Define "validate"
    Jim Langston, Feb 7, 2006
    #2
    1. Advertising

  3. Mike Wahler Guest

    <> wrote in message
    news:...
    > 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
    Mike Wahler, Feb 7, 2006
    #3
  4. Guest

    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, 2006
    #4
  5. Ben Pope Guest

    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...
    Ben Pope, Feb 8, 2006
    #5
  6. Mike Wahler Guest

    <> wrote in message
    news:...
    >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
    Mike Wahler, Feb 8, 2006
    #6
  7. Raider Guest

    Raider, Feb 9, 2006
    #7
  8. wrote:
    > Can anybody know how to validate IPV4 and IPV6 address in C++


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

    Stephan
    =?iso-8859-1?q?Stephan_Br=F6nnimann?=, Feb 9, 2006
    #8
  9. Jim Langston Guest

    <> wrote in message
    news:...
    >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?
    Jim Langston, Feb 9, 2006
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Skumar
    Replies:
    3
    Views:
    806
    Steve Zimmerman
    Aug 24, 2003
  2. Replies:
    6
    Views:
    836
    James Kanze
    Apr 2, 2008
  3. Philipp Hagemeister
    Replies:
    3
    Views:
    1,081
    Martin v. Löwis
    Mar 4, 2009
  4. Kai Timmer

    Get the ipv6 address from a interface

    Kai Timmer, Apr 9, 2009, in forum: Python
    Replies:
    4
    Views:
    1,942
    Дамјан ГеоргиевÑки
    Apr 11, 2009
  5. Jesse van den Kieboom

    Ipv6 on a ipv4/ipv6 hostname

    Jesse van den Kieboom, Jun 5, 2005, in forum: Ruby
    Replies:
    1
    Views:
    355
    Dibya Prakash
    Jun 5, 2005
Loading...

Share This Page