uname 0.1

uname is a special version of uname.
uname is a special version of uname. Supports -a, -s, -r, -n, -v, -m options.

USAGE: uname [options]

-s Print the kernel name
-v Print the kernel version
-r Print the kernel release
-n Print the network node hostname
-m Print the machine hardware name
-a Print all of the above

Without options, uname acts like uname -s

Sample:

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

void print_usage(void);

int main( int argc, char *argv[] )
{
int c;
extern char *optarg;
extern int optind, optopt;
int a_flag = 0, s_flag = 0, n_flag = 0, r_flag = 0, v_flag = 0,
m_flag = 0;
int errflag=0;
char host[256];
struct utsname uts;

if ( gethostname( host, 255 ) != 0 || uname( &uts ) < 0 )
{
fprintf( stderr, "Unable to get host informationn" );
exit( 1 );
}

/* if no options, then just print sysname */
if ( argc == 1 ) {
s_flag = 1;
}
else
{
while ( ( c = getopt( argc, argv, "asnrvm" ) ) != -1 )
{
switch ( c ) {
case 'a':
a_flag = 1;
break;
case 's':
s_flag = 1;
break;
case 'n':
n_flag = 1;
break;
case 'r':
r_flag = 1;
break;
case 'v':
v_flag = 1;
break;
case 'm':
m_flag = 1;
break;
case '?':
errflag++;
break;
}
}
}

/* Must have been one or more erroneous options passed -
print usage info and exit */
if ( errflag != 0 )
{
print_usage();
exit( 1 );
}

char *sysname, *machine, *nodename, *release, *version;

sysname=uts.sysname;
machine=uts.machine;
nodename=uts.nodename;
release=uts.release;
version=uts.version;

if ( a_flag == 1 ) {
printf( "%s %s %s %s %sn", sysname, nodename, release, version,
machine );
}
else
{
char *printstring;
/* allocate enough space for all eventualities....*/
printstring = (char *)malloc(strlen(sysname)+
strlen(version)+
strlen(release)+
strlen(nodename)+
strlen(machine)+6);
strcpy( printstring , "");

if ( s_flag == 1 ) {
strcat( printstring, sysname );
strcat( printstring, " ");
}
if ( n_flag == 1 ) {
strcat( printstring, nodename );
strcat( printstring, " ");
}
if ( r_flag == 1 ) {
strcat( printstring, release );
strcat( printstring, " ");
}
if ( v_flag == 1 ) {
strcat( printstring, version );
strcat( printstring, " ");
}
if ( m_flag == 1 ) {
strcat( printstring, machine );
strcat( printstring, " ");
}
puts( printstring );
free( printstring );
}
return 0;
}

void print_usage(void)
{
char *usage[] = { "uname - (C) 2004 Kevin Waldron",
"Distributed under the terms of the GNU General Public Licence",
"USAGE:", "uname [options]",
" -s Print the kernel name",
" -v Print the kernel version",
" -r Print the kernel release",
" -n Print the network node hostname",
" -m Print the machine hardware name",
" -a Print all of the above",
" ", "Without options, uname acts like uname -s" };

int i = 0;
for ( i = 0 ; i < 12 ; i++ )
{
printf( "%sn", *(usage+i) );
}
}

last updated on:
March 13th, 2007, 16:18 GMT
price:
FREE!
developed by:
Kevin Waldron
homepage:
www.zazzybob.com
license type:
GPL (GNU General Public License) 
category:
ROOT \ Utilities

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Rate it!

Add your review!

SUBMIT