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
@@ -65,7 +65,12 @@ 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
AI_PASSIVE flag is ignored.", so it doesn't hurt but doesn't add anything
either. The OS X manpage says:
If the AI_PASSIVE bit is set it indicates that the returned socket
address structure is intended for use in a call to bind(2).
[...]
If the AI_PASSIVE bit is not set, the returned socket address structure
will be ready for use in a call to connect(2) for a connection-oriented
protocol or connect(2), sendto(2), or sendmsg(2) if a connectionless
protocol was chosen.
Therefore I think it's more correct semantics to always set this flag if
we're going to bind/listen.
Then once we've set the flag, you can pass NULL to gethostname for empty
hostnames, if listening, as a separate feature/change.
// Martin
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel