summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fa2472c)
raw | patch | inline | side by side (parent: fa2472c)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 26 Oct 2010 14:20:51 +0000 (16:20 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 26 Oct 2010 14:20:51 +0000 (16:20 +0200) |
src/oping.c | patch | blob | history |
diff --git a/src/oping.c b/src/oping.c
index 0f8e4139cb03427954a3e42926353b8575e4ba76..78f053f31e4f3e8568ff32e18c22caa3731cce62 100644 (file)
--- a/src/oping.c
+++ b/src/oping.c
# endif
#endif
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#if HAVE_NETINET_IP_H
+# include <netinet/ip.h>
+#endif
+
#if HAVE_NETDB_H
# include <netdb.h> /* NI_MAXHOST */
#endif
static char *opt_filename = NULL;
static int opt_count = -1;
static int opt_send_ttl = 64;
-static unsigned opt_send_tos = 0;
+static uint8_t opt_send_tos = 0;
static int host_num = 0;
exit (status);
} /* }}} void usage_exit */
+static void usage_tos_exit (const char *arg, int status) /* {{{ */
+{
+ if (arg != 0)
+ fprintf (stderr, "Invalid ToS argument: \"%s\"\n\n", arg);
+
+ fprintf (stderr, "Valid ToS arguments (option \"-z\") are:\n"
+ "\n"
+ " lowdelay (%#04x) minimize delays\n"
+ " throughput (%#04x) optimize throughput\n"
+ " reliability (%#04x) optimize reliability\n"
+ " mincost (%#04x) minimize cost\n"
+ " 0x00 - 0xff specify manually\n"
+ "\n",
+ (unsigned int) IPTOS_LOWDELAY,
+ (unsigned int) IPTOS_THROUGHPUT,
+ (unsigned int) IPTOS_RELIABILITY,
+ (unsigned int) IPTOS_MINCOST);
+
+ exit (status);
+} /* }}} void usage_tos_exit */
+
+static int set_opt_send_tos (const char *opt) /* {{{ */
+{
+ if (opt == NULL)
+ return (EINVAL);
+
+ if (strcasecmp ("lowdelay", opt) == 0)
+ opt_send_tos = IPTOS_LOWDELAY;
+ else if (strcasecmp ("throughput", opt) == 0)
+ opt_send_tos = IPTOS_THROUGHPUT;
+ else if (strcasecmp ("reliability", opt) == 0)
+ opt_send_tos = IPTOS_RELIABILITY;
+ else if (strcasecmp ("mincost", opt) == 0)
+ opt_send_tos = IPTOS_MINCOST;
+ else if (strcasecmp ("help", opt) == 0)
+ usage_tos_exit (/* arg = */ NULL, /* status = */ EXIT_SUCCESS);
+ else
+ {
+ unsigned long value;
+ char *endptr;
+
+ errno = 0;
+ endptr = NULL;
+ value = strtoul (opt, &endptr, /* base = */ 0);
+ if ((errno != 0) || (endptr == opt)
+ || (endptr == NULL) || (*endptr != 0)
+ || (value >= 0xff))
+ usage_tos_exit (/* arg = */ opt, /* status = */ EXIT_FAILURE);
+
+ opt_send_tos = (uint8_t) value;
+ }
+
+ return (0);
+} /* }}} int set_opt_send_tos */
+
static int read_options (int argc, char **argv) /* {{{ */
{
int optchar;
}
case 'z':
- {
- int new_send_tos;
- new_send_tos = atoi (optarg);
- if ((new_send_tos > 0) && (new_send_tos < 256))
- opt_send_tos = new_send_tos;
- else
- fprintf (stderr, "Ignoring invalid TOS argument: %s\n",
- optarg);
+ set_opt_send_tos (optarg);
break;
- }
case 'h':
usage_exit (argv[0], 0);