aboutsummaryrefslogtreecommitdiff
path: root/src/libndb/ipattr.c
blob: 70f3873cea4af6ab31e258bb4424a2ac993ef909 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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((uchar)c))
			continue;
		if(isxdigit((uchar)c))
			hex = 1;
		else if(isalpha((uchar)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";
}