954,479 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

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

0
By anurag_pareek on Jun 28th, 2005 3:18 pm

This Program gives the details (name, kernel, machine type, domain, groups, sizeof data types, etc) of the host it is running on.

/* hostDetails.c - display as much information about system as possible */

#include <unistd.h> 
#include <sys/types.h> 
#include <stdio.h>
#include <sys/utsname.h> 
#include <pwd.h>
#include <stdlib.h>

#define MAX_DOMAIN_LEN 512
#define MAX_HOST_LEN   512

int main(int argc, char *argv[])
{
        int    counter;

        /* to be used by uname() */
        struct utsname uname_buf;

        /* to be used by getdomainname() */
        char   domain[MAX_DOMAIN_LEN];
        
        /* to be used by getgroups() */
        gid_t  *list=NULL;
        int    num_gid;

        /* to be used by gethostname() */
        char   host_buf[MAX_HOST_LEN];

        /* check all things are provided */
        if (argc != 1 )
        {
                printf("call with no parameter\n  usage: maxInfo\n\n");
                exit(-1);
        }

        uname(&uname_buf);

        printf("Result of uname()\n"); 
        printf("sysname  = %s\n", uname_buf.sysname); 
        printf("nodename = %s\n", uname_buf.nodename); 
        printf("release  = %s\n", uname_buf.release); 
        printf("version  = %s\n", uname_buf.version); 
        printf("machine  = %s\n", uname_buf.machine); 
        printf("\n"); 

        printf("Result of getdomainname()\n"); 
        getdomainname(domain, MAX_DOMAIN_LEN);
        printf("domain name  = %s\n", domain); 
        printf("\n"); 

        printf("Result of getegid()/getgid()\n"); 
        printf("gid           = %lu\n", (unsigned long) getgid()); 
        printf("effective gid = %lu\n", (unsigned long) getegid()); 
        printf("\n"); 

        printf("Result of getgroups()\n"); 
        num_gid = getgroups(0, list); 
        list = (gid_t *) malloc (sizeof(gid_t)*num_gid);
        num_gid = getgroups(num_gid, list); 

        if (list != NULL)
        {
        	for (counter=0; counter<num_gid; counter++)
        	{
        		printf("%lu ", (unsigned long) list[counter]); 
        	}
        }

        printf("\n"); 
        printf("\n"); 

        printf("Result of gethostid()/gethostname()\n"); 
        printf("host id       = 0x%lx\n", gethostid());
        gethostname(host_buf, MAX_HOST_LEN);
        printf("host name     = %s\n", host_buf);
        printf("\n"); 

        printf("Result of sizeof() (in bytes)\n"); 
        printf("sizeof(char)        = %d\n", sizeof(char)); 
        printf("sizeof(short)       = %d\n", sizeof(short)); 
        printf("sizeof(int)         = %d\n", sizeof(int)); 
        printf("sizeof(long)        = %d\n", sizeof(long)); 
        printf("sizeof(long long)   = %d\n", sizeof(long long)); 
        printf("sizeof(float)       = %d\n", sizeof(float)); 
        printf("sizeof(double)      = %d\n", sizeof(double)); 
        printf("sizeof(long double) = %d\n", sizeof(long double)); 

        return 0;
}

The last time I has seen such odd header files, was in one of Herb Schildt's old books.

bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
 

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

bofarull
Newbie Poster
9 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

stupid program...does nothing..loads of errors...

maxthrill
Newbie Poster
1 post since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You