Skip to content

Commit 34cc4d0

Browse files
committed
mac-to-eui64: Fix the displaying of some IPv6 addresses
Given a MAC address of de:ad:be:ef:00:01 we would print (SLAAC Host) : ::dcad:beff:feef:01 (link-local) : fe80::dcad:beff:feef:01 While not wrong, the :01 would be better shown as just :1 However, given 00:10:a4:01:23:45 we would print (SLAAC Host) : ::210:a4ff:fe1:2345 (link-local) : fe80::210:a4ff:fe1:2345 this _is_ wrong. The :fe1: should be :fe01: The simplest, and perhaps correct way in any case, to fix this is to simply display the addresses in uncompressed form (the other tools in here tend to display in uncompressed form and there is always the ipv6-fmt program) by ensuring we 0 pad each component of the EUI-64 address when combining the pairs. So now the above two examples become (SLAAC Host) : ::dcad:beff:feef:0001 (link-local) : fe80::dcad:beff:feef:0001 (SLAAC Host) : ::0210:a4ff:fe01:2345 (link-local) : fe80::0210:a4ff:fe01:2345 Signed-off-by: Andrew Clayton <[email protected]>
1 parent 4b54fc5 commit 34cc4d0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mac-to-eui64.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* mac-to-eui64.c - Generate a modified EUI-64 identifier for the given MAC
33
* address.
44
*
5-
* Copyright (C) 2016 - 2017 Andrew Clayton <[email protected]>
5+
* Copyright (C) 2016 - 2017, 2021 Andrew Clayton
6+
67
*
78
* Licensed under the GNU General Public License Version 2 or
89
* the GNU Lesser General Public License Version 2.1
@@ -43,10 +44,10 @@ int main(int argc, char *argv[])
4344
printf("%02x%s", mac[i], (i < 7) ? ":" : "");
4445
printf("\n(SLAAC Host) : ::");
4546
for (i = 0; i < 8; i += 2)
46-
printf("%x%x%s", mac[i], mac[i + 1], i+1 < 7 ? ":" : "");
47+
printf("%02x%02x%s", mac[i], mac[i + 1], i+1 < 7 ? ":" : "");
4748
printf("\n(link-local) : fe80::");
4849
for (i = 0; i < 8; i += 2)
49-
printf("%x%x%s", mac[i], mac[i + 1], i+1 < 7 ? ":" : "");
50+
printf("%02x%02x%s", mac[i], mac[i + 1], i+1 < 7 ? ":" : "");
5051
printf("\n");
5152

5253
exit(EXIT_SUCCESS);

0 commit comments

Comments
 (0)