Incrementing IPv6 address

T

Tester Tester

hello every body.
I am working in address incrementation(+1) using c language.User
inputs a value which is in hex address and incremented by 1.
Suppose my address is - abc5:5723:2109:ffff:76af:82ea:9256:ffff.
So my output becomes - abc5:5723:2109:ffff:76af:82ea:9257:0000

I already parse the entire string and put it in 8 different array but
unable to do when the the last 4 digit reaches FFFF..I could not write
the logic of that last portion.can any body help me to solve the
problem?

My code is -

#include "stdafx.h"
#include "conio.h"
#include "stdio.h"
#include "string.h"


int _tmain(int argc, _TCHAR* argv[])
{
char address[] = "abc5:5723:2109:ffff:76af:82ea:9256:ffff";
printf("Your IPv6 address is ");
puts(address);
char a[10], b[10], c[10], d[10], e[10], f[10], g[10], h[10];
if(sscanf(address, "%10[^:]:%10[^:]:%10[^:]:%10[^:]:%10[^:]:
%10[^:]:%10[^:]:%10[^:]:",a,b,c,d,e,f,g,h)==8)
{
//puts(a);
//puts(b);
}
int m,n,o,p,q,r,s,t;
sscanf(a,"%x", &m);
sscanf(b,"%x", &n);
sscanf(c,"%x", &o);
sscanf(d,"%x", &p);
sscanf(e,"%x", &q);
sscanf(f,"%x", &r);
sscanf(g,"%x", &s);
sscanf(h,"%x", &t);

t++;


printf("The final output is %x:%x:%x:%x:%x:%x:%x:%x",m,n,o,p,q,r,s,t);


getch();
return 0;

}

Output -

You IPv6 address is abc5:5723:2109:ffff:76af:82ea:9256:ffff
The final output is abc5:5723:2109:ffff:76af:82ea:9256:10000

Waiting for your reply.

Ayanava
 
M

Martin Brown

hello every body.
I am working in address incrementation(+1) using c language.User

Output -

You IPv6 address is abc5:5723:2109:ffff:76af:82ea:9256:ffff
The final output is abc5:5723:2109:ffff:76af:82ea:9256:10000

Waiting for your reply.

This looks like homework. How do you think you might do it?

Hint: quite a few Web scripts fell over the exact same problem at Y2k
rollover including the USNO who should have known better.

Instead of displaying YYYY as 2000 they showed 19100 instead.

Regards,
Martin Brown
 

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

Top