1: /*
   2:  * hostname - get (or set) hostname
   3:  */
   4: 
   5: #include    <stdio.h>
   6: #include    <sys/types.h>
   7: 
   8: char hostname[32];
   9: extern int errno;
  10: 
  11: main(argc, argv)
  12: char    *argv[];
  13: {
  14:     int myerrno;
  15: 
  16:     argc--;
  17:     argv++;
  18:     if (argc) {
  19:         if (sethostname(*argv))
  20:             perror("sethostname");
  21:         myerrno = errno;
  22:     }
  23:     else    {
  24:         gethostname(hostname, sizeof(hostname));
  25:         myerrno = errno;
  26:         printf("%s\n", hostname);
  27:     }
  28:     exit(myerrno);
  29: }
  30: 
  31: sethostname(s)
  32: char *s;
  33: {
  34:     FILE    *fopen();
  35:     register FILE   *fp;
  36: 
  37:     if ((fp = fopen("/etc/localhostname", "w")) != (FILE *) NULL) {
  38:         fprintf(fp, "%s\n", s);
  39:         fclose(fp);
  40:         (void) chmod("/etc/localhostname", 0644);
  41:         if (ferror(fp))
  42:             return(-1);
  43:         else
  44:             return(0);
  45:     }
  46:     else
  47:         return(-1);
  48: }

Defined functions

main defined in line 11; never used
sethostname defined in line 31; used 1 times
  • in line 19

Defined variables

hostname defined in line 8; used 3 times
Last modified: 1983-05-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 715
Valid CSS Valid XHTML 1.0 Strict