]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libndb/ipattr.c
Import sources from 2011-03-30 iso image
[plan9front.git] / sys / src / libndb / ipattr.c
1 #include <u.h>
2 #include <ctype.h>
3
4 /*
5  *  return ndb attribute type of an ip name
6  */
7 char*
8 ipattr(char *name)
9 {
10         char *p, c;
11         int dot = 0;
12         int alpha = 0;
13         int colon = 0;
14         int hex = 0;
15
16         for(p = name; *p; p++){
17                 c = *p;
18                 if(isdigit(c))
19                         continue;
20                 if(isxdigit(c))
21                         hex = 1;
22                 else if(isalpha(c) || c == '-')
23                         alpha = 1;
24                 else if(c == '.')
25                         dot = 1;
26                 else if(c == ':')
27                         colon = 1;
28                 else
29                         return "sys";
30         }
31
32         if(alpha){
33                 if(dot)
34                         return "dom";
35                 else
36                         return "sys";
37         }
38
39         if(colon)
40                 return "ip";    /* ip v6 */
41
42         if(dot && !hex)
43                 return "ip";
44         else
45                 return "sys";
46 }