[FFmpeg-devel] [PATCH] avformat/rtsp: fix getnameinfo() call on FreeBSD

Nicolas George george at nsup.org
Thu Nov 24 17:12:41 EET 2016

Le quartidi 4 frimaire, an CCXXV, Kevin Lo a écrit :
> FreeBSD's socket calls require the sockaddr struct length to agree
> with the address family, Linux does not.  This patch fixes a failing
> getnameinfo() call on FreeBSD.
> Signed-off-by: Kevin Lo <kevlo at kevlo.org>

I looked at the standard, the semantic of salen is not specified. In
doubt, I would consider the usage to be invalid even if it works by
happenstance on Linux.

> ---
> diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
> index c6292c5..15fe25d 100644
> --- a/libavformat/rtsp.c
> +++ b/libavformat/rtsp.c
> @@ -2310,7 +2310,11 @@ static int sdp_read_header(AVFormatContext *s)
>              AVDictionary *opts = map_to_opts(rt);
>              err = getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip,

> +#ifdef __FreeBSD__
> +                              ((struct sockaddr*) &rtsp_st->sdp_ip)->sa_len,
> +#else
>                                sizeof(rtsp_st->sdp_ip),
> +#endif

On the other hand, sa_len is not standard, and littering the code with
ifdefry is ugly. Better add a field sdp_ip_len and set it at the same
time as sdp_ip.

Also, there are other instance of the same misuse of getnameinfo() in
this file.

>                                namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
>              if (err) {
>                  av_log(s, AV_LOG_ERROR, "getnameinfo: %s\n", gai_strerror(err));


  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161124/cb9b1dbd/attachment.sig>

More information about the ffmpeg-devel mailing list