3 * This generates the network table.
5 * Copyright (C) 1994-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
23 EXEC SQL INCLUDE sqlca;
27 char *whoami = "network.gen";
28 char *db = "moira/moira";
30 int main(int argc, char **argv)
33 char *outf = NULL, outft[MAXPATHLEN];
38 EXEC SQL BEGIN DECLARE SECTION;
40 char name[SUBNET_NAME_SIZE], description[SUBNET_DESCRIPTION_SIZE];
41 EXEC SQL END DECLARE SECTION;
47 if (stat(argv[1], &sb) == 0)
49 if (ModDiff(&flag1, "subnet", sb.st_mtime))
53 fprintf(stderr, "File %s does not need to be rebuilt.\n",
59 sprintf(outft, "%s~", outf);
60 if (!(out = fopen(outft, "w")))
62 fprintf(stderr, "unable to open %s for output\n", outf);
68 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
74 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
76 gettimeofday(&now, NULL);
78 fprintf(out, "; MIT Network Table\n;\n");
79 fprintf(out, "; \t%cAuthor: $\n", '$');
80 fprintf(out, "; \t%cDate: $\n", '$');
81 fprintf(out, "; \t%cRevision: $\n;\n", '$');
82 fprintf(out, "; Network table generated by Moira at %s;\n",
85 EXEC SQL DECLARE x CURSOR FOR SELECT
86 name, snet_id, saddr, description
87 FROM subnet ORDER BY saddr;
91 EXEC SQL FETCH x INTO :name, :id, :saddr, :description;
98 addr.s_addr = htonl(saddr);
99 fprintf(out, "NETWORK : %-16.16s : %-12.12s : %s\n", name,
100 inet_ntoa(addr), strtrim(description));
107 fprintf(out, "; End of automatically generated network table\n");
110 perror("close failed");
118 db_error(sqlca.sqlcode);