본문 바로가기

컴퓨터/프로그램,각종팁

IPv4 주소를 IPv6 주소로 변환

#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

제주삼다수, 2L,... 오뚜기 진라면 매운... 상하목장 유기농 흰... 남양 프렌치카페 카... 고려인삼유통 홍삼 ... 종근당건강 오메가3... 요이치 카링 유무선...