#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;
}
vi 편집기 사용법 (0) | 2017.05.21 |
---|---|
[프로그래밍/알고리즘] 정렬(sort) 소스 모음 (0) | 2017.05.19 |
[프로그래밍/Visual C++ 6.0] 단축키 (0) | 2016.12.26 |
[프로그래밍] 배열 stack / 단순연결리스트 stack (0) | 2016.12.24 |
[프로그래밍] malloc 메모리 할당 및 해제 / 재할당 (0) | 2016.12.23 |