//------------------------------------------------------------------- // utsinfo.c // // This module creates a pseudo-file (named '/proc/utsinfo') // which prints information held within the 'system_utsname' // kernel data-structure, including the hostname of the node // that is executing this module's 'get_info()' function. // // NOTE: Written and tested with Linux kernel version 2.6.10 // // programmer: ALLAN CRUSE // written on: 25 MAR 2005 //------------------------------------------------------------------- #include // for init_module() #include // for create_proc_read_entry() #include // for 'system_utsname' object char modname[] = "utsinfo"; int my_get_info( char *buf, char **start, off_t off, int count ) { int len = 0; len += sprintf( buf+len, "\nDisplaying information from the " ); len += sprintf( buf+len, "\'system_utsname\' data-structure\n\n" ); len += sprintf( buf+len, "sysname: %s\n", system_utsname.sysname ); len += sprintf( buf+len, "nodename: %s\n", system_utsname.nodename ); len += sprintf( buf+len, "release: %s\n", system_utsname.release ); len += sprintf( buf+len, "version: %s\n", system_utsname.version ); len += sprintf( buf+len, "machine: %s\n", system_utsname.machine ); len += sprintf( buf+len, "domainname: %s", system_utsname.domainname ); len += sprintf( buf+len, "\n\n" ); return len; } int init_module( void ) { printk( "<1>\nInstalling \'%s\' module\n", modname ); create_proc_info_entry( modname, 0, NULL, my_get_info ); return 0; // SUCCESS } void cleanup_module( void ) { remove_proc_entry( modname, NULL ); printk( "<1>Removing \'%s\' module\n", modname ); } MODULE_LICENSE("GPL");