A C Program to display as much information about system as possible

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
anurag_pareek anurag_pareek is offline Offline Jun 28th, 2005, 6:18 am |
0
This Program gives the details (name, kernel, machine type, domain, groups, sizeof data types, etc) of the host it is running on.
Quick reply to this message  
C Syntax
  1. /* hostDetails.c - display as much information about system as possible */
  2.  
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <stdio.h>
  6. #include <sys/utsname.h>
  7. #include <pwd.h>
  8. #include <stdlib.h>
  9.  
  10. #define MAX_DOMAIN_LEN 512
  11. #define MAX_HOST_LEN 512
  12.  
  13. int main(int argc, char *argv[])
  14. {
  15. int counter;
  16.  
  17. /* to be used by uname() */
  18. struct utsname uname_buf;
  19.  
  20. /* to be used by getdomainname() */
  21. char domain[MAX_DOMAIN_LEN];
  22.  
  23. /* to be used by getgroups() */
  24. gid_t *list=NULL;
  25. int num_gid;
  26.  
  27. /* to be used by gethostname() */
  28. char host_buf[MAX_HOST_LEN];
  29.  
  30. /* check all things are provided */
  31. if (argc != 1 )
  32. {
  33. printf("call with no parameter\n usage: maxInfo\n\n");
  34. exit(-1);
  35. }
  36.  
  37. uname(&uname_buf);
  38.  
  39. printf("Result of uname()\n");
  40. printf("sysname = %s\n", uname_buf.sysname);
  41. printf("nodename = %s\n", uname_buf.nodename);
  42. printf("release = %s\n", uname_buf.release);
  43. printf("version = %s\n", uname_buf.version);
  44. printf("machine = %s\n", uname_buf.machine);
  45. printf("\n");
  46.  
  47. printf("Result of getdomainname()\n");
  48. getdomainname(domain, MAX_DOMAIN_LEN);
  49. printf("domain name = %s\n", domain);
  50. printf("\n");
  51.  
  52. printf("Result of getegid()/getgid()\n");
  53. printf("gid = %lu\n", (unsigned long) getgid());
  54. printf("effective gid = %lu\n", (unsigned long) getegid());
  55. printf("\n");
  56.  
  57. printf("Result of getgroups()\n");
  58. num_gid = getgroups(0, list);
  59. list = (gid_t *) malloc (sizeof(gid_t)*num_gid);
  60. num_gid = getgroups(num_gid, list);
  61.  
  62. if (list != NULL)
  63. {
  64. for (counter=0; counter<num_gid; counter++)
  65. {
  66. printf("%lu ", (unsigned long) list[counter]);
  67. }
  68. }
  69.  
  70. printf("\n");
  71. printf("\n");
  72.  
  73. printf("Result of gethostid()/gethostname()\n");
  74. printf("host id = 0x%lx\n", gethostid());
  75. gethostname(host_buf, MAX_HOST_LEN);
  76. printf("host name = %s\n", host_buf);
  77. printf("\n");
  78.  
  79. printf("Result of sizeof() (in bytes)\n");
  80. printf("sizeof(char) = %d\n", sizeof(char));
  81. printf("sizeof(short) = %d\n", sizeof(short));
  82. printf("sizeof(int) = %d\n", sizeof(int));
  83. printf("sizeof(long) = %d\n", sizeof(long));
  84. printf("sizeof(long long) = %d\n", sizeof(long long));
  85. printf("sizeof(float) = %d\n", sizeof(float));
  86. printf("sizeof(double) = %d\n", sizeof(double));
  87. printf("sizeof(long double) = %d\n", sizeof(long double));
  88.  
  89. return 0;
  90. }
  91.  
  92.  
0
bumsfeld bumsfeld is offline Offline | Aug 17th, 2005
The last time I has seen such odd header files, was in one of Herb Schildt's old books.
 
0
bofarull bofarull is offline Offline | Mar 7th, 2006
I'm compiling with the old TC 2.0v and some syntax errors come up, may be because the 'ancient' compiler I'm using.

Bofarull
 
0
maxthrill maxthrill is offline Offline | Apr 4th, 2006
stupid program...does nothing..loads of errors...
 
 

Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC