-
Notifications
You must be signed in to change notification settings - Fork 4
/
mac-type.c
49 lines (42 loc) · 1.12 KB
/
mac-type.c
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
47
48
49
/*
* mac-type.c - Check the U/L (LG) & IG bits in a MAC address.
*
* Copyright (C) 2016 - 2017 Andrew Clayton <[email protected]>
*
* Licensed under the GNU General Public License Version 2 or
* the GNU Lesser General Public License Version 2.1
*
* See GPLv2 & LGPLv2.1 in the source tree.
*/
#include <stdio.h>
#include <stdlib.h>
#include "short_types.h"
int main(int argc, char *argv[])
{
char macstr[20];
u8 mac;
if (argc < 2) {
scanf("%19s", macstr);
printf("%s\n\n", macstr);
} else {
snprintf(macstr, sizeof(macstr), "%s", argv[1]);
}
mac = strtoul(macstr, NULL, 16);
/*
* Test for the U/L (LG) bit which is the second-least-significant
* bit of the first byte of the address.
*/
if (mac & 0x02)
printf("U/L (LG) bit is set. Address is locally administered.\n");
else
printf("U/L (LG) bit is NOT set. Address is universally administered.\n");
/*
* Test for the IG bit which is the least-significant bit of the
* first byte of the address.
*/
if (mac & 0x01)
printf("IG bit is set. Broadcast address.\n");
else
printf("IG bit is NOT set. Unicast address.\n");
exit(EXIT_SUCCESS);
}