0

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;
}

4
Contributors
3
Replies
4
Views
12 Years
Discussion Span
Last Post by maxthrill
0

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

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.