summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHakan Olsson <ho@cvs.openbsd.org>2001-06-27 05:16:50 +0000
committerHakan Olsson <ho@cvs.openbsd.org>2001-06-27 05:16:50 +0000
commit7dbaadfd726d3d1764a3085697ede3fb5e6b5f45 (patch)
tree12d5220e460a3d1a5cef9679b3f45c48e14cbc32
parent2ffb1ae7e20770be65cd62e2bbf088f62f8639ac (diff)
sockaddr2text w/o HAVE_GETNAMEINFO
-rw-r--r--sbin/isakmpd/util.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/sbin/isakmpd/util.c b/sbin/isakmpd/util.c
index 212e79172d8..e9ebba748e6 100644
--- a/sbin/isakmpd/util.c
+++ b/sbin/isakmpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.13 2001/06/27 00:10:35 ho Exp $ */
+/* $OpenBSD: util.c,v 1.14 2001/06/27 05:16:49 ho Exp $ */
/* $EOM: util.c,v 1.23 2000/11/23 12:22:08 niklas Exp $ */
/*
@@ -39,6 +39,7 @@
#include <sys/socket.h>
#include <sys/stat.h>
#include <netinet/in.h>
+#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
@@ -271,12 +272,26 @@ text2sockaddr (char *address, char *port, struct sockaddr **sa)
int
sockaddr2text (struct sockaddr *sa, char **address)
{
-#ifdef HAVE_GETNAMEINFO
char buf[NI_MAXHOST];
+#ifdef HAVE_GETNAMEINFO
if (getnameinfo (sa, sa->sa_len, buf, sizeof buf, 0, 0,
allow_name_lookups ? 0 : NI_NUMERICHOST))
return -1;
+#else
+ if (sa->sa_family == AF_INET)
+ {
+ strncpy (buf, inet_ntoa (((struct sockaddr_in *)sa)->sin_addr),
+ NI_MAXHOST - 1);
+ buf[NI_MAXHOST - 1] = '\0';
+ }
+ else
+ {
+ log_print ("sockaddr2text: unsupported protocol family %d\n",
+ sa->sa_family);
+ strcpy (buf, "<error>");
+ }
+#endif
*address = malloc (strlen (buf) + 1);
if (!address)
@@ -284,9 +299,6 @@ sockaddr2text (struct sockaddr *sa, char **address)
strcpy (*address, buf);
return 0;
-#else
- return -1;
-#endif
}
/*