Score:0

dhcpd server invalid mac detection

jp flag

On my dhcp configuration, i have on commit hook to save device information. My problem is some of the mac addresses becomes invalid:

8:7c:39:cf:b6:3f - this should start with zero

8:d0:b7:52:f9:68 - also this

my dhcpd.conf

set clientmac = binary-to-ascii(16,8,":",substring(hardware,1,6));

djdomi avatar
za flag
remind, that you should add like what OS you uses, and what are you trying to solve?
Score:1
in flag

It depends on what you use to parse it, one can argue that it is completely valid to leave out prefix zeroes, and that is what we do most of the time because there is no definition of how many digits there should be.

However if we skip over the part about if this is being invalid and why or not and instead ask "How do I get this in desired format" we can provide a answer.

In this case isc has a KB article about it

This is not a bug. The problem is that the binary-to-ascii function doesn't "know" anything about the intended use of the converted binary digits and it's unusual to include leading zeroes when printing numeric values.

However, with a bit of additional manipulation it's still possible to get the desired result:

set foo = concat (
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,1,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,2,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,3,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,4,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,5,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,6,1))),2)
);

(It operates by converting each "component" separately, adding a leading zero to it (in case one is needed); taking the last two hex characters, and then concatenating them all together again.)

jp flag
Thank you for your time answering this issue. Good solution.
in flag
If this solves your question, please mark it as answer ;)
jp flag
No yet, I am still looking for a better solution. I am currently using my alternative solution which is `if mac_address is invalid then do arp ip_address` which is currently shorter than concatenating strings. But you have a good solution anyway.
in flag
The question is about MAC address being "invalid" and how to have them with prefixed zeros? Hope you find a good solution for your real issue then, even tho that seems different from this question.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.