+
+static ping_target *
+parse_mode (Bool ping_works_p)
+{
+ char *source = get_string_resource ("ping", "Ping");
+ char *token, *end;
+ char dummy;
+
+ ping_target *hostlist = 0;
+
+ if (!source) source = strdup("");
+
+ if (!*source || !strcmp (source, "default"))
+ {
+# ifdef HAVE_PING
+ if (ping_works_p) /* if root or setuid, ping will work. */
+ source = strdup("subnet/29,/etc/hosts");
+ else
+# endif
+ source = strdup("simulation");
+ }
+
+ token = source;
+ end = source + strlen(source);
+ while (token < end)
+ {
+ char *next;
+# ifdef HAVE_PING
+ ping_target *new;
+ struct stat st;
+ unsigned int n0=0, n1=0, n2=0, n3=0, m=0;
+ char d;
+# endif /* HAVE_PING */
+
+ for (next = token;
+ *next &&
+ *next != ',' && *next != ' ' && *next != '\t' && *next != '\n';
+ next++)
+ ;
+ *next = 0;
+
+
+ if (debug_p)
+ fprintf (stderr, "%s: parsing %s\n", progname, token);
+
+ if (!strcmp (token, "simulation"))
+ return 0;
+
+ if (!ping_works_p)
+ {
+ fprintf(stderr,
+ "%s: this program must be setuid to root for `ping mode' to work.\n"
+ " Running in `simulation mode' instead.\n",
+ progname);
+ return 0;
+ }
+
+#ifdef HAVE_PING
+ if ((4 == sscanf (token, "%u.%u.%u/%u %c", &n0,&n1,&n2, &m,&d)) ||
+ (5 == sscanf (token, "%u.%u.%u.%u/%u %c", &n0,&n1,&n2,&n3,&m,&d)))
+ {
+ /* subnet: A.B.C.D/M
+ subnet: A.B.C/M
+ */
+ unsigned long ip = pack_addr (n0, n1, n2, n3);
+ new = subnetHostsList(ip, m);
+ }
+ else if (4 == sscanf (token, "%u.%u.%u.%u %c", &n0, &n1, &n2, &n3, &d))
+ {
+ /* IP: A.B.C.D
+ */
+ new = newHost (token);
+ }
+ else if (!strcmp (token, "subnet"))
+ {
+ new = subnetHostsList(0, 24);
+ }
+ else if (1 == sscanf (token, "subnet/%u %c", &m, &dummy))
+ {
+ new = subnetHostsList(0, m);
+ }
+ else if (*token == '.' || *token == '/' || !stat (token, &st))
+ {
+ /* file name
+ */
+ new = readPingHostsFile (token);
+ }
+ else
+ {
+ /* not an existant file - must be a host name
+ */
+ new = newHost (token);
+ }
+
+ if (new)
+ {
+ ping_target *nn = new;
+ while (nn && nn->next)
+ nn = nn->next;
+ nn->next = hostlist;
+ hostlist = new;
+
+ sensor = ping;
+ }
+#endif /* HAVE_PING */
+
+ token = next + 1;
+ while (token < end &&
+ (*token == ',' || *token == ' ' ||
+ *token == '\t' || *token == '\n'))
+ token++;
+ }
+
+ return hostlist;
+}
+
+
+