2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <sys/param.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
27 #define PRECISION -7 /* HZ == 100 */
30 #define PRECISION -6 /* HZ == 50 */
33 #define PRECISION -6 /* HZ == 64 */
36 #define PRECISION -3 /* HZ == 10 */
48 static struct server dcn5 = { "dcn5.udel.edu", "128.4.0.5" };
49 static struct server wwvb = { "wwvb.isi.edu", "128.9.2.129" };
50 static struct server sdsc = { "sdsc-fuzz.nsf.net", "192.12.207.1" };
51 static struct server umd1 = { "umd1.umd.edu", "128.8.10.1" };
57 static struct server papaya = { "papaya.srv.cs.cmu.edu", "128.2.222.199" };
58 static struct server guava = { "guava.srv.cs.cmu.edu", "128.2.250.187" };
59 static struct server cluster1 =
60 { "cluster1.fs.andrew.cmu.edu", "128.2.249.123" };
64 static char *headers1[] = {
66 " DO NOT EDIT THIS FILE MANUALLY. It is maintained by mkntpconf.",
68 " Local clock parameters",
70 " Precision of the local clock to the nearest power of 2",
78 static char *headers2[] = {
85 extern char *mktemp();
93 register char *p, **v;
95 char hostname[MAXHOSTNAMELEN + 1];
96 char tempfn[MAXPATHLEN + 1], config[MAXPATHLEN + 1];
100 name = (ac > 0) ? (ac--, *av++) : (ac = 0, "mkntpconf");
101 (void)strcpy(tempfn, name);
102 if ((p = strrchr(tempfn, '/')) == 0)
107 (void)strcpy(config, tempfn);
108 (void)strcat(config, "ntp.conf");
109 (void)strcat(tempfn, "ntp.XXXXXX");
110 (void)mktemp(tempfn);
111 if (gethostname(hostname, MAXHOSTNAMELEN) == -1) {
112 perror("gethostname");
115 hostname[MAXHOSTNAMELEN] = 0;
116 for (p = hostname; *p; p++)
119 if ((f = fopen(tempfn, "w")) == NULL) {
124 for (v = headers1; *v; v++)
125 fprintf(f, "#%s\n", *v);
126 fprintf(f, "precision %d\n", PRECISION);
127 for (v = headers2; *v; v++)
128 fprintf(f, "#%s\n", *v);
129 if (strcmp(hostname, papaya.s_name) == 0
130 || strcmp(hostname, guava.s_name) == 0) {
131 if (strcmp(hostname, papaya.s_name) == 0) {
140 peerline(cluster1, f);
142 if ((p = strchr(hostname, '.')) != 0
143 && strcmp(p + 1, "srv.cs.cmu.edu") == 0) {
149 if ((g = fopen("/etc/attributes", "r")) != NULL) {
150 while (fgets(line, sizeof(line), g) != NULL) {
151 if ((p = strchr(line, ':')) != 0)
153 if (strcmp(line, papaya.s_name) == 0
154 || strcmp(line, guava.s_name) == 0)
156 if ((p = strchr(line, '.')) == 0
157 || strcmp(p + 1, "srv.cs.cmu.edu") != 0)
166 if (rename(tempfn, config) == -1) {
170 if (chmod(config, 0644) == -1) {
183 register struct hostent *hp;
186 if ((hp = gethostbyname(s.s_name)) != 0 && hp->h_addrtype == AF_INET)
187 fprintf(f, "%-15.15s # %s", inet_ntoa(*(struct in_addr *)hp->h_addr),
190 fprintf(f, "%-15.15s # %s", s.s_addr, s.s_name);
192 fprintf(f, "%s", s.s_name);
193 (void)fputc('\n', f);