Find the answer to your Linux question:
Results 1 to 1 of 1
Hi, For IP address validation, 'm using network address and service translation API getaddrinfo(). It is used to validate the configured machine is IPV4 or IPV6 by checking retrieved struct ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    1

    getaddrinfo API with Partial IP in node (IPV6)


    Hi,

    For IP address validation, 'm using network address and service translation API getaddrinfo(). It is used to validate the configured machine is IPV4 or IPV6 by checking retrieved struct addrinfo member ai_family contents.

    ----------------------------------------------------------------------------------------------
    For example:
    IPV4 Address => A.B.C.D
    IPV6 Address => Aa:Bb:Cc:Dd:Ee

    <snip>

    struct addrinfo AddrHints, *res;
    memset(&AddrHints, 0, sizeof(AddrHints));
    AddrHints.ai_flags = AI_NUMERICHOST;
    service =NULL;
    Node = (IPV4 or IPV6 address)

    getaddrinfo(Node, NULL , &AddrHints, &res);

    if(res->ai_family == AF_INET6) { ... }

    if(res->ai_family == AF_INET) { ... }


    </snip>

    ----------------------------------------------------------------------------------------------

    CASE 1: FULL IPV4 or IPV6 address as node parameter

    If we provide Full IPV4 or IPV6 address as mentioned above with the retrieved struct addrinfo member ai_family contents the proper information.
    FULL ip address E.g. [node = "A.B.C.D" or "Aa:Bb:Cc:Dd:Ee"]

    CASE 2 :Partial IPV4
    When a partial IPV4 address is provided in node parameter of getaddrinfo(), it returns correctly ai_family as INET (means its a IPV4)
    Partial IPV4 ip address [node = "A.B.C"]

    CASE 3: Partial IPV6
    When a partial IPV6 address is provided in node parameter of getaddrinfo(), it Fails to return the res contents
    Partial IPV6 ip address [node = "Aa:Bb:Cc"]


    Its not able to retrieve addrinfo struct and hence ai_family properly for partial IPV6 addresses.

    Its observed that same partial IP scenario works fine on Solaris machines

    Linux => 2.6.18-92.1.10.el5.xs5.0.0.39xen #1 SMP Thu Oct 2 07:35:45 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux

    Solaris => SunOS 5.10 Generic_142909-17 sun4u sparc SUNW,Sun-Fire-V440


    Attached the POC

    Can some one look into this ?
    Please comment ...
    Attached Files Attached Files
    Last edited by kiran_b; 12-22-2010 at 08:35 AM. Reason: Tag

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •