summaryrefslogtreecommitdiff
path: root/sys/src/libndb/ipattr.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libndb/ipattr.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libndb/ipattr.c')
-rwxr-xr-xsys/src/libndb/ipattr.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/sys/src/libndb/ipattr.c b/sys/src/libndb/ipattr.c
new file mode 100755
index 000000000..d23d5ee09
--- /dev/null
+++ b/sys/src/libndb/ipattr.c
@@ -0,0 +1,46 @@
+#include <u.h>
+#include <ctype.h>
+
+/*
+ * return ndb attribute type of an ip name
+ */
+char*
+ipattr(char *name)
+{
+ char *p, c;
+ int dot = 0;
+ int alpha = 0;
+ int colon = 0;
+ int hex = 0;
+
+ for(p = name; *p; p++){
+ c = *p;
+ if(isdigit(c))
+ continue;
+ if(isxdigit(c))
+ hex = 1;
+ else if(isalpha(c) || c == '-')
+ alpha = 1;
+ else if(c == '.')
+ dot = 1;
+ else if(c == ':')
+ colon = 1;
+ else
+ return "sys";
+ }
+
+ if(alpha){
+ if(dot)
+ return "dom";
+ else
+ return "sys";
+ }
+
+ if(colon)
+ return "ip"; /* ip v6 */
+
+ if(dot && !hex)
+ return "ip";
+ else
+ return "sys";
+}