summaryrefslogtreecommitdiffstats
path: root/ipv4_scan.c
blob: 061692b7bb917494026ba1f22a3690e01e94720e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#include "scan.h"

unsigned int ipv4_scan(const char *s,char ip[4])
{
	unsigned int i;
	unsigned int len;
	unsigned long u;

	len = 0;
	i = scan_ulong(s,&u); if (!i) return 0; ip[0] = u; s += i; len += i;
	if (*s != '.') return 0; ++s; ++len;
	i = scan_ulong(s,&u); if (!i) return 0; ip[1] = u; s += i; len += i;
	if (*s != '.') return 0; ++s; ++len;
	i = scan_ulong(s,&u); if (!i) return 0; ip[2] = u; s += i; len += i;
	if (*s != '.') return 0; ++s; ++len;
	i = scan_ulong(s,&u); if (!i) return 0; ip[3] = u; s += i; len += i;
	return len;
}