summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2014-06-27 11:30:25 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2014-06-28 14:08:12 +0200
commit1eed696f35daf52f5ec135c1959c0064d82d5966 (patch)
tree9438d3a6f813f775214374c24be1f9e3390b5721
parent27b9bc50b83b91c0364f819c4c0ca6bf6e242293 (diff)
downloadgnutls-1eed696f35daf52f5ec135c1959c0064d82d5966.tar.gz
Use inet_ntop() for printing IP addresses.
The old dumb code is used in systems that don't have that function.
-rw-r--r--configure.ac2
-rw-r--r--lib/x509/output.c12
2 files changed, 12 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index b09f227829..e7c4d8b767 100644
--- a/configure.ac
+++ b/configure.ac
@@ -151,7 +151,7 @@ AC_C_BIGENDIAN
dnl No fork on MinGW, disable some self-tests until we fix them.
dnl Check clock_gettime and pthread_mutex_lock in libc (avoid linking to other libs)
-AC_CHECK_FUNCS([fork getrusage getpwuid_r nanosleep daemon getpid clock_gettime iconv localtime vasprintf],,)
+AC_CHECK_FUNCS([fork inet_ntop getrusage getpwuid_r nanosleep daemon getpid clock_gettime iconv localtime vasprintf],,)
AM_CONDITIONAL(HAVE_FORK, test "$ac_cv_func_fork" != "no")
AC_LIB_HAVE_LINKFLAGS(rt,, [#include <time.h>
diff --git a/lib/x509/output.c b/lib/x509/output.c
index af244c6621..41f3be710c 100644
--- a/lib/x509/output.c
+++ b/lib/x509/output.c
@@ -31,6 +31,10 @@
#include <gnutls_errors.h>
#include <extras/randomart.h>
+#ifdef HAVE_INET_NTOP
+# include <arpa/inet.h>
+#endif
+
#define addf _gnutls_buffer_append_printf
#define adds _gnutls_buffer_append_str
@@ -56,6 +60,12 @@ static char *ip_to_string(void *_ip, int ip_size, char *string,
return NULL;
}
+#ifdef HAVE_INET_NTOP
+ if (ip_size == 4)
+ return inet_ntop(AF_INET, _ip, string, string_size);
+ else
+ return inet_ntop(AF_INET6, _ip, string, string_size);
+#else
ip = _ip;
switch (ip_size) {
case 4:
@@ -70,8 +80,8 @@ static char *ip_to_string(void *_ip, int ip_size, char *string,
(ip[12] << 8) | ip[13], (ip[14] << 8) | ip[15]);
break;
}
-
return string;
+#endif
}
static void