aboutsummaryrefslogtreecommitdiff
path: root/lib/if2ip.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/if2ip.c')
-rw-r--r--lib/if2ip.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/if2ip.c b/lib/if2ip.c
index 5fa70a68c..557b6fb8c 100644
--- a/lib/if2ip.c
+++ b/lib/if2ip.c
@@ -74,9 +74,13 @@
#include <sys/sockio.h>
#endif
+#ifdef HAVE_INET_NTOA_R
+#include "inet_ntoa_r.h"
+#endif
+
#define SYS_ERROR -1
-char *if2ip(char *interface)
+char *if2ip(char *interface, char *buf, int buf_size)
{
int dummy;
char *ip=NULL;
@@ -101,7 +105,12 @@ char *if2ip(char *interface)
struct sockaddr_in *s = (struct sockaddr_in *)&req.ifr_dstaddr;
memcpy(&in, &(s->sin_addr.s_addr), sizeof(in));
- ip = (char *)strdup(inet_ntoa(in));
+#if defined(HAVE_INET_NTOA_R)
+ ip = inet_ntoa_r(in,buf,buf_size);
+#else
+ ip = strncpy(buf,inet_ntoa(in),buf_size);
+ ip[buf_size - 1] = 0;
+#endif
}
close(dummy);
}