[FFmpeg-devel] [PATCH/RFC] Prefer getaddrinfo over gethostbyname

Ronald S. Bultje rsbultje
Mon Jan 11 18:58:49 CET 2010


Hi,

On Wed, Jan 6, 2010 at 5:02 PM, Martin Storsj? <martin at martin.st> wrote:
> Here's a rerolled version of the series.

0012:

-static int is_multicast_address(struct sockaddr_in *addr)
-{
-    return IN_MULTICAST(ntohl(addr->sin_addr.s_addr));
-}

Not OK, since the ipv6-replacement of that might not exist. I'd like
to move from separate codepaths to merging codepaths, i.e.:

static int is_multicast_address(struct sockaddr_storage *addr)
{
    if (addr->ss_family == AF_INET) {
        return IN_MULTICAST(ntohl(((struct sockaddr_in
*)addr)->sin_addr.s_addr));
    }
    if (addr->ss_family == AF_INET6) {
        return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr);
    }

    return 0;
}

First of all: this wouldn't even compile, because your struct
sockaddr_storage contains no ss_family field, only an "x" field.
That's fine with me, but probably wrong, and you might want to fix
that. Example:

#if !HAVE_STRUCT_SOCKADDR_STORAGE
struct sockaddr_storage {
    union {
        struct {
            field ss_family;
            other fields;
        };
        struct sockaddr_in x;
    };
};
#endif

Although this'd compile, there was also some discussion on whether
this is fine b/c it might be a gcc extension, not sure.

Then second, the fix here would be to use your newly-created
HAVE_IPV6_MULTICAST macro and check that to create:

static int is_multicast_address(struct sockaddr_storage *addr)
{
    if (addr->ss_family == AF_INET) {
        return IN_MULTICAST(ntohl(((struct sockaddr_in
*)addr)->sin_addr.s_addr));
    }
#if HAVE_IPV6_MULTICAST
    if (addr->ss_family == AF_INET6) {
        return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr);
    }
#endif

    return 0;
}

Same for the other functions. I.e. please make sure it compiles and
works on older systems. For now, patch not yet OK.

Ronald



More information about the ffmpeg-devel mailing list