+/*
+ * Check the network map and determine whether the supplied node name is
+ * valid. If it is not a neighbor node, supply the name of a neighbor node
+ * which is the next hop.
+ */
+int is_valid_node(char *nexthop, char *node) {
+ char *ignetcfg = NULL;
+ int i;
+ char linebuf[SIZ];
+ char buf[SIZ];
+ int retval;
+ struct NetMap *nmptr;
+
+ if (node == NULL) {
+ return(-1);
+ }
+
+ /*
+ * First try the neighbor nodes
+ */
+ ignetcfg = CtdlGetSysConfig(IGNETCFG);
+ if (ignetcfg == NULL) {
+ if (nexthop != NULL) {
+ strcpy(nexthop, "");
+ }
+ return(-1);
+ }
+
+ retval = (-1);
+ if (nexthop != NULL) {
+ strcpy(nexthop, "");
+ }
+
+ /* Use the string tokenizer to grab one line at a time */
+ for (i=0; i<num_tokens(ignetcfg, '\n'); ++i) {
+ extract_token(linebuf, ignetcfg, i, '\n');
+ extract(buf, linebuf, 0);
+ if (!strcasecmp(buf, node)) {
+ if (nexthop != NULL) {
+ strcpy(nexthop, "");
+ }
+ retval = 0;
+ }
+ }
+
+ phree(ignetcfg);
+ if (retval == 0) {
+ return(retval); /* yup, it's a direct neighbor */
+ }
+
+ /*
+ * If we get to this point we have to see if we know the next hop
+ */
+ if (the_netmap != NULL) {
+ for (nmptr = the_netmap; nmptr != NULL; nmptr = nmptr->next) {
+ if (!strcasecmp(nmptr->nodename, node)) {
+ if (nexthop != NULL) {
+ strcpy(nexthop, nmptr->nexthop);
+ }
+ return(0);
+ }
+ }
+ }
+
+ /*
+ * If we get to this point, the supplied node name is bogus.
+ */
+ lprintf(5, "Invalid node name <%s>\n", node);
+ return(-1);
+}
+
+
+