]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
cast
authorJelte Jansen <jeltejan@NLnetLabs.nl>
Thu, 18 Aug 2005 09:11:31 +0000 (09:11 +0000)
committerJelte Jansen <jeltejan@NLnetLabs.nl>
Thu, 18 Aug 2005 09:11:31 +0000 (09:11 +0000)
str2host.c

index 573b8aa48b7c6c50733a3823a72d4d061654d7b3..c4c825bcb79d9c1f48ef3da9db73720f0021ebb7 100644 (file)
 #include <sys/param.h>
 #endif
 
+bool
+ldns_is_ipv4_addr(const char *str)
+{
+       int a, i;
+       const char *dot = str;
+
+       if (strlen(str) < 7 || strlen(str) > 16) {
+               return false;
+       }
+
+       for (i = 0; i < 3; i++) {
+               a = atoi(dot);
+               if (a < 0 || a > 255) {
+                       return false;
+               }
+               dot = strchr(dot, '.');
+               if (!dot) {
+                       return false;
+               }
+       }
+       a = atoi(dot);
+       if (a < 0 || a > 255) {
+               return false;
+       }
+
+       return true;
+}
+
+/* todo: check for more errors (like ffffff:f etc) */
+bool
+ldns_is_ipv6_addr(const char *str)
+{
+       int a;
+       size_t i;
+       const char *dot = str;
+
+       if (strlen(str) < 3 || strlen(str) > 40) {
+               return false;
+       }
+
+       for (i = 0; i < strlen(str); i++) {
+               if (str[i] != ':' &&
+                   ldns_hexdigit_to_int(str[i]) < 0) {
+                       return false;
+               }
+       }
+       a = atoi(dot);
+       if (a < 0 || a > 255) {
+               return false;
+       }
+
+       return true;
+}
+
 ldns_status
 ldns_str2rdf_int16(ldns_rdf **rd, const char *shortstr)
 {