#include /* system services */ #include /* error numbers and codes */ #include /* vms descriptors */ #include /* logical names defs */ #include /* processor status fields */ #define MAXHOSTNAMELEN 64 /* maximum host name length */ #define TABLE_NAME "LNM$SYSTEM_TABLE" #define LOGICAL_NAME "ARPANET_HOST_NAME" /* Wollongong */ static char hostname[MAXHOSTNAMELEN]; /* local buffer */ #ifndef min(a,b) #define min(a,b) ((a-b > 0) ? b : a) #endif /* min */ int gethostname(name, namelen) char *name; int namelen; { short hostnamel; int rc; unsigned long attr; struct dsc$descriptor tabnam; struct dsc$descriptor lognam; unsigned char acmode; struct { unsigned short len; unsigned short code; char *bufaddr; unsigned short *retlen; int eoi; } itemlist = { sizeof(hostname), LNM$_STRING , hostname, &hostnamel, 0 }; attr = LNM$M_CASE_BLIND; tabnam.dsc$w_length = strlen(TABLE_NAME); tabnam.dsc$a_pointer = TABLE_NAME; tabnam.dsc$b_class = DSC$K_CLASS_S; tabnam.dsc$b_dtype = DSC$K_DTYPE_T; lognam.dsc$w_length = strlen(LOGICAL_NAME); lognam.dsc$a_pointer = LOGICAL_NAME; lognam.dsc$b_class = DSC$K_CLASS_S; lognam.dsc$b_dtype = DSC$K_DTYPE_T; acmode = PSL$C_USER; rc = sys$trnlnm(&attr, &tabnam, &lognam, &acmode, &itemlist); if (!(rc & 0x01)) { vaxc$errno = rc; errno = EVMSERR; return(-1); } else { strncpy(name,hostname,min(namelen,hostnamel)); name[min(namelen,hostnamel)] ='\0'; return (0); } } #if defined(DEBUG) && defined(MAIN) #include /* standard input/output defs. */ main() { char name[MAXHOSTNAMELEN]; if (gethostname(name,sizeof(name))) { fprintf(stdout,"Unable to get hostname\n"); perror("hostname"); } else { fprintf(stdout,"Hostname: <%s>\n",hostname); } } #endif /* DEBUG && MAIN */