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

Martin Storsjö martin
Mon Jan 11 20:45:02 CET 2010


On Mon, 11 Jan 2010, Ronald S. Bultje wrote:

> 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:

Agh, I thought I checked that none of the uses of sockaddr_storage 
actually used its fields. (Instead of checking ->ss_family, one can cast 
it to (struct sockaddr *) and check ->sa_family instead.) But apparently I 
missed this one.

Also, I tried to check the RFC, but happened only to check the previous 
version (RFC 2553), which only mentions this field as __ss_family, while 
the newer revision, RFC 3493, specifies the field as ss_family instead.

So if we want to redefine the correct content of this struct, we would 
need to know the platform specific size of ss_family. (RFC 3493 defines it 
as sa_family_t, but I guess we can't rely on that typedef either?)

The other option would be to avoid accessing the ss_family field - by 
redefining the parameter to is_multicast_address to be struct sockaddr 
insted, and use ->sa_family.

Or simply revert the sockaddr_storage replacement, for now?

> 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;
> }

Well, actually, udp.c defines some kind of fallback for 
IN6_IS_ADDR_MULTICAST at the start of the file, but this might be a good 
idea anyway.

// Martin



More information about the ffmpeg-devel mailing list