2

Linux : uname -a :2.6.18 as well as 2.6.39

I am very new in it... When the driver is first loaded, before ifconfig can change the MAC address, the existing (permanent) MAC address is stored away, able to be retrieved via this ioctl.

case ETHTOOL_GPERMADDR:
rc = ethtool_get_perm_addr(dev, useraddr);
break;

anyone has tested it ? Can I get code or a part of a code to implement it ?

Jatin Bodarya
  • 1,425
  • 2
  • 20
  • 32

1 Answers1

1

Invoke it like this:

# ethtool -P eth0

From the ethtool source (ethtool.c from package ethtool-debugsource-3.2-3.1.2.x86_64):

static int do_permaddr(struct cmd_context *ctx)
{
        int i, err;
        struct ethtool_perm_addr *epaddr;

        epaddr = malloc(sizeof(struct ethtool_perm_addr) + MAX_ADDR_LEN);
        epaddr->cmd = ETHTOOL_GPERMADDR;
        epaddr->size = MAX_ADDR_LEN;

        err = send_ioctl(ctx, epaddr);
        if (err < 0)
                perror("Cannot read permanent address");
        else {
                printf("Permanent address:");
                for (i = 0; i < epaddr->size; i++)
                        printf("%c%02x", (i == 0) ? ' ' : ':',
                               epaddr->data[i]);
                printf("\n");
        }
        free(epaddr);

        return err;
}
Peter L.
  • 1,041
  • 2
  • 22
  • 26
  • It hardly depends on your type of NIC . and the ethtool code is not a suitable for that. as It won't work in many devices – Jatin Bodarya Feb 23 '13 at 05:31