#include <stdio.h>
#include <arpa/inet.h> int main()
{
int i;
int ret;
struct in6_addr addr6;
unsigned long ul1, ul2, ul3, ul0;
char str[INET6_ADDRSTRLEN] = {}; ret = inet_pton(AF_INET6, "ff02::12", &addr6);
if (ret != ) {
perror("inet_pton()");
return -;
} for (i = ; i < ; i++) {
ul3 = addr6.s6_addr32[];
ul2 = addr6.s6_addr32[];
ul1 = addr6.s6_addr32[];
ul0 = addr6.s6_addr32[]; ul3 = ntohl(ul3)+;
if (ul3) {
goto u3;
}
ul2 = ntohl(ul2)+;
if (ul2) {
goto u2;
}
ul1 = ntohl(ul1)+;
if (ul1) {
goto u1;
}
ul0 = ntohl(ul0)+; addr6.s6_addr32[] = htonl(ul0);
u1:
addr6.s6_addr32[] = htonl(ul1);
u2:
addr6.s6_addr32[] = htonl(ul2);
u3:
addr6.s6_addr32[] = htonl(ul3); if ((inet_ntop(AF_INET6, &addr6, str, INET6_ADDRSTRLEN)) != NULL) {
printf("%s\n", str);
} else {
fprintf(stderr, "inet_ntop() error\n");
return -;
}
} return ;
}
05-11 15:55