Jordi Ortiz | 17 Jun 2012 23:58
Picon

[PATCH] TCP: Use AI_PASSIVE flag when no address is set

---
 libavformat/tcp.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 7e348f7..c9ff47a 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
 <at>  <at>  -65,7 +65,12  <at>  <at>  static int tcp_open(URLContext *h, const char *uri, int flags)
     hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = SOCK_STREAM;
     snprintf(portstr, sizeof(portstr), "%d", port);
-    ret = getaddrinfo(hostname, portstr, &hints, &ai);
+    if (listen_socket && !hostname[0]) {
+        hints.ai_flags |= AI_PASSIVE;
+        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",
--

-- 
1.7.10

Martin Storsjö | 18 Jun 2012 10:54

Re: [PATCH] TCP: Use AI_PASSIVE flag when no address is set

On Sun, 17 Jun 2012, Jordi Ortiz wrote:

> ---
> libavformat/tcp.c |    7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> index 7e348f7..c9ff47a 100644
> --- a/libavformat/tcp.c
> +++ b/libavformat/tcp.c
>  <at>  <at>  -65,7 +65,12  <at>  <at>  static int tcp_open(URLContext *h, const char *uri, int flags)
>     hints.ai_family = AF_UNSPEC;
>     hints.ai_socktype = SOCK_STREAM;
>     snprintf(portstr, sizeof(portstr), "%d", port);
> -    ret = getaddrinfo(hostname, portstr, &hints, &ai);
> +    if (listen_socket && !hostname[0]) {
> +        hints.ai_flags |= AI_PASSIVE;
> +        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",
> -- 
> 1.7.10

I'd rather have you split this in two. There's two almost separate issues 
here. If listen_socket is set, you should set AI_PASSIVE, regardless of 
the hostname. The glibc manpage says "If node is not NULL, then the 
(Continue reading)

Jordi Ortiz | 26 Jun 2012 18:22
Picon

[PATCH 1/2] tcp: Set AI_PASSIVE on listen

---
 libavformat/tcp.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index e77e4c5..d2bfb48 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
 <at>  <at>  -65,6 +65,8  <at>  <at>  static int tcp_open(URLContext *h, const char *uri, int flags)
     hints.ai_socktype = SOCK_STREAM;
     snprintf(portstr, sizeof(portstr), "%d", port);
     ret = getaddrinfo(hostname, portstr, &hints, &ai);
+    if (listen_socket)
+        hints.ai_flags |= AI_PASSIVE;
     if (ret) {
         av_log(h, AV_LOG_ERROR,
                "Failed to resolve hostname %s: %s\n",
--

-- 
1.7.10

Jordi Ortiz | 26 Jun 2012 18:22
Picon

[PATCH 2/2] tcp: Set node NULL if no hostname is provided

---
 libavformat/tcp.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index d2bfb48..c5677fe 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
 <at>  <at>  -64,9 +64,12  <at>  <at>  static int tcp_open(URLContext *h, const char *uri, int flags)
     hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = SOCK_STREAM;
     snprintf(portstr, sizeof(portstr), "%d", port);
-    ret = getaddrinfo(hostname, portstr, &hints, &ai);
     if (listen_socket)
         hints.ai_flags |= AI_PASSIVE;
+    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",
--

-- 
1.7.10

Jordi Ortiz | 26 Jun 2012 19:22
Picon

[PATCH 2/2] tcp: Set node NULL if no hostname is provided

---
 libavformat/tcp.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 1546446..c5677fe 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
 <at>  <at>  -66,7 +66,10  <at>  <at>  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",
--

-- 
1.7.10

Martin Storsjö | 26 Jun 2012 21:28

Re: [PATCH 2/2] tcp: Set node NULL if no hostname is provided

On Tue, 26 Jun 2012, Jordi Ortiz wrote:

> ---
> libavformat/tcp.c |    5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> index 1546446..c5677fe 100644
> --- a/libavformat/tcp.c
> +++ b/libavformat/tcp.c
>  <at>  <at>  -66,7 +66,10  <at>  <at>  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",
> -- 
> 1.7.10

Both look ok to me now, will push later.

// Martin
Martin Storsjö | 26 Jun 2012 18:39

Re: [PATCH 1/2] tcp: Set AI_PASSIVE on listen

On Tue, 26 Jun 2012, Jordi Ortiz wrote:

> ---
> libavformat/tcp.c |    2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> index e77e4c5..d2bfb48 100644
> --- a/libavformat/tcp.c
> +++ b/libavformat/tcp.c
>  <at>  <at>  -65,6 +65,8  <at>  <at>  static int tcp_open(URLContext *h, const char *uri, int flags)
>     hints.ai_socktype = SOCK_STREAM;
>     snprintf(portstr, sizeof(portstr), "%d", port);
>     ret = getaddrinfo(hostname, portstr, &hints, &ai);
> +    if (listen_socket)
> +        hints.ai_flags |= AI_PASSIVE;
>     if (ret) {

You set the flag _after_ calling getaddrinfo?

// Martin
Jordi Ortiz | 26 Jun 2012 19:06
Picon

Re: [PATCH 1/2] tcp: Set AI_PASSIVE on listen


+    if (listen_socket)
+        hints.ai_flags |= AI_PASSIVE;
   if (ret) {

You set the flag _after_ calling getaddrinfo?

Ups, I did the modifications and then split the commits, that line go away on the following commit. Patch comming.
<div>
<br><div class="gmail_quote"><blockquote class="gmail_quote">
<div class="im">
<blockquote class="gmail_quote">

+ &nbsp; &nbsp;if (listen_socket)<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;hints.ai_flags |= AI_PASSIVE;<br>
 &nbsp; &nbsp;if (ret) {<br>
</blockquote>
<br>
</div>
You set the flag _after_ calling getaddrinfo?<br><br>
</blockquote></div>Ups, I did the modifications and then split the commits, that line go away on the following commit. Patch comming.<br>
</div>
Jordi Ortiz | 26 Jun 2012 19:21
Picon

[PATCH 1/2] tcp: Set AI_PASSIVE on listen

---
 libavformat/tcp.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index e77e4c5..1546446 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
 <at>  <at>  -64,6 +64,8  <at>  <at>  static int tcp_open(URLContext *h, const char *uri, int flags)
     hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = SOCK_STREAM;
     snprintf(portstr, sizeof(portstr), "%d", port);
+    if (listen_socket)
+        hints.ai_flags |= AI_PASSIVE;
     ret = getaddrinfo(hostname, portstr, &hints, &ai);
     if (ret) {
         av_log(h, AV_LOG_ERROR,
--

-- 
1.7.10


Gmane