c code for the MAC Address from an Ethernet Adapter

c code for the MAC Address from an Ethernet Adapter

Post by nkl » Sat, 28 Jun 2003 12:35:33



hi all,

Any experts can help me to get the c ocde that can  retrieve
1) the MAC Address from an Ethernet Adapter, and
2) "Drive Serial Number" from the Harddisk firmware

Thank you very much

 
 
 

c code for the MAC Address from an Ethernet Adapter

Post by Grant Edward » Sat, 28 Jun 2003 12:45:55



> Any experts can help me to get the c ocde that can  retrieve
> 1) the MAC Address from an Ethernet Adapter, and
> 2) "Drive Serial Number" from the Harddisk firmware

Sure sounds like some sort of lame copy-protection scheme, eh?

--
Grant Edwards                   grante             Yow!  I just had a NOSE
                                  at               JOB!!
                               visi.com            

 
 
 

c code for the MAC Address from an Ethernet Adapter

Post by nkl » Sat, 28 Jun 2003 13:04:59


Any code/code-fragments will be helpful.
Thanks,




> > Any experts can help me to get the c ocde that can  retrieve
> > 1) the MAC Address from an Ethernet Adapter, and
> > 2) "Drive Serial Number" from the Harddisk firmware

> Sure sounds like some sort of lame copy-protection scheme, eh?

> --
> Grant Edwards                   grante             Yow!  I just had a NOSE
>                                   at               JOB!!
>                                visi.com

 
 
 

c code for the MAC Address from an Ethernet Adapter

Post by Gary Desrosier » Sat, 28 Jun 2003 13:55:29


#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <net/if.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netdb.h>

int main(int argc,char *argv[])
{
  int r;
  struct protoent *proto;
  int sock;
  struct ifreq ifr;

  if(argc < 2)
  {
    printf("Usage: dumpmac ifname\n");
    exit(1);
  }
  proto = getprotobyname("tcp");
  sock = socket(PF_INET,SOCK_STREAM,proto->p_proto);
  memset(&ifr,0,sizeof(struct ifreq));
  strcpy(ifr.ifr_name,argv[1]);
  r = ioctl(sock,SIOCGIFHWADDR,&ifr);
  if(r != 0)
  {
    printf("Couldn't get mac address\n");
    exit(1);
  }
  printf("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
  (unsigned char)ifr.ifr_hwaddr.sa_data[0],
  (unsigned char)ifr.ifr_hwaddr.sa_data[1],
  (unsigned char)ifr.ifr_hwaddr.sa_data[2],
  (unsigned char)ifr.ifr_hwaddr.sa_data[3],
  (unsigned char)ifr.ifr_hwaddr.sa_data[4],
  (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
  return(0);

Quote:}

Gary.

> Any code/code-fragments will be helpful.
> Thanks,




>> > Any experts can help me to get the c ocde that can  retrieve
>> > 1) the MAC Address from an Ethernet Adapter, and
>> > 2) "Drive Serial Number" from the Harddisk firmware

>> Sure sounds like some sort of lame copy-protection scheme, eh?

>> --
>> Grant Edwards                   grante             Yow!  I just had a
>> NOSE
>>                                   at               JOB!!
>>                                visi.com

 
 
 

1. PXE boot with twin ethernet adapters: which MAC address gets transmitted?

I have two ethernet cards on my machine. If I enable PXE to be able to boot
over the ethenet the machine usually transmits its MAC address and listens
to see if a DHCP server responds, right?

Which one of the two MAC addresses will it be? Does the protocol specify?
Or does it transmit both?

--
Rahul

2. Problems with PC-Linux-connection.

3. Determination of the IP address by a given Ethernet MAC hardware address

4. Irix @ Queens

5. ethernet address vs. MAC address

6. Gated challenges...

7. which physical adaptor's MAC address is exposed after channel bonding?

8. optical mouse for RedHat?

9. Null Hub Adaptor (Was How to Ethernet Two Home Macs)

10. How to get MAC address in my source code?

11. Code to change MAC address in Tru64 4.0f

12. howto obtain mac address in code

13. eth0 mac address(c code)