fix netdb bug
1) If netdb calls exit() then tash will be destroyed. so I call 'return' instead of calling exit().
2) Usage message is wrong, showing address options even though HAVE_GETHOSTBYADDR flag is off.
* Private Functions
****************************************************************************/
-static void show_usage(FAR const char *progname, int exitcode) noreturn_function;
-static void show_usage(FAR const char *progname, int exitcode)
+static void show_usage(FAR const char *progname)
{
- fprintf(stderr, "USAGE: %s --ipv4 <ipv4-addr>\n", progname);
+ fprintf(stderr, "USAGE: %s --host <host-name>\n", progname);
#ifdef HAVE_GETHOSTBYADDR
+ fprintf(stderr, " %s --ipv4 <ipv4-addr>\n", progname);
fprintf(stderr, " %s --ipv6 <ipv6-addr>\n", progname);
- fprintf(stderr, " %s --host <host-name>\n", progname);
#endif
fprintf(stderr, " %s --help\n", progname);
- exit(exitcode);
}
/****************************************************************************
@@ -147,17 +145,20 @@ int netdb_main(int argc, char *argv[])
/* Handle: netdb --help */
if (argc == 2 && strcmp(argv[1], "--help") == 0) {
- show_usage(argv[0], EXIT_SUCCESS);
+ show_usage(argv[0]);
+ return EXIT_FAILURE;
}
/* Otherwise there must be exactly two arguments following the program name */
else if (argc < 3) {
fprintf(stderr, "ERROR -- Missing arguments\n\n");
- show_usage(argv[0], EXIT_FAILURE);
+ show_usage(argv[0]);
+ return EXIT_FAILURE;
} else if (argc > 3) {
fprintf(stderr, "ERROR -- Too many arguments\n\n");
- show_usage(argv[0], EXIT_FAILURE);
+ show_usage(argv[0]);
+ return EXIT_FAILURE;
}
#ifdef HAVE_GETHOSTBYADDR
/* Handle: netdb --ipv4 <ipv4-addr> */
@@ -170,7 +171,8 @@ int netdb_main(int argc, char *argv[])
ret = inet_pton(AF_INET, argv[2], &addr);
if (ret < 0) {
fprintf(stderr, "ERROR -- Bad IPv4 address\n\n");
- show_usage(argv[0], EXIT_FAILURE);
+ show_usage(argv[0]);
+ return EXIT_FAILURE;
}
/* Get the matching host name + any aliases */
@@ -192,7 +194,8 @@ int netdb_main(int argc, char *argv[])
ret = inet_pton(AF_INET6, argv[2], &addr);
if (ret < 0) {
fprintf(stderr, "ERROR -- Bad IPv6 address\n\n");
- show_usage(argv[0], EXIT_FAILURE);
+ show_usage(argv[0]);
+ return EXIT_FAILURE;
}
/* Get the matching host name + any aliases */
@@ -221,7 +224,8 @@ int netdb_main(int argc, char *argv[])
else {
fprintf(stderr, "ERROR -- Unrecognized option: %s\n\n", argv[1]);
- show_usage(argv[0], EXIT_FAILURE);
+ show_usage(argv[0]);
+ return EXIT_FAILURE;
}
/* If we get here, then gethostbyname() or gethostbyaddr() was
