diff mbox

[FFmpeg-devel,v3] avformat/rtsp: introduce get_sa_len() function

Message ID 20161125071722.GA94123@ns.kevlo.org
State Changes Requested
Headers show

Commit Message

Kevin Lo Nov. 25, 2016, 7:17 a.m. UTC
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@kevlo.org>
---

v3: Check for the right feature when using a sockaddr_in6.
Some systems, such as OS/2, define AF_INET6 without a full implementation.

Comments

Michael Niedermayer Dec. 13, 2016, 9:06 p.m. UTC | #1
On Fri, Nov 25, 2016 at 03:17:22PM +0800, Kevin Lo wrote:
> 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@kevlo.org>
> ---
> 
> v3: Check for the right feature when using a sockaddr_in6.
> Some systems, such as OS/2, define AF_INET6 without a full implementation.


> 
> diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
> index c6292c5..ff0e221 100644
> --- a/libavformat/rtsp.c
> +++ b/libavformat/rtsp.c

It seems nicolas disagrees about this patch in v2, this v3 is still
using the same design and you did not reply to nicolas
so ill mark this in patchwork as "changes requested"

[...]
diff mbox

Patch

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index c6292c5..ff0e221 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -202,6 +202,21 @@  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));
+#if HAVE_STRUCT_SOCKADDR_IN6
+    case AF_INET6:
+	return (sizeof(struct sockaddr_in6));
+#endif
+    default:
+	return (sizeof(struct sockaddr));
+    }
+}
+
 #if CONFIG_RTPDEC
 static void init_rtp_handler(RTPDynamicProtocolHandler *handler,
                              RTSPStream *rtsp_st, AVStream *st)
@@ -1614,7 +1629,8 @@  int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
             }
             if (ttl > 0)
                 snprintf(optbuf, sizeof(optbuf), "?ttl=%d", ttl);
-            getnameinfo((struct sockaddr*) &addr, sizeof(addr),
+            getnameinfo((struct sockaddr*) &addr,
+			get_sa_len((struct sockaddr*) &addr),
                         namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
             ff_url_join(url, sizeof(url), "rtp", NULL, namebuf,
                         port, "%s", optbuf);
@@ -1830,7 +1846,8 @@  redirect:
         goto fail;
     }
     if (!getpeername(tcp_fd, (struct sockaddr*) &peer, &peer_len)) {
-        getnameinfo((struct sockaddr*) &peer, peer_len, host, sizeof(host),
+        getnameinfo((struct sockaddr*) &peer,
+		    get_sa_len((struct sockaddr*) &peer), host, sizeof(host),
                     NULL, 0, NI_NUMERICHOST);
     }
 
@@ -2310,7 +2327,7 @@  static int sdp_read_header(AVFormatContext *s)
             AVDictionary *opts = map_to_opts(rt);
 
             err = getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip,
-                              sizeof(rtsp_st->sdp_ip),
+                              get_sa_len((struct sockaddr*) &rtsp_st->sdp_ip),
                               namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
             if (err) {
                 av_log(s, AV_LOG_ERROR, "getnameinfo: %s\n", gai_strerror(err));