Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #14377 > unrolled thread
| Started by | joao <joao82@simpmail.com.br> |
|---|---|
| First post | 2011-12-07 21:54 +0000 |
| Last post | 2011-12-07 22:48 +0000 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.c
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
| From | joao <joao82@simpmail.com.br> |
|---|---|
| Date | 2011-12-07 21:54 +0000 |
| Subject | Question : 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]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-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]
| From | Ike Naar <ike@sverige.freeshell.org> |
|---|---|
| Date | 2011-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]
| From | Ike Naar <ike@sverige.freeshell.org> |
|---|---|
| Date | 2011-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