3 * This generates the network table.
5 * (c) Copyright 1994 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
13 #include <sys/types.h>
16 #include <netinet/in.h>
18 EXEC SQL INCLUDE sqlca;
21 char *whoami = "network.gen";
22 char *db = "moira/moira";
29 char *outf = NULL, outft[64], *p, buf[256];
34 EXEC SQL BEGIN DECLARE SECTION;
36 char name[65], description[65];
37 EXEC SQL END DECLARE SECTION;
42 if (stat(argv[1], &sb) == 0) {
43 if (ModDiff(&flag1, "subnet", sb.st_mtime))
46 fprintf(stderr, "File %s does not need to be rebuilt.\n",
52 sprintf(outft, "%s~", outf);
53 if ((out = fopen(outft, "w")) == NULL) {
54 fprintf(stderr, "unable to open %s for output\n", outf);
57 } else if (argc != 1) {
58 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
64 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
66 gettimeofday(&now, NULL);
68 fprintf(out, "; MIT Network Table\n;\n");
69 fprintf(out, "; \t%cAuthor: $\n", '$');
70 fprintf(out, "; \t%cDate: $\n", '$');
71 fprintf(out, "; \t%cRevision: $\n;\n", '$');
72 fprintf(out, "; Network table generated by Moira at %s;\n",
75 EXEC SQL DECLARE x CURSOR FOR SELECT
76 name, snet_id, saddr, description
77 FROM subnet ORDER BY saddr;
80 EXEC SQL FETCH x INTO :name, :id, :saddr, :description;
81 if (sqlca.sqlcode != 0) break;
82 if (id == 0) continue;
83 if (*strtrim(name) == 0) continue;
84 addr.s_addr=htonl(saddr);
85 fprintf(out, "NETWORK : %-16.16s : %-12.12s : %s\n", name,
87 strtrim(description));
94 fprintf(out, "; End of automatically generated network table\n");
96 perror("close failed");
104 db_error(sqlca.sqlcode);