- char proto[1024],path[1024],tmp[1024]; // PETR: protocol and path strings
-
- url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
- &port, path, sizeof(path), uri); // PETR: use url_split
- if (strcmp(proto,"tcp")) goto fail; // PETR: check protocol
- if ((q = strchr(hostname,'@'))) { strcpy(tmp,q+1); strcpy(hostname,tmp); } // PETR: take only the part after '@' for tcp protocol
-
- s = av_malloc(sizeof(TCPContext));
- if (!s)
- return AVERROR(ENOMEM);
- h->priv_data = s;
-
- if (port <= 0 || port >= 65536)
- goto fail;
-
- if(!ff_network_init())
+ char hostname[1024],proto[1024],path[1024];
+ char portstr[10];
+
+ av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
+ &port, path, sizeof(path), uri);
+ if (strcmp(proto,"tcp") || port <= 0 || port >= 65536)
+ return AVERROR(EINVAL);
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ snprintf(portstr, sizeof(portstr), "%d", port);
+ ret = getaddrinfo(hostname, portstr, &hints, &ai);
+ if (ret) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Failed to resolve hostname %s: %s\n",
+ hostname, gai_strerror(ret));