xref: /plan9/sys/src/libndb/ipattr.c (revision 7dd7cddf99dd7472612f1413b4da293630e6b1bc)
1 #include <u.h>
2 #include <ctype.h>
3 
4 /*
5  *  return ndb attribute type of an ip name
6  */
7 char*
ipattr(char * name)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 }
47