User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 402,507 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,821 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Jun 28th, 2005
Views: 2,000
This Program gives the details (name, kernel, machine type, domain, groups, sizeof data types, etc) of the host it is running on.
c Syntax | 3 stars
  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 (Newest First)
maxthrill | Newbie Poster | Apr 4th, 2006
stupid program...does nothing..loads of errors...
bofarull | Newbie Poster | 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
bumsfeld | Posting Shark | Aug 17th, 2005
The last time I has seen such odd header files, was in one of Herb Schildt's old books.
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 5:51 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC