- *q = '\0';
- if (*p != ':')
- goto fail;
- p++;
- port = strtoul(p, (char **)&p, 10);
- if (port <= 0 || port >= 65536)
- goto fail;
-
- dest_addr.sin_family = AF_INET;
- dest_addr.sin_port = htons(port);
- if (resolve_host(&dest_addr.sin_addr, hostname) < 0)
- goto fail;
+ p = strchr(uri, '?');
+ if (p) {
+ if (av_find_info_tag(buf, sizeof(buf), "listen", p))
+ s->listen = 1;
+ if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) {
+ s->timeout = strtol(buf, NULL, 10) * 100;
+ }
+ if (av_find_info_tag(buf, sizeof(buf), "listen_timeout", p)) {
+ s->listen_timeout = strtol(buf, NULL, 10);
+ }
+ }
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ snprintf(portstr, sizeof(portstr), "%d", port);
+ if (s->listen)
+ 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",
+ hostname, gai_strerror(ret));
+ return AVERROR(EIO);
+ }
+
+ cur_ai = ai;