aboutsummaryrefslogtreecommitdiff
path: root/src/libndb/ipattr.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-02-11 19:41:16 +0000
committerrsc <devnull@localhost>2005-02-11 19:41:16 +0000
commitd957951b75df08a9bb0293e3e13ff87759afbb92 (patch)
tree4d7868b0d223956217cbc8819d7afb3bec532cca /src/libndb/ipattr.c
parentad017cfbf5530cfc3ae2fafd723cdade2a4405f6 (diff)
downloadplan9port-d957951b75df08a9bb0293e3e13ff87759afbb92.tar.gz
plan9port-d957951b75df08a9bb0293e3e13ff87759afbb92.tar.bz2
plan9port-d957951b75df08a9bb0293e3e13ff87759afbb92.zip
new
Diffstat (limited to 'src/libndb/ipattr.c')
-rw-r--r--src/libndb/ipattr.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/libndb/ipattr.c b/src/libndb/ipattr.c
new file mode 100644
index 00000000..d23d5ee0
--- /dev/null
+++ b/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";
+}