network: use getservbyport() only if available

The absence of this function will only give a less informative
string back from our fallback implementation of getnameinfo().

Signed-off-by: Mans Rullgard <mans@mansr.com>
This commit is contained in:
Mans Rullgard 2012-10-14 20:24:51 +01:00
parent da0d0ae9a4
commit c3e73100af
2 changed files with 4 additions and 0 deletions

2
configure vendored
View File

@ -1190,6 +1190,7 @@ HAVE_LIST="
GetProcessTimes
GetSystemTimeAsFileTime
getrusage
getservbyport
gettimeofday
gnu_as
ibm_asm
@ -3158,6 +3159,7 @@ if enabled network; then
check_struct "sys/types.h sys/socket.h" "struct sockaddr" sa_len
check_type netinet/sctp.h "struct sctp_event_subscribe"
check_func getaddrinfo $network_extralibs
check_func getservbyport $network_extralibs
# Prefer arpa/inet.h over winsock2
if check_header arpa/inet.h ; then
check_func closesocket

View File

@ -235,8 +235,10 @@ int ff_getnameinfo(const struct sockaddr *sa, int salen,
if (serv && servlen > 0) {
struct servent *ent = NULL;
#if HAVE_GETSERVBYPORT
if (!(flags & NI_NUMERICSERV))
ent = getservbyport(sin->sin_port, flags & NI_DGRAM ? "udp" : "tcp");
#endif
if (ent)
snprintf(serv, servlen, "%s", ent->s_name);