File: mac.c

package info (click to toggle)
xtables-addons 3.13-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,504 kB
  • sloc: ansic: 10,717; sh: 4,481; perl: 356; makefile: 143; python: 15
file content (29 lines) | stat: -rw-r--r-- 572 bytes parent folder | download | duplicates (6)
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
static bool mac_parse(const char *addr, unsigned char *dest, uint8_t *mask)
{
	unsigned int i = 0, value;
	char *end;

	for (i = 0; i < ETH_ALEN; ++i) {
		value = strtoul(addr, &end, 16);
		if (addr == end || value > 0xFF)
			return false;
		if (i == ETH_ALEN - 1) {
			if (*end != '\0' && *end != '/')
				return false;
		} else if (*end != ':') {
			return false;
		}
		dest[i] = value;
		addr = end + 1;
	}

	*mask = 48;
	if (*end == '/') {
		if (!xtables_strtoui(end + 1, &end, &value, 0, 48))
			return false;
		if (*end != '\0')
			return false;
	}

	return true;
}