Reading hard disk, cpu serial number

Hello fellows,
I want to get the serial number of my hard disk and cpu using a C/C++ on "Linux platform". I am using redhat 9, I know I can get the hard disk serial number using command "hdparm" and cpu serial number using command /proc/cpuinfo, but how can i be able to get using C/C++ program.

help plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

Majid
[391 byte] By [majidikhan] at [2007-11-19 22:05:18]
# 1 Re: Reading hard disk, cpu serial number
How about executing a command in the console (from your program that is) for that info and then storing it in a string object, then you can do whatever you want with that data.
YourSurrogateGod at 2007-11-9 1:03:01 >
# 2 Re: Reading hard disk, cpu serial number
This is the way to find out the hard disk serial number using C code

/*
* didkinfo.c
* It gets the hard disk information in this case serial no.
* It uses ioctl() system call
*/

#include <linux/types.h>
#include <linux/hdreg.h>
#include <linux/fcntl.h>

int main()
{
int fd,err,i;

/* structure to get disk information and
* returned by HDIO_GET_IDENTITY, as per ANSI ATA2 rev.2f spec
*/
struct hd_driveid hd;

/* open the device */
if( (fd=open("/dev/hda", O_RDONLY ) ) < 0 )
perror("Device Open Error");

/* get required info */

if( (err = ioctl(fd,HDIO_GET_IDENTITY,&hd) ) < 0)
perror("IOCTL err");
else
printf("Serial No = %s\n",hd.serial_no);

return (0);
}
majidikhan at 2007-11-9 1:04:01 >