os_support: Don't try to return the service name as a string in getnameinfo

Some systems may be lacking getservbyport; the previous ifdef wasn't
quite enough since it still assumed that struct servent was defined,
as pointed out by Clément Gregoire.

Simply remove the possibility to return non-numeric services in
getnameinfo; no caller of getnameinfo within libavformat
currently try to use getnameinfo for retrieving the port number without
NI_NUMERICSERV, and falling back on getservbyport may be non-threadsafe.

Signed-off-by: Martin Storsjö <martin@martin.st>
pull/158/head
Martin Storsjö 9 years ago
parent 567ca14295
commit 00b62968d0
  1. 2
      configure
  2. 11
      libavformat/os_support.c

2
configure vendored

@ -1513,7 +1513,6 @@ SYSTEM_FUNCS="
GetProcessMemoryInfo GetProcessMemoryInfo
GetProcessTimes GetProcessTimes
getrusage getrusage
getservbyport
GetSystemTimeAsFileTime GetSystemTimeAsFileTime
gettimeofday gettimeofday
gmtime_r gmtime_r
@ -4240,7 +4239,6 @@ fi
if ! disabled network; then if ! disabled network; then
check_func getaddrinfo $network_extralibs check_func getaddrinfo $network_extralibs
check_func getservbyport $network_extralibs
check_func inet_aton $network_extralibs check_func inet_aton $network_extralibs
check_type netdb.h "struct addrinfo" check_type netdb.h "struct addrinfo"

@ -204,16 +204,9 @@ int ff_getnameinfo(const struct sockaddr *sa, int salen,
} }
if (serv && servlen > 0) { if (serv && servlen > 0) {
struct servent *ent = NULL;
#if HAVE_GETSERVBYPORT
if (!(flags & NI_NUMERICSERV)) if (!(flags & NI_NUMERICSERV))
ent = getservbyport(sin->sin_port, flags & NI_DGRAM ? "udp" : "tcp"); return EAI_FAIL;
#endif /* HAVE_GETSERVBYPORT */ snprintf(serv, servlen, "%d", ntohs(sin->sin_port));
if (ent)
snprintf(serv, servlen, "%s", ent->s_name);
else
snprintf(serv, servlen, "%d", ntohs(sin->sin_port));
} }
return 0; return 0;

Loading…
Cancel
Save