start_stop_daemon: NOMMU fixes, round 2 by Alex Landau <landau_alex@yahoo.com>
[oweals/busybox.git] / networking / ipcalc.c
index 909373cbb234b6bc018529e356ff8cc45905b9f2..f3e3ad98f45ef9b3e1fdab16e633365f9e8f2149 100644 (file)
  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
-#include "busybox.h"
-#include <ctype.h>
 #include <getopt.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
 
+#include "libbb.h"
+
 #define CLASS_A_NETMASK        ntohl(0xFF000000)
 #define CLASS_B_NETMASK        ntohl(0xFFFF0000)
 #define CLASS_C_NETMASK        ntohl(0xFFFFFF00)
@@ -43,7 +43,7 @@ static int get_prefix(unsigned long netmask)
        int ret = 0;
 
        netmask = htonl(netmask);
-       while(msk) {
+       while (msk) {
                if (netmask & msk)
                        ret++;
                msk >>= 1;
@@ -63,20 +63,19 @@ int get_prefix(unsigned long netmask);
 #define SILENT    0x20
 
 #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS
-       static const struct option long_options[] = {
-               {"netmask",             no_argument, NULL, 'm'},
-               {"broadcast",   no_argument, NULL, 'b'},
-               {"network",             no_argument, NULL, 'n'},
-#ifdef CONFIG_FEATURE_IPCALC_FANCY
-               {"prefix",              no_argument, NULL, 'p'},
-               {"hostname",    no_argument, NULL, 'h'},
-               {"silent",              no_argument, NULL, 's'},
-#endif
-               {NULL, 0, NULL, 0}
-       };
-#else
-#define long_options 0
+       static const char ipcalc_longopts[] =
+               "netmask\0"   No_argument "m"
+               "broadcast\0" No_argument "b"
+               "network\0"   No_argument "n"
+# if ENABLE_FEATURE_IPCALC_FANCY
+               "prefix\0"    No_argument "p"
+               "hostname\0"  No_argument "h"
+               "silent\0"    No_argument "s"
+# endif
+               ;
 #endif
+
+int ipcalc_main(int argc, char **argv);
 int ipcalc_main(int argc, char **argv)
 {
        unsigned opt;
@@ -85,9 +84,9 @@ int ipcalc_main(int argc, char **argv)
        struct in_addr a;
        char *ipstr;
 
-       if (ENABLE_FEATURE_IPCALC_LONG_OPTIONS)
-               applet_long_options = long_options;
-
+#if ENABLE_FEATURE_IPCALC_LONG_OPTIONS
+       applet_long_options = ipcalc_longopts;
+#endif
        opt = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs"));
        argc -= optind;
        argv += optind;