tcp: Pass NULL as hostname to getaddrinfo if the string is empty
authorJordi Ortiz <nenjordi@gmail.com>
Tue, 26 Jun 2012 17:22:21 +0000 (19:22 +0200)
committerMartin Storsjö <martin@martin.st>
Wed, 27 Jun 2012 11:04:02 +0000 (14:04 +0300)
This gives you the proper v4 or v6 version of the "any address",
allowing receiving connections on any address on the machine.

Signed-off-by: Martin Storsjö <martin@martin.st>
libavformat/tcp.c

index 5313195..6a65860 100644 (file)
@@ -65,7 +65,10 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
     snprintf(portstr, sizeof(portstr), "%d", port);
     if (listen_socket)
         hints.ai_flags |= AI_PASSIVE;
-    ret = getaddrinfo(hostname, portstr, &hints, &ai);
+    if (!hostname[0])
+        ret = getaddrinfo(NULL, portstr, &hints, &ai);
+    else
+        ret = getaddrinfo(hostname, portstr, &hints, &ai);
     if (ret) {
         av_log(h, AV_LOG_ERROR,
                "Failed to resolve hostname %s: %s\n",