home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3321 / gethostname.c next >
Encoding:
C/C++ Source or Header  |  1991-05-12  |  769 b   |  25 lines

  1. /* gethostname() for SysV -- by Donald Burr
  2.    Uses uname() and returns the system's UUCP nodename for a hostname
  3.    A quick hack I did for locktty */
  4.  
  5. #include <sys/utsname.h>    /* #include for uname() call */
  6. #include <string.h>        /* String routines strcpy() */
  7.  
  8. int gethostname(hostname, somenumber)
  9.  
  10. char    *hostname[];        /* Where the hostname will be returned */
  11. int    somenumber;        /* Haven't figured out what this is */
  12.  
  13. {
  14.     struct utsname name;    /* uname returns the sysname here */
  15. /* had an asterisk */
  16.     if ((uname(&name)) == -1)    /* did it fail? */
  17.         return -1;        /* failed, so return a failure */
  18.     else {
  19.         strcpy(hostname, name.nodename);
  20.                     /* return the nodename */
  21.         return 1;  }        /* successfull completion */
  22.  
  23.     return -1;        /* something must be wrong... exit */
  24. }
  25.