1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
/*
* system.c - system commands
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef sun386
#include <sys/utsname.h>
#endif
#define UNKNOWN "unknown"
/*
* Get the hostname
*/
void CNget_hostname(hostname, maxlen)
char *hostname;
int maxlen;
{
/*
* If gethostname() is not available on your system, then
* change the "ifdef" in the define below to "ifndef", i.e.
* #ifdef NO_GETHOSTNAME
* becomes
* #ifndef NO_GETHOSTNAME
*/
#ifdef NO_GETHOSTNAME
struct utsname name;
if (uname(&name) >= 0) {
/* Architecture */
(void) strcpy(hostname,name.nodename);
} else {
(void) strcpy(hostname,UNKNOWN);
}
#else
if (gethostname(hostname, maxlen) < 0)
(void) strcpy(hostname, UNKNOWN);
#endif
}
/*
* Get the system/architecture
*/
void CNget_sysname(sysname)
char *sysname;
{
#ifndef sun386
struct utsname name;
if (uname(&name) >= 0) {
/* Architecture */
(void) strcpy(sysname,name.sysname);
} else {
(void) strcpy(sysname,UNKNOWN);
}
#endif
#ifdef sun386
/* machine/architecture */
(void) strcpy(sysname, "sun386");
#endif
}
|