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


Groups > comp.lang.c > #14377 > unrolled thread

Question : inet_pton

Started byjoao <joao82@simpmail.com.br>
First post2011-12-07 21:54 +0000
Last post2011-12-07 22:48 +0000
Articles 4 — 3 participants

Back to article view | Back to comp.lang.c


Contents

  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

#14377 — Question : inet_pton

Fromjoao <joao82@simpmail.com.br>
Date2011-12-07 21:54 +0000
SubjectQuestion : inet_pton
Message-ID<jbonab$4qo$1@speranza.aioe.org>
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 !

[toc] | [next] | [standalone]


#14378

FromIan Collins <ian-news@hotmail.com>
Date2011-12-08 11:02 +1300
Message-ID<9ka62tFi1tU1@mid.individual.net>
In reply to#14377
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

[toc] | [prev] | [next] | [standalone]


#14380

FromIke Naar <ike@sverige.freeshell.org>
Date2011-12-07 22:45 +0000
Message-ID<slrn3vfsjdvr41.t59.ike@sverige.freeshell.org>
In reply to#14377
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;
}

[toc] | [prev] | [next] | [standalone]


#14381

FromIke Naar <ike@sverige.freeshell.org>
Date2011-12-07 22:48 +0000
Message-ID<slrn3vfsjdvra5.t59.ike@sverige.freeshell.org>
In reply to#14380
On 2011-12-07, Ike Naar <ike@sverige.freeshell.org> wrote:
>       printf("%0x", addr[i]);

the format should be "%02x" (with "%0x" the output will be
a bit confusing).

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web