1. 程式人生 > >c語言判斷格式是否IPv6

c語言判斷格式是否IPv6

int net_is_validipv6(const char *hostname)
{
	struct sockaddr_in6 addr;
	
	if (!hostname) return -1;
	if (strchr(hostname, '.')) return -1;//暫時排除::ffff:204.152.189.116
	if (inet_pton(AF_INET6, hostname, &addr.sin6_addr) != 1) return -1;
    	
	return 0;
}