[mythtv] allow DNS names as well as IP addresses in server setup

Eric Cooper ecc at cmu.edu
Sun Mar 6 01:26:29 UTC 2005


On Sat, Mar 05, 2005 at 06:24:02PM -0500, Anduin Withers wrote:
> 2. The logic is faulty, you can't if (h == 0 || blah), that or is going to
> be bad (you're not short-circuiting)

Yes, || short-circuits.  If h is 0, you don't do the rest of the
test, so you don't dereference h.  But I was mistakenly thinking that
length referred to the length of the list, when it's really the length of
each address in bytes, so it's unnecessary.

> 3. Why not just use gethostbyname? gethostbyname2 is a glibc extension.

I didn't want to deal with the case of IPv6 addresses coming back from
the lookup.

> 4. You might want to push it through inet_aton first, only when it
> is invalid push it to gethostbyname (instead of defaulting to a lookup
> and falling back).

gethostbyname does the right thing: it simply converts dotted-quad
strings into IP addresses (i.e "1.2.3.4" gets mapped to 1.2.3.4,
without a resolver call).

So better code would be:

    QHostAddress hadr;
    struct hostent *h = gethostbyname2(host, AF_INET);
    if (h != 0) {
        hadr.setAddress(ntohl(*(Q_UINT32 *)h->h_addr));
    } else {
        VERBOSE(VB_NETWORK, QString("Unknown host: %1").arg(host));
	return false;
    }

Thanks for the comments.

-- 
Eric Cooper             e c c @ c m u . e d u


More information about the mythtv-dev mailing list