From 6afd5c16d3f7377d47ee3d9bb3237b636cfe2f35 Mon Sep 17 00:00:00 2001 From: Dominick Meglio Date: Sun, 18 Sep 2005 16:44:49 +0000 Subject: Added constants that will be used by ares_getaddrinfo. Made ares_getnameinfo use the reentrant getservbyport (getservbyport_r) if it isavailable to ensure it works properly in a threaded environment --- ares_getnameinfo.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'ares_getnameinfo.c') diff --git a/ares_getnameinfo.c b/ares_getnameinfo.c index 23a5c79..e137fd3 100644 --- a/ares_getnameinfo.c +++ b/ares_getnameinfo.c @@ -256,7 +256,16 @@ static char *lookup_service(unsigned short port, int flags, char *buf) { struct servent *se; const char *proto; - +#if GETSERVBYPORT_R_ARGS == 6 + struct servent ret; + char buf[4096]; + int len = 4096; +#elif GETSERVBYPORT_R_ARGS == 5 + char buf[4096]; + int len = 4096; +#elif GETSERVBYPORT_R_ARGS == 4 + struct servent_data sed; +#endif if (flags & ARES_NI_UDP) proto = "udp"; else if (flags & ARES_NI_SCTP) @@ -265,7 +274,23 @@ static char *lookup_service(unsigned short port, int flags, char *buf) proto = "dccp"; else proto = "tcp"; +#ifdef HAVE_GETSERVBYPORT_R + #if GETSERVBYPORT_R_ARGS == 6 + if (getservbyport_r(port, proto, se, buf, len, &ret)) + se = NULL; + #elif GETSERVBYPORT_R_ARGS == 5 + se = getservbyport_r(port, proto, se, buf, len); + #elif GETSERVBYPORT_R_ARGS == 4 + if (getservbyport_r(port, proto, se, &sed) == -1) + se = NULL; + #else + /* Lets just hope the OS uses TLS! */ + se = getservbyport(port, proto); + #endif +#else + /* Lets just hope the OS uses TLS! */ se = getservbyport(port, proto); +#endif if (se && se->s_name) strcpy(buf, se->s_name); else -- cgit v1.2.3