+/* ---------- Subnet Menu -------- */
+
+/* Function Name: ShowSubnetInfo
+ * Description: Gets information about a subnet given its name.
+ * Arguments: argc, argc - the name of the subnet in in argv[1].
+ * Returns: DM_NORMAL.
+ */
+
+/* ARGSUSED */
+int
+ShowSubnetInfo(argc, argv)
+int argc;
+char ** argv;
+{
+ struct qelem *top;
+
+ top = GetMCInfo(SUBNET, argv[1], (char *) NULL);
+ Loop(top, (void *) PrintSubnetInfo);
+ FreeQueue(top);
+ return(DM_NORMAL);
+}
+
+/* Function Name: AddSubnet
+ * Description: Creates a new subnet.
+ * Arguments: argc, argv - the name of the new subnet is argv[1].
+ * Returns: DM_NORMAL.
+ */
+
+/* ARGSUSED */
+int
+AddSubnet(argc, argv)
+int argc;
+char ** argv;
+{
+ char **args, *info[MAX_ARGS_SIZE], *name = argv[1];
+ int stat;
+/*
+ * Check to see if this subnet already exists.
+ */
+ if (!ValidName(name))
+ return(DM_NORMAL);
+
+ if ( (stat = do_mr_query("get_subnet", 1, &name,
+ NullFunc, NULL)) == MR_SUCCESS) {
+ Put_message("This subnet already exists.");
+ return(DM_NORMAL);
+ }
+ else if (stat != MR_NO_MATCH) {
+ com_err(program_name, stat, " in AddSubnet.");
+ return(DM_NORMAL);
+ }
+ if ((args = AskMCDInfo(SetSubnetDefaults(info, name), SUBNET, FALSE)) ==
+ NULL) {
+ Put_message("Aborted.");
+ FreeInfo(info);
+ return(DM_NORMAL);
+ }
+
+/*
+ * Actually create the new Subnet.
+ */
+ if ( (stat = do_mr_query("add_subnet", CountArgs(args),
+ args, Scream, NULL)) != 0)
+ com_err(program_name, stat, " in AddSubnet.");
+
+ FreeInfo(info);
+ return(DM_NORMAL);
+}
+
+/* Function Name: RealUpdateSubnet
+ * Description: This function actually performs the subnet update.
+ * Arguments: info - all information nesc. for updating the subnet.
+ * junk - an UNUSED boolean.
+ * Returns: none.
+ */
+
+/* ARGSUSED */
+static void
+RealUpdateSubnet(info, junk)
+char ** info;
+Bool junk;
+{
+ register int stat;
+ char ** args = AskMCDInfo(info, SUBNET, TRUE);
+ if (args == NULL) {
+ Put_message("Aborted.");
+ return;
+ }
+ if ( (stat = do_mr_query("update_subnet", CountArgs(args),
+ args, Scream, NULL)) != 0)
+ com_err(program_name, stat, " in UpdateSubnet.");
+ else
+ Put_message("Subnet successfully updated.");
+}
+
+/* Function Name: UpdateSubnet
+ * Description: This Function Updates a subnet
+ * Arguments: name of the subnet in argv[1].
+ * Returns: DM_NORMAL.
+ */
+
+/* ARGSUSED */
+int
+UpdateSubnet(argc, argv)
+int argc;
+char ** argv;
+{
+ struct qelem *top;
+ top = GetMCInfo( SUBNET, argv[1], (char *) NULL );
+ QueryLoop(top, NullPrint, RealUpdateSubnet, "Update the subnet");
+
+ FreeQueue(top);
+ return(DM_NORMAL);
+}
+
+/* Function Name: RealDeleteSubnet
+ * Description: Actually performs the subnet deletion.
+ * Arguments: info - all information about this subnet.
+ * one_subnet - If true then there was only one subnet in
+ * the queue, and we should confirm.
+ * Returns: none.
+ */
+
+static void
+RealDeleteSubnet(info, one_subnet)
+char ** info;
+Bool one_subnet;
+{
+ register int stat;
+ char temp_buf[BUFSIZ];
+
+ sprintf(temp_buf,
+ "Are you sure the you want to delete the subnet %s (y/n) ?",
+ info[C_NAME]);
+ if (!one_subnet || Confirm(temp_buf)) {
+ if ( (stat = do_mr_query("delete_subnet", 1,
+ &info[C_NAME], Scream, NULL)) != 0) {
+ com_err(program_name, stat, " in delete_subnet.");
+ sprintf(temp_buf, "Subnet %s ** NOT ** deleted.",
+ info[C_NAME]);
+ Put_message(temp_buf);
+ }
+ else {
+ sprintf(temp_buf, "subnet %s sucesfully deleted.",
+ info[C_NAME]);
+ Put_message(temp_buf);
+ }
+ }
+}
+
+/* Function Name: DeleteSubnet
+ * Description: This function removes a subnet from the database.
+ * Arguments: argc, argv - the name of the subnet is stored in argv[1].
+ * Returns: DM_NORMAL.
+ */
+
+/* ARGSUSED */
+int
+DeleteSubnet(argc, argv)
+int argc;
+char ** argv;
+{
+ struct qelem *top;
+
+ top = GetMCInfo( SUBNET, argv[1], (char *) NULL );
+ QueryLoop(top, PrintSubnetInfo, RealDeleteSubnet, "Delete the subnet");
+
+ FreeQueue(top);
+ return(DM_NORMAL);
+}
+