Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #14380

Re: Question : inet_pton

From Ike Naar <ike@sverige.freeshell.org>
Newsgroups comp.lang.c
Subject Re: Question : inet_pton
Date 2011-12-07 22:45 +0000
Organization A noiseless patient Spider
Message-ID <slrn3vfsjdvr41.t59.ike@sverige.freeshell.org> (permalink)
References <jbonab$4qo$1@speranza.aioe.org>

Show all headers | View raw


On 2011-12-07, joao <joao82@simpmail.com.br> 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[i]);
    }
    printf("\n");
  }
  return 0;
}

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Question :  inet_pton joao <joao82@simpmail.com.br> - 2011-12-07 21:54 +0000
  Re: Question :  inet_pton Ian Collins <ian-news@hotmail.com> - 2011-12-08 11:02 +1300
  Re: Question :  inet_pton Ike Naar <ike@sverige.freeshell.org> - 2011-12-07 22:45 +0000
    Re: Question :  inet_pton Ike Naar <ike@sverige.freeshell.org> - 2011-12-07 22:48 +0000

csiph-web