Annotation of researchv10no/lbin/mailx/hostname.c, revision 1.1.1.1

1.1       root        1: #ident "@(#)hostname.c 1.3 'attmail mail(1) command'"
                      2: #ident "@(#)mailx:hostname.c   1.3.1.1"
                      3: /*     Copyright (c) 1984 AT&T */
                      4: /*       All Rights Reserved   */
                      5: 
                      6: /*     THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T     */
                      7: /*     The copyright notice above does not evidence any        */
                      8: /*     actual or intended publication of such source code.     */
                      9: 
                     10: #ident "@(#)mailx:hostname.c   1.3"
                     11: /*
                     12:  * mailx -- a modified version of a University of California at Berkeley
                     13:  *     mail program
                     14:  *
                     15:  * Code to figure out what host we are on.
                     16:  */
                     17: 
                     18: #include "rcv.h"
                     19: #include "configdefs.h"
                     20: 
                     21: #ifdef preSVr4
                     22: # define       MAILCNFG        "/usr/lib/mail/mailcnfg"
                     23: #else
                     24: # define       MAILCNFG        "/etc/mail/mailcnfg"
                     25: # include "maillock.h"
                     26: # include <sys/utsname.h>
                     27: #endif
                     28: 
                     29: 
                     30: char host[64];
                     31: char domain[128];
                     32: /*
                     33:  * Initialize the network name of the current host.
                     34:  */
                     35: void
                     36: inithost()
                     37: {
                     38:        register struct netmach *np;
                     39: #ifdef GATEWAY
                     40:        FILE *fp;                                                       /* adb */
                     41: 
                     42:        if (fp = fopen(GATEWAY, "r")) {                                 /* adb */
                     43:                fgets(host, sizeof host, fp);                           /* adb */
                     44:                host[strlen(host)-1] = 0;                               /* adb */
                     45:                fclose(fp);                                             /* adb */
                     46:        } else {                                                        /* adb */
                     47:                getuname(host, sizeof host);                            /* adb */
                     48:        }
                     49: #else
                     50:        struct utsname name;
                     51:        char *fp;
                     52:        extern char *xgetenv();
                     53:        extern int  xsetenv();
                     54: 
                     55:        xsetenv(MAILCNFG);
                     56:        if (fp = xgetenv("CLUSTER")) {
                     57:                strncpy(host, fp, sizeof(host));
                     58:        } else {
                     59:                uname(&name);
                     60:                strncpy(host, name.nodename, sizeof host);
                     61:        }
                     62: #endif
                     63:        strcpy(domain, host);
                     64:        strcat(domain, maildomain());
                     65:        for (np = netmach; np->nt_machine != 0; np++)
                     66:                if (strcmp(np->nt_machine, EMPTY) == 0)
                     67:                        break;
                     68:        if (np->nt_machine == 0) {
                     69:                printf("Cannot find empty slot for dynamic host entry\n");
                     70:                exit(1);
                     71:        }
                     72:        np->nt_machine = host;
                     73:        np++;
                     74:        np->nt_machine = domain;
                     75:        if (debug) fprintf(stderr, "host '%s', domain '%s'\n", host, domain);
                     76: }
                     77: 
                     78: #ifdef WHOAMI
                     79: getuname(sys,length)
                     80: char *sys;
                     81: int length;
                     82: {
                     83:        FILE *fp;
                     84: 
                     85:        if (fp = fopen(WHOAMI, "r")) {
                     86:                fgets(sys, length, fp);
                     87:                sys[strlen(sys)-1] = 0;
                     88:                fclose(fp);
                     89:        } else {
                     90:                strcpy(sys,"????");
                     91:        }
                     92: }
                     93: #else
                     94: #include <sys/utsname.h>
                     95: char *
                     96: getuname(sys,length)
                     97: char *sys;
                     98: int length;
                     99: {
                    100:        struct utsname name;
                    101:        uname(&name);
                    102:        strncpy(sys, getuname(), length);
                    103:        return;
                    104: }
                    105: #endif /* WHOAMI */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.