Skip to content

Commit

Permalink
[runtime] Use getprotobyname_r() where needed and available
Browse files Browse the repository at this point in the history
Fixes mono#7087
  • Loading branch information
alexischr committed Aug 17, 2018
1 parent 47cb859 commit 32b4515
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
17 changes: 17 additions & 0 deletions configure.ac
Expand Up @@ -2286,6 +2286,23 @@ if test x$host_win32 = xno; then
AC_MSG_RESULT(no)
])

dnl **********************************
dnl *** Check for getprotobyname_r ***
dnl **********************************
AC_MSG_CHECKING(for getprotobyname_r)
AC_TRY_LINK([
#include <stdio.h>
#include <netdb.h>
], [
getprotobyname_r(NULL, NULL, NULL, 0, NULL);
], [
# Yes, we have it...
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_GETPROTOBYNAME_R, 1, [Have getprotobyname_r])
], [
AC_MSG_RESULT(no)
])

dnl **********************************
dnl *** Check for getnameinfo ***
dnl **********************************
Expand Down
23 changes: 20 additions & 3 deletions mono/utils/networking-posix.c
Expand Up @@ -127,7 +127,24 @@ mono_get_address_info (const char *hostname, int port, int flags, MonoAddressInf

#endif

#ifdef HAVE_GETPROTOBYNAME
#if (defined(__linux__) && defined (HAVE_GETPROTOBYNAME_R)

static int
fetch_protocol (const char *proto_name, int *cache, int *proto, int default_val)
{
if (!*cache) {
struct protoent protoent_buf = { 0 };
struct protoent *pent = NULL;
char buf[1024];

getprotobyname_r (proto_name, &protoent_buf, buf, 1024, &pent);
*proto = pent ? pent->p_proto : default_val;
*cache = 1;
}
return *proto;
}

#elif HAVE_GETPROTOBYNAME

static int
fetch_protocol (const char *proto_name, int *cache, int *proto, int default_val)
Expand All @@ -142,6 +159,8 @@ fetch_protocol (const char *proto_name, int *cache, int *proto, int default_val)
return *proto;
}

#endif

int
mono_networking_get_tcp_protocol (void)
{
Expand All @@ -163,8 +182,6 @@ mono_networking_get_ipv6_protocol (void)
return fetch_protocol ("ipv6", &cache, &proto, 41); //41 is SOL_IPV6 on linux
}

#endif

#if defined (HAVE_SIOCGIFCONF)

#define IFCONF_BUFF_SIZE 1024
Expand Down

0 comments on commit 32b4515

Please sign in to comment.