-3

This is how you would convert a 32 bit integer ipv4;

int e = 12345678;
u_char ip[4];
ip[0] = ip & 0xFF;
ip[1] = (ip >> 8) & 0xFF;
ip[2] = (ip >> 16) & 0xFF;
ip[3] = (ip >> 24) & 0xFF;
printf("\t%d.%d.%d.%d\n", bytes[0], bytes[1], bytes[2], bytes[3]);

How can I convert ipv6 to dotted string? What instead of 0xFF? PLEASE HELP

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • possible duplicate of [Conversion IPv6 to long and long to IPv6](http://stackoverflow.com/questions/17875728/conversion-ipv6-to-long-and-long-to-ipv6) – tripleee May 25 '14 at 09:31

1 Answers1

1

Well, first of all: IPv6 doesn't use dots (except when representing an embedded IPv4 address) but colons.

And representing an IPv6 address in its recommended canonical representation isn't that easy either. I would recommend just using inet_ntop to convert from numerical to printable format.

Community
  • 1
  • 1
Sander Steffann
  • 9,509
  • 35
  • 40