/*---------------------------------------------------------------------+
| Copyright (c) 1995, SAS Institute Inc. |
| Unpublished - All Rights Reserved |
| S A S / C S A M P L E |
| |
| NAME: GETHNM |
| LANGUAGE: C |
| PURPOSE: This program uses the socket call, gethostname() to |
| return the hostname as defined to the local host. |
| Additional details on this socket function may be |
| found in the SAS/C Library Reference Vol 2, Third |
| Edition, Release 6.00. |
| NOTES: The local host must have an operational TCPIP stack. |
| MVS - |
| COMPILE, LINK, EXECUTE: SUBMIT prefix.SAMPLE.AUX(LC370CLG) |
| NOTES: "prefix" is the SAS/C installation defined high-level |
| qualifier. |
| TSO - |
| COMPILE: LC370 CLIST |
| LINK: CLK370 CLIST |
| EXECUTE: CALL 'your.load.lib(GETHNM)' |
| CMS - |
| COMPILE: LC370 |
| LINK: CLINK GETHNM (GENMOD |
| EXECUTE: GETHNM |
+---------------------------------------------------------------------*/
#include <stdlib.h>
#include <netdb.h>
#include <stdio.h>
main()
{
char buf[128];
/*---------------------------------------------------------------------+
| gethostname returns the hostname in the "buf" array. If gethostname()|
| succeeds it returns a "0", otherwise a "-1" and errno is set |
| accordingly. |
+---------------------------------------------------------------------*/
if (gethostname(buf,sizeof(buf)))
{
perror("Can't retrive host name");
return EXIT_FAILURE;
}
printf("%s\n",buf);
return EXIT_SUCCESS;
}
|