Expanding IPv6 address using inet_pton

R

Roxy Natal

hello every body,

My name is roxy and i am from brazil.I want to expand IPv6 address
using inet_pton().After
that I increment the address by 1 using C code.If my address is -
1234:12::ffff then after expand
it will be 1234:0012:0000:0000:0000:0000:0000:ffff
When I increment the address it will display -
1234:0012:0000:0000:0000:0000:0001:0000
Whenever it will reaches ffff it just put 0x0000 and increment the
next value by 1.
I already done some code part(not the increment part).Please help me
in this matter.

#include "stdafx.h"
#include "string.h"
#include "stdlib.h"
#include "conio.h"
#include "arpa/inet.h"
#include "inet/ip6.h"



int main(int argc, char argv[])
{

struct in6_addr {
unsigned char s6_addr[16]; // IPv6 address
};
struct in6_addr ipv6;
char str[]="abcd:1234::ffff";
if(strcnt(str,":")>1)
{


if(inet_pton(AF_INET6,str,&ipv6.s6_addr))
printf("%s is

%0llu(IPv6)\n",str,ipv6.s6_addr);
else
printf("Error..");
}

getch();

return 0;

}
 
B

Ben Bacarisse

Roxy Natal said:
My name is roxy and i am from brazil.I want to expand IPv6 address
using inet_pton().After
that I increment the address by 1 using C code.

There have been a few similar questions posted here recently. Can you
tell us how this problem came up? It is in some commonly used textbook?
Some on-line tutorial?

You make quite a few of the same mistakes as the other posters, so
you could start by finding the previous threads a reading the replies
given there.

Rather the repeat lots of stuff, I'll make only one remark about your
code:

struct in6_addr {
unsigned char s6_addr[16]; // IPv6 address
};
struct in6_addr ipv6;

printf("%s is

%0llu(IPv6)\n",str,ipv6.s6_addr);

Where did you get the idea of printing an array of 16 unsigned chars
using the llu format?

<snip>
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top