让我们假设一个结构
struct in6_addr
{
unsigned char s6_addr[16];
}x;
s6_addr
包含二进制形式的任何ipv6地址。现在我想检索该ipv6地址并以人类可读的格式打印。我知道以人类可读的形式打印ipv6地址我们使用inet_ntop()
。但在打印ipv6地址之前或使用inet_ntop()
之前,我只想确保此变量包含任何ipv6地址或任何值,然后仅使用inet_ntop()
if(/* Condition */)
{
/* if condition becomes true then only use inet_ntop() */
inet_ntop();
}