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>
15 #include <sys/param.h>
16 #include <sys/socket.h>
17 #include <netinet/in.h>
18 #include <arpa/inet.h>
26 #define PRECISION -7 /* HZ == 100 */
29 #define PRECISION -6 /* HZ == 50 */
32 #define PRECISION -6 /* HZ == 64 */
35 #define PRECISION -3 /* HZ == 10 */
47 static struct server dcn5 = { "dcn5.udel.edu", "128.4.0.5" };
48 static struct server wwvb = { "wwvb.isi.edu", "128.9.2.129" };
49 static struct server sdsc = { "sdsc-fuzz.nsf.net","192.12.207.1" };
50 static struct server umd1 = { "umd1.umd.edu", "128.8.10.1" };
56 static struct server papaya = { "papaya.srv.cs.cmu.edu", "128.2.222.199" };
57 static struct server guava = { "guava.srv.cs.cmu.edu", "128.2.250.187" };
58 static struct server cluster1 = { "cluster1.fs.andrew.cmu.edu", "128.2.249.123" };
62 static char *headers1[] = {
64 " DO NOT EDIT THIS FILE MANUALLY. It is maintained by mkntpconf.",
66 " Local clock parameters",
68 " Precision of the local clock to the nearest power of 2",
76 static char *headers2[] = {
83 extern char *mktemp();
91 register char *p, **v;
93 char hostname[MAXHOSTNAMELEN+1];
94 char tempfn[MAXPATHLEN+1], config[MAXPATHLEN+1];
98 name = (ac > 0) ? (ac--, *av++) : (ac = 0, "mkntpconf");
99 (void) strcpy(tempfn, name);
100 if ((p = strrchr(tempfn, '/')) == 0)
105 (void) strcpy(config, tempfn);
106 (void) strcat(config, "ntp.conf");
107 (void) strcat(tempfn, "ntp.XXXXXX");
108 (void) mktemp(tempfn);
109 if (gethostname(hostname, MAXHOSTNAMELEN) == -1) {
110 perror("gethostname");
113 hostname[MAXHOSTNAMELEN] = 0;
114 for (p = hostname; *p; p++)
117 if ((f = fopen(tempfn, "w")) == NULL) {
122 for (v = headers1; *v; v++)
123 fprintf(f, "#%s\n", *v);
124 fprintf(f, "precision %d\n", PRECISION);
125 for (v = headers2; *v; v++)
126 fprintf(f, "#%s\n", *v);
127 if (strcmp(hostname, papaya.s_name) == 0
128 || strcmp(hostname, guava.s_name) == 0) {
129 if (strcmp(hostname, papaya.s_name) == 0) {
138 peerline(cluster1, f);
140 if ((p = strchr(hostname, '.')) != 0
141 && strcmp(p+1, "srv.cs.cmu.edu") == 0) {
147 if ((g = fopen("/etc/attributes", "r")) != NULL) {
148 while (fgets(line, sizeof(line), g) != NULL) {
149 if ((p = strchr(line, ':')) != 0)
151 if (strcmp(line, papaya.s_name) == 0
152 || strcmp(line, guava.s_name) == 0)
154 if ((p = strchr(line, '.')) == 0
155 || strcmp(p+1, "srv.cs.cmu.edu") != 0)
164 if (rename(tempfn, config) == -1) {
168 if (chmod(config, 0644) == -1) {
181 register struct hostent *hp;
184 if ((hp = gethostbyname(s.s_name)) != 0 && hp->h_addrtype == AF_INET)
185 fprintf(f, "%-15.15s # %s",
186 inet_ntoa(* (struct in_addr *) hp->h_addr),
189 fprintf(f, "%-15.15s # %s", s.s_addr, s.s_name);
191 fprintf(f, "%s", s.s_name);
192 (void) fputc('\n', f);