Question : inet_pton

Discussion in 'C Programming' started by joao, Dec 7, 2011.

  1. joao

    joao Guest

    Dears friends

    Do you give me an advise for expand IPv6 adresses with inet_pton() ? I
    need expand then increment in 1 and display.

    I am having this :

    unsigned char addr[16] = inet_pton(AF_INET6,"1234:12::ffff",&addr) ;

    but he no work.

    Many Thanks !
     
    joao, Dec 7, 2011
    #1
    1. Advertising

  2. joao

    Ian Collins Guest

    On 12/ 8/11 10:54 AM, joao wrote:
    > Dears friends
    >
    > Do you give me an advise for expand IPv6 adresses with inet_pton() ? I
    > need expand then increment in 1 and display.


    The best advice is to ask on comp.unix.programmer. inet_pton() is
    defined in the Unix specification.

    --
    Ian Collins
     
    Ian Collins, Dec 7, 2011
    #2
    1. Advertising

  3. joao

    Ike Naar Guest

    On 2011-12-07, joao <> wrote:
    > Do you give me an advise for expand IPv6 adresses with inet_pton() ? I
    > need expand then increment in 1 and display.
    >
    > I am having this :
    >
    > unsigned char addr[16] = inet_pton(AF_INET6,"1234:12::ffff",&addr) ;
    >
    > but he no work.


    Did you read the documentation for inet_pton?
    The return value of inet_pton is not an array, but an integer
    that specifies whether the second argument was a valid address (1)
    or not (0 or -1). Also, the & in &addr is redundant because addr is
    an array. You probably want something like:

    #include <stdio.h>
    #include <arpa/inet.h>

    int main(void)
    {
    unsigned char addr[16];
    if (1 == inet_pton(AF_INET6, "1234:12::ffff", addr))
    {
    /* valid address, print the converted value */
    size_t i;
    for (i = 0; i != sizeof addr; ++i)
    {
    printf("%0x", addr);
    }
    printf("\n");
    }
    return 0;
    }
     
    Ike Naar, Dec 7, 2011
    #3
  4. joao

    Ike Naar Guest

    On 2011-12-07, Ike Naar <> wrote:
    > printf("%0x", addr);


    the format should be "%02x" (with "%0x" the output will be
    a bit confusing).
     
    Ike Naar, Dec 7, 2011
    #4
    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. sean
    Replies:
    1
    Views:
    605
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    670
    Iain Norman
    Feb 16, 2005
  3. =?Utf-8?B?YW5kcmV3MDA3?=

    question row filter (more of sql query question)

    =?Utf-8?B?YW5kcmV3MDA3?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    956
    Scott Allen
    Oct 6, 2005
  4. Neha Jain

    inet_pton problem in C

    Neha Jain, Dec 2, 2011, in forum: C Programming
    Replies:
    2
    Views:
    394
  5. Roxy Natal

    Expanding IPv6 address using inet_pton

    Roxy Natal, Dec 6, 2011, in forum: C Programming
    Replies:
    1
    Views:
    674
    Ben Bacarisse
    Dec 6, 2011
Loading...

Share This Page