aboutsummaryrefslogtreecommitdiffstats
path: root/resolv.c
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@itojun.org>1999-10-14 05:41:33 +0000
committerJun-ichiro itojun Hagino <itojun@itojun.org>1999-10-14 05:41:33 +0000
commit831497b33e358305b8f409882ec61097335b772d (patch)
tree70de51573eace737c5d829570dc33bd6b5261020 /resolv.c
parent5ed4011c300a8c1688ee5aa1b184aa0d2fc54bc7 (diff)
use inet_pton() and inet_ntop(), which are RFC2553 standard function
for converting IPv[46] numeric notation to/from binary form. recent BIND includes those functions so fallback is not necessary on most of the platforms. sorry if it raises any portability problem on other platforms. remove partial inclusion of inet_ntop() in packet-ipv6.c. move ip6_to_str() to packet.c, it fits better there than packet-ipv6.c. svn path=/trunk/; revision=829
Diffstat (limited to 'resolv.c')
-rw-r--r--resolv.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/resolv.c b/resolv.c
index 8048f2e15d..4c8efb6404 100644
--- a/resolv.c
+++ b/resolv.c
@@ -1,7 +1,7 @@
/* resolv.c
* Routines for network object lookup
*
- * $Id: resolv.c,v 1.13 1999/10/11 03:03:11 guy Exp $
+ * $Id: resolv.c,v 1.14 1999/10/14 05:41:33 itojun Exp $
*
* Laurent Deniel <deniel@worldnet.fr>
*
@@ -858,6 +858,11 @@ gboolean get_host_ipaddr(const char *host, guint32 *addrp)
struct in_addr ipaddr;
struct hostent *hp;
+ /*
+ * don't change it to inet_pton(AF_INET), they are not 100% compatible.
+ * inet_pton(AF_INET) does not support hexadecimal notation nor
+ * less-than-4 octet notation.
+ */
if (!inet_aton(host, &ipaddr)) {
/* It's not a valid dotted-quad IP address; is it a valid
* host name? */
@@ -875,3 +880,29 @@ gboolean get_host_ipaddr(const char *host, guint32 *addrp)
*addrp = ntohl(ipaddr.s_addr);
return TRUE;
}
+
+/*
+ * Translate IPv6 numeric address or FQDN hostname, into binary IPv6 address.
+ * Return TRUE if we succeed and set "*addrp" to that numeric IP address;
+ * return FALSE if we fail.
+ */
+gboolean get_host_ipaddr6(const char *host, struct e_in6_addr *addrp)
+{
+ struct hostent *hp;
+
+ if (inet_pton(AF_INET6, host, addrp) == 1)
+ return TRUE;
+
+ /* try FQDN */
+#ifdef HAVE_GETHOSTBYNAME2
+ hp = gethostbyname2(host, AF_INET6);
+#else
+ hp = NULL;
+#endif
+ if (hp != NULL && hp->h_length == sizeof(struct e_in6_addr)) {
+ memcpy(addrp, hp->h_addr, hp->h_length);
+ return TRUE;
+ }
+
+ return FALSE;
+}