Question : inet_pton

J

joao

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 !
 
I

Ian Collins

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.
 
I

Ike Naar

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top