Link to home
Start Free TrialLog in
Avatar of sandy_wu
sandy_wu

asked on

How can I get a MAC address and Harddisk serial number in c under linux?

I want to write a programmer in c, it can get network card MAC address, and harddisk serial number, How can I do? show me a example is best!
Avatar of bryanh
bryanh

I don't have an example handy, or the time to write one, but let me get you started:

You can get the network card MAC address with a SIOCGIFHWADDR ioctl to any internet socket.  The program 'ifconfig' is a good example of this.  You can get the hard disk serial number, if it is an ATA disk, with a HDIO_GET_IDENTITY ioctl.  The program 'hdparm' is a good example of this.

A more modern and possibly easier way to get the disk serial number is from the file /proc/ide/hda/identity, where it is an ASCII string starting with the 20th byte.

Of course, you might also just call Ifconfig and Hdparm, especially if you can use a high level language instead of C.
Avatar of sandy_wu

ASKER

Hello bryanh:

   thank U! please tell me where can i find "hdparm" and "ifconfig", are they c source code?
   In /proc/ide/hda/identity, how much bytes should the serial have?

   thanks very much!

   
   
Hello bryanh:

   thank U! please tell me where can i find "hdparm" and "ifconfig", are they c source code?
   In /proc/ide/hda/identity, how much bytes should the serial have?

   thanks very much!

   
   
Hello bryanh:

I have used the "hdparm -I /dev/hda1", but the serial result seem not equal to the bytes in proc/ide/hda/identity, why?  

thanks again!
ASKER CERTIFIED SOLUTION
Avatar of bryanh
bryanh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank U bryanh:
   Although I cant get into www.freshmeat.com, But i still thank you very much!