[FFmpeg-devel] [PATCH v2] avformat/rtsp: introduce get_sa_len() function
Nicolas George
george at nsup.org
Fri Nov 25 13:03:55 EET 2016
> >Since the Linux implementation of sockaddr doesn't have sa_len as a member,
> >but the FreeBSD version does, introduce a get_sa_len() function that
> >determines the size based on the address family.
> >
> >Signed-off-by: Kevin Lo <kevlo at kevlo.org>
For some reason I do not have the original mail in my archives. I reply
to this one instead.
> >---
> >
> >diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
> >index c6292c5..4c543ed 100644
> >--- a/libavformat/rtsp.c
> >+++ b/libavformat/rtsp.c
> >@@ -202,6 +202,19 @@ static int get_sockaddr(AVFormatContext *s,
> > return 0;
> > }
> >
> >+static socklen_t
> >+get_sa_len(struct sockaddr *addr)
> >+{
> >+ switch (addr->sa_family) {
> >+ case AF_INET:
> >+ return (sizeof(struct sockaddr_in));
> >+ case AF_INET6:
> >+ return (sizeof(struct sockaddr_in6));
> >+ default:
> >+ return (sizeof(struct sockaddr));
> >+ }
I think this is misdesigned. It will not work if new address families
are added, while the whole point of the modern socket API is to
transparently handle that.
The system always gives us the correct size of the sockaddr structure
(ai_addrlen in struct addrinfo, the third argument of getpeername(),
etc.), we only have to keep it instead of discarding it.
Regards,
--
Nicolas George
More information about the ffmpeg-devel
mailing list