컴퓨터/프로그램,각종팁
IPv4 주소를 IPv6 주소로 변환
스노우볼^^
2009. 4. 29. 20:21
#ifdef WIN32 # pragma comment(lib, "ws2_32.lib") # include <winsock2.H># include <WS2TCPIP.H> #else #endif #include <stdio.h> /** @code RFC 3493 3.7 Compatibility with IPv4 Nodes The IPv4 address is encoded into the low-order 32 bits of the IPv6 address, and the high-order 96 bits hold the fixed prefix 0:0:0:0:0:FFFF. IPv4-mapped addresses are written as follows: ::FFFF: @endcode */ struct in_addr6 IPv4ToIPv6(struct in_addr IPv4) { struct in_addr6 IPv6; memset(&IPv6, 0x00, sizeof(IPv6)); IPv6.s6_addr[10] = IPv6.s6_addr[11] = 0xFF; memcpy(&IPv6.s6_addr[12], &IPv4.s_addr, sizeof(IPv4)); return IPv6; } int main(int argc, char **argv) { struct in_addr IPv4; struct in_addr6 IPv6; const char *pszIPv4 = "192.168.0.1"; IPv4.s_addr = inet_addr(pszIPv4); IPv6 = IPv4ToIPv6(IPv4); return 0; }http://blog.daum.net/aswip/3206874?srchid=BR1http%3A%2F%2Fblog.daum.net%2Faswip%2F3206874