summaryrefslogtreecommitdiff
path: root/lib/inet_ntop.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2014-10-06 14:00:40 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2014-10-06 14:00:40 +0200
commit6e9c41a892ed0e0da326e0278b3221ce3f5713b8 (patch)
tree2e301d871bbeeb44aa57ff9cc070fcf3be484487 /lib/inet_ntop.c
Initial import of sane-backends version 1.0.24-1.2
Diffstat (limited to 'lib/inet_ntop.c')
-rw-r--r--lib/inet_ntop.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/inet_ntop.c b/lib/inet_ntop.c
new file mode 100644
index 0000000..b5e357c
--- /dev/null
+++ b/lib/inet_ntop.c
@@ -0,0 +1,40 @@
+#include "../include/sane/config.h"
+
+#ifndef HAVE_INET_NTOP
+
+#include <string.h>
+#include <sys/types.h>
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#endif
+
+
+const char *
+inet_ntop (int af, const void *src, char *dst, size_t cnt)
+{
+ struct in_addr in;
+ char *text_addr;
+
+#ifdef HAVE_INET_NTOA
+ if (af == AF_INET)
+ {
+ memcpy (&in.s_addr, src, sizeof (in.s_addr));
+ text_addr = inet_ntoa (in);
+ if (text_addr && dst)
+ {
+ strncpy (dst, text_addr, cnt);
+ return dst;
+ }
+ else
+ return 0;
+ }
+#endif /* HAVE_INET_NTOA */
+ return 0;
+}
+
+#endif /* !HAVE_INET_NTOP */