ifconfig - who decided that MAC address should be lowercase?

On some Linux computers, ifconfig displays the MAC address ("HWaddr") hex digits in uppercase. On other Linux computers, the [a-f] digits are lowercase.

Why the difference? Are there two competing versions of the program? Is there an option somewhere to control it?

5

1 Answer

There are several possible reasons.

 Different interface types

One possibility: ifconfig delegates printing of the hardware address to the interface implementation. Actual printing is performed by a function in the interface struct for the specific interface in net-tools-1.60 (from here), called by lib/interface.c, line 678:

printf(_("HWaddr %s "), hw->print(ptr->hwaddr));

See the source code for nettools-1.60 in lib/hw.c for a list of supported interface types: There are separate implementations for ethernet, fiber, token ring, etc.

Now to the actual printing function: Example: lib/ether.c:

/* Display an Ethernet address in readable format. */
static char *pr_ether(unsigned char *ptr)
{ static char buff[64]; snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X", (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) ); return (buff);
}

The different kinds of network interfaces can be implemented to display the same kind of information differently by using lowercase xs in the formatting string instead (i.e. %02x instead of %02X). For example, the IrDA interface uses lowercase hex digits (lib/irda.c):

/* * Function irda_print (ptr) * * Print hardware address of interface * */
static char *irda_print(unsigned char *ptr)
{ static char buff[8]; sprintf(&buff[strlen(buff)], "%02x:%02x:%02x:%02x", ptr[3], ptr[2], ptr[1], ptr[0]); return (buff);
}

Patches to ifconfig

Another possibility, and likely the reason here: Distributions often change the software packages. The above code snippet is from the original net-tools-1.60, let's look at Debian's, or rather, its patch net-tools-1.60-23.diff (from here):

+---
++++ net-tools/lib/ether.c
[...]
+@@ -39,7 +39,7 @@ static char *pr_ether(unsigned char *ptr
+ {
+ static char buff[64];
+
+- snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X",
++ snprintf(buff, sizeof(buff), "%02x:%02x:%02x:%02x:%02x:%02x",
+ (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
+ (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
+ );

So Debian patched the source code to ifconfig for their distribution, which might also get picked up by Ubuntu (Wikipedia: "Ubuntu packages are based on packages from Debian's unstable branch").

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like