Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
Beside ifconfig being obsolete, all relevant functions don't care if a hex digit is lower or upper case. What upsets you about lower case? –  ott-- Feb 6 '13 at 21:21
    
just curious as to why it's sometimes different. Sure my tools can use stackoverflow.com/questions/2264428/… –  OJW Feb 6 '13 at 21:46
    
Only see uppercase on my centos systems. Can you supply distro/version for the lowercase? –  ckhan Feb 6 '13 at 22:36
    
@ckhan which type of systems prefer uppercase? My lowercase example was Ubuntu 12.04 (tested on desktop and server editions) –  OJW Feb 6 '13 at 22:38
    
UC was centos, obviously. ignore previous. –  OJW Feb 6 '13 at 23:07

1 Answer 1

up vote 4 down vote accepted

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.orig/lib/ether.c
++++ 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").

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.