|
|
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:
13: FILE *fopen();
14:
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;
22: int bufsize;
23: {
24: int i;
25: FILE *fp;
26:
27: if ( (fp = fopen(ETC_HOSTNAME, "r")) == NULL ) {
28: #ifdef DEBUG
29: fprintf(stderr, "gethostname: Can't open %s.\n", ETC_HOSTNAME);
30: #endif
31: return (-1);
32: }
33:
34: fgets(name, bufsize, fp);
35: fclose(fp);
36:
37: /* Truncate at first newline. */
38: for (i = 0;
39: (i < bufsize) && (name[i] != NIL) && (name[i] != '\n');
40: ++i ) {
41: }
42:
43: if (i >= bufsize) {
44: #ifdef DEBUG
45: fprintf(stderr,
46: "gethostname: Found neither a NULL nor a newline.\n");
47: #endif
48: return (-1);
49: } else {
50: name[i] = NIL;
51: }
52: return (0);
53: }
54:
55: int getdomain(name, bufsize)
56: unsigned char *name;
57: int bufsize;
58: {
59: int i;
60: FILE *fp;
61:
62: if ( (fp = fopen(ETC_DOMAIN, "r")) == NULL ) {
63: #ifdef DEBUG
64: fprintf(stderr, "getdomainname: Can't open %s.\n", ETC_DOMAIN);
65: #endif
66: return (-1);
67: }
68:
69: fgets(name, bufsize, fp);
70: fclose(fp);
71:
72: /* Truncate at first newline. */
73: for (i = 0;
74: (i < bufsize) && (name[i] != NIL) && (name[i] != '\n');
75: ++i ) {
76: }
77:
78: if (i >= bufsize) {
79: #ifdef DEBUG
80: fprintf(stderr,
81: "getdomain: Found neither a NULL nor a newline.\n");
82: #endif
83: return (-1);
84: } else {
85: name[i] = NIL;
86: }
87: return (0);
88: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.