]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lua net.interfaces(): fix mac addresses
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 16 Apr 2019 10:52:16 +0000 (12:52 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Thu, 18 Apr 2019 07:04:29 +0000 (07:04 +0000)
Only the first byte was being shown since 3ab77332.
I can't see at all why this part was changed;
the buffer is (and was) way overlong for this,
so writing one zero byte just after the end is OK.

daemon/bindings/net.c

index 0b22ffcb619505255dc87430134e00048bc1de08..144f8b47f795f265f0e3e922746548f078a90bbf 100644 (file)
@@ -240,11 +240,11 @@ static int net_interfaces(lua_State *L)
 
                /* Hardware address. */
                char *p = buf;
-               memset(buf, 0, sizeof(buf));
-               for (unsigned k = 0; k < sizeof(iface.phys_addr); ++k) {
-                       sprintf(p, "%s%.2x", k > 0 ? ":" : "", iface.phys_addr[k] & 0xff);
+               for (int k = 0; k < sizeof(iface.phys_addr); ++k) {
+                       sprintf(p, "%.2x:", (uint8_t)iface.phys_addr[k]);
                        p += 3;
                }
+               p[-1] = '\0';
                lua_pushstring(L, buf);
                lua_setfield(L, -2, "mac");