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];
36 EXEC SQL BEGIN DECLARE SECTION;
38 char name[SUBNET_NAME_SIZE], description[SUBNET_DESCRIPTION_SIZE];
39 EXEC SQL END DECLARE SECTION;
46 sprintf(outft, "%s~", outf);
47 if (!(out = fopen(outft, "w")))
49 fprintf(stderr, "unable to open %s for output\n", outf);
55 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
61 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
63 gettimeofday(&now, NULL);
65 fprintf(out, "; MIT Network Table\n;\n");
66 fprintf(out, "; \t%cAuthor: $\n", '$');
67 fprintf(out, "; \t%cDate: $\n", '$');
68 fprintf(out, "; \t%cRevision: $\n;\n", '$');
69 fprintf(out, "; Network table generated by Moira at %s;\n",
72 EXEC SQL DECLARE x CURSOR FOR SELECT
73 name, snet_id, saddr, description
74 FROM subnet ORDER BY saddr;
78 EXEC SQL FETCH x INTO :name, :id, :saddr, :description;
85 addr.s_addr = htonl(saddr);
86 fprintf(out, "NETWORK : %-16.16s : %-12.12s : %s\n", name,
87 inet_ntoa(addr), strtrim(description));
94 fprintf(out, "; End of automatically generated network table\n");
97 perror("close failed");
105 db_error(sqlca.sqlcode);