[FFmpeg-devel] [PATCH] ffserver: stop using the deprecated resolve_host()
Mans Rullgard
mans
Mon Mar 8 01:32:42 CET 2010
This replaces resolve_host() usage in ffserver with a wrapper
for getaddrinfo returning the first IPv4 address, if any.
Ultimately, ffserver should be made to work with IPv6 addresses,
but that change is much more involved.
---
ffserver.c | 32 +++++++++++++++++++++++++++-----
1 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/ffserver.c b/ffserver.c
index e6b8034..1d5c2d8 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -312,6 +312,28 @@ static AVLFG random_state;
static FILE *logfile = NULL;
+static int get_inet_addr(struct in_addr *sin_addr, const char *hostname)
+{
+ struct addrinfo *addr_list, *addr;
+ int err;
+
+ err = getaddrinfo(hostname, NULL, NULL, &addr_list);
+ if (err)
+ return err;
+
+ for (addr = addr_list; addr; addr = addr->ai_next)
+ if (addr->ai_family == AF_INET)
+ break;
+
+ if (addr)
+ *sin_addr = ((struct sockaddr_in *)addr->ai_addr)->sin_addr;
+ else
+ err = -1;
+
+ freeaddrinfo(addr_list);
+ return err;
+}
+
static char *ctime1(char *buf2)
{
time_t ti;
@@ -3830,7 +3852,7 @@ static int parse_ffconfig(const char *filename)
my_http_addr.sin_port = htons(val);
} else if (!strcasecmp(cmd, "BindAddress")) {
get_arg(arg, sizeof(arg), &p);
- if (resolve_host(&my_http_addr.sin_addr, arg) != 0) {
+ if (get_inet_addr(&my_http_addr.sin_addr, arg) != 0) {
fprintf(stderr, "%s:%d: Invalid host/IP address: %s\n",
filename, line_num, arg);
errors++;
@@ -3848,7 +3870,7 @@ static int parse_ffconfig(const char *filename)
my_rtsp_addr.sin_port = htons(atoi(arg));
} else if (!strcasecmp(cmd, "RTSPBindAddress")) {
get_arg(arg, sizeof(arg), &p);
- if (resolve_host(&my_rtsp_addr.sin_addr, arg) != 0) {
+ if (get_inet_addr(&my_rtsp_addr.sin_addr, arg) != 0) {
fprintf(stderr, "%s:%d: Invalid host/IP address: %s\n",
filename, line_num, arg);
errors++;
@@ -4332,7 +4354,7 @@ static int parse_ffconfig(const char *filename)
get_arg(arg, sizeof(arg), &p);
- if (resolve_host(&acl.first, arg) != 0) {
+ if (get_inet_addr(&acl.first, arg) != 0) {
fprintf(stderr, "%s:%d: ACL refers to invalid host or ip address '%s'\n",
filename, line_num, arg);
errors++;
@@ -4342,7 +4364,7 @@ static int parse_ffconfig(const char *filename)
get_arg(arg, sizeof(arg), &p);
if (arg[0]) {
- if (resolve_host(&acl.last, arg) != 0) {
+ if (get_inet_addr(&acl.last, arg) != 0) {
fprintf(stderr, "%s:%d: ACL refers to invalid host or ip address '%s'\n",
filename, line_num, arg);
errors++;
@@ -4382,7 +4404,7 @@ static int parse_ffconfig(const char *filename)
} else if (!strcasecmp(cmd, "MulticastAddress")) {
get_arg(arg, sizeof(arg), &p);
if (stream) {
- if (resolve_host(&stream->multicast_ip, arg) != 0) {
+ if (get_inet_addr(&stream->multicast_ip, arg) != 0) {
fprintf(stderr, "%s:%d: Invalid host/IP address: %s\n",
filename, line_num, arg);
errors++;
--
1.7.0
More information about the ffmpeg-devel
mailing list