|
|
1.1 ! root 1: /* gethostname.c ! 2: ! 3: Get hostname and domainname from the files which define them ! 4: in /etc. ! 5: by La Monte H. Yarroll ([email protected]) ! 6: Copyright (c) 1991 by Mark Williams Company ! 7: Permission to use and redistribute is granted, provided the ! 8: above copyright notice appears on all copies. ! 9: */ ! 10: ! 11: #include <stdio.h> ! 12: #include "cron.h" ! 13: ! 14: FILE *fopen(); ! 15: ! 16: #define ETC_HOSTNAME "/etc/uucpname" ! 17: #define ETC_DOMAIN "/etc/domain" ! 18: #define NIL ((unsigned char) NULL) ! 19: ! 20: int gethostname(name, bufsize) ! 21: unsigned char *name; /* Host name */ ! 22: int bufsize; /* Maximum size of the host name */ ! 23: { ! 24: int i; ! 25: FILE *fp; ! 26: ! 27: if ( (fp = fopen(ETC_HOSTNAME, "r")) == NULL ) { ! 28: Dprint("gethostname: Can't open %s.\n", ETC_HOSTNAME); ! 29: return (-1); ! 30: } ! 31: ! 32: fgets(name, bufsize, fp); ! 33: fclose(fp); ! 34: ! 35: /* Truncate at first newline. */ ! 36: for (i = 0; ! 37: (i < bufsize) && (name[i] != NIL) && (name[i] != '\n'); ! 38: ++i ) { ! 39: } ! 40: ! 41: if (i >= bufsize) { ! 42: Dprint("gethostname: %s\n", ! 43: "Found neither a NULL nor a newline."); ! 44: return (-1); ! 45: } else { ! 46: name[i] = NIL; ! 47: } ! 48: return (0); ! 49: } ! 50: ! 51: int getdomain(name, bufsize) ! 52: unsigned char *name; /* Domain name */ ! 53: int bufsize; /* Maximum size of the domain name */ ! 54: { ! 55: int i; ! 56: FILE *fp; ! 57: ! 58: if ( (fp = fopen(ETC_DOMAIN, "r")) == NULL ) { ! 59: Dprint("getdomainname: Can't open %s.\n", ETC_DOMAIN); ! 60: return (-1); ! 61: } ! 62: ! 63: fgets(name, bufsize, fp); ! 64: fclose(fp); ! 65: ! 66: /* Truncate at first newline. */ ! 67: for (i = 0; ! 68: (i < bufsize) && (name[i] != NIL) && (name[i] != '\n'); ! 69: ++i ) { ! 70: } ! 71: ! 72: if (i >= bufsize) { ! 73: Dprint("getdomain: %s\n", ! 74: "Found neither a NULL nor a newline."); ! 75: return (-1); ! 76: } else { ! 77: name[i] = NIL; ! 78: } ! 79: return (0); ! 80: } ! 81:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.