日期:2014-05-16 浏览次数:20736 次
#include
#include
#include
#include
int main(int argc, char **argv)
{
char ip[] = "ff3f:2345:1234::1234";
struct in6_addr addr;
int ret = inet_pton(AF_INET6, ip, (void *)&addr); //IP字符串 ——》网络字节流
if(0 == ret)
{
printf("inet_pton error, return! \n");
return -1;
}
else
{
printf("inet_pton ip: %u\n",addr.s6_addr);
}
}
/* IPv6 address */
struct in6_addr
{
union
{
uint8_t __u6_addr8[16];
#if defined __USE_MISC
------解决方案--------------------
defined __USE_GNU
uint16_t __u6_addr16[8];
uint32_t __u6_addr32[4];
#endif
} __in6_u;
#define s6_addr __in6_u.__u6_addr8
#if defined __USE_MISC
------解决方案--------------------
defined __USE_GNU
# define s6_addr16 __in6_u.__u6_addr16
# define s6_addr32 __in6_u.__u6_addr32
#endif
};
// 这里打印的是数组uint8_t __u6_addr8[16]的首地址,当然每次运行都是不同的值了
printf("inet_pton ip: %u\n",addr.s6_addr);