ShadowStar
2014-04-08 16:11:58 +08:00
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
int main() {
struct in6_addr ip;
char *addr1, *addr2, *addr3;
addr1 = strdup("2a01:198:603:0::");
addr2 = strdup("2a01:198:603:0:396e:4789:8e99:890f");
addr3 = strdup("2a01::");
inet_pton(AF_INET6, addr1, &ip);
printf("0x%x%x%x%x\n", htonl(ip.__u6_addr.__u6_addr32[0]),htonl(ip.__u6_addr.__u6_addr32[1]),htonl(ip.__u6_addr.__u6_addr32[2]),htonl(ip.__u6_addr.__u6_addr32[3]));
inet_pton(AF_INET6, addr2, &ip);
printf("0x%x%x%x%x\n", htonl(ip.__u6_addr.__u6_addr32[0]),htonl(ip.__u6_addr.__u6_addr32[1]),htonl(ip.__u6_addr.__u6_addr32[2]),htonl(ip.__u6_addr.__u6_addr32[3]));
inet_pton(AF_INET6, addr3, &ip);
printf("0x%x%x%x%x\n", htonl(ip.__u6_addr.__u6_addr32[0]),htonl(ip.__u6_addr.__u6_addr32[1]),htonl(ip.__u6_addr.__u6_addr32[2]),htonl(ip.__u6_addr.__u6_addr32[3]));
return 1;
}