if (ret->family == 0) {
SockAddr sk_namelookup(const char *host, char **canonicalname){    SockAddr ret = snew(struct SockAddr_tag);    unsigned long a;    struct hostent *h = NULL;    char realhost[8192];    /* Clear the structure and default to IPv4. */    memset(ret, 0, sizeof(struct SockAddr_tag));    ret->family = 0;		       /* We set this one when we have resolved the host. */    *realhost = '\0';    ret->error = NULL;    if ((a = inet_addr(host)) == (unsigned long) INADDR_NONE) {#ifdef IPV6	if (getaddrinfo(host, NULL, NULL, &ret->ai) == 0) {	    ret->family = ret->ai->ai_family;	} else#endif	{	    /*	     * Otherwise use the IPv4-only gethostbyname... (NOTE:	     * we don't use gethostbyname as a fallback!)	     */	    if (ret->family == 0) {		/*debug(("Resolving \"%s\" with gethostbyname() (IPv4 only)...\n", host)); */		if ( (h = gethostbyname(host)) )		    ret->family = AF_INET;	    }	    if (ret->family == 0) {		ret->error = (h_errno == HOST_NOT_FOUND ||			      h_errno == NO_DATA ||			      h_errno == NO_ADDRESS ? "Host does not exist" :			      h_errno == TRY_AGAIN ?			      "Temporary name service failure" :			      "gethostbyname: unknown error");		return ret;	    }	}#ifdef IPV6	/* If we got an address info use that... */	if (ret->ai) {	    /* Are we in IPv4 fallback mode? */	    /* We put the IPv4 address into the a variable so we can further-on use the IPv4 code... */	    if (ret->family == AF_INET)		memcpy(&a,		       (char *) &((struct sockaddr_in *) ret->ai->				  ai_addr)->sin_addr, sizeof(a));	    /* Now let's find that canonicalname... */	    if (getnameinfo((struct sockaddr *) ret->ai->ai_addr,			    ret->family ==			    AF_INET ? sizeof(struct sockaddr_in) :			    sizeof(struct sockaddr_in6), realhost,			    sizeof(realhost), NULL, 0, 0) != 0) {		strncpy(realhost, host, sizeof(realhost));	    }	}	/* We used the IPv4-only gethostbyname()... */	else#endif	{	    memcpy(&a, h->h_addr, sizeof(a));	    /* This way we are always sure the h->h_name is valid :) */	    strncpy(realhost, h->h_name, sizeof(realhost));	}    } else {	/*	 * This must be a numeric IPv4 address because it caused a	 * success return from inet_addr.	 */	ret->family = AF_INET;	strncpy(realhost, host, sizeof(realhost));    }    ret->address = ntohl(a);    realhost[lenof(realhost)-1] = '\0';    *canonicalname = snewn(1+strlen(realhost), char);    strcpy(*canonicalname, realhost);    return ret;}