944,192 Members | Top Members by Rank

Ad:
  • C Code Snippet
  • Views: 2945
  • C RSS
0

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

by on Jun 28th, 2005
This Program gives the details (name, kernel, machine type, domain, groups, sizeof data types, etc) of the host it is running on.
C Code Snippet (Toggle Plain Text)
  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.  
Comments on this Code Snippet
Aug 17th, 2005
0

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

The last time I has seen such odd header files, was in one of Herb Schildt's old books.
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005
Mar 7th, 2006
0

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

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
Newbie Poster
bofarull is offline Offline
9 posts
since Mar 2006
Apr 4th, 2006
0

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

stupid program...does nothing..loads of errors...
Newbie Poster
maxthrill is offline Offline
1 posts
since Mar 2006
Message:
Previous Thread in C Forum Timeline: input bianary ASCII converted into Characters
Next Thread in C Forum Timeline: Need Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC