X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=networking%2Fipcalc.c;h=18abc12eb405a07d8ae6aae342cab8d62a99d5fb;hb=d7171c114028815df4e92f9c26875f1d60c6af2a;hp=0ee9646c2476ceb22421f87c83d23e23dd6c7e8f;hpb=c61852a02bd2d61682235ba3185173f527313827;p=oweals%2Fbusybox.git diff --git a/networking/ipcalc.c b/networking/ipcalc.c index 0ee9646c2..18abc12eb 100644 --- a/networking/ipcalc.c +++ b/networking/ipcalc.c @@ -12,12 +12,11 @@ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ -#include "busybox.h" -#include -#include #include #include +#include "libbb.h" + #define CLASS_A_NETMASK ntohl(0xFF000000) #define CLASS_B_NETMASK ntohl(0xFFFF0000) #define CLASS_C_NETMASK ntohl(0xFFFFFF00) @@ -36,14 +35,14 @@ static unsigned long get_netmask(unsigned long ipaddr) return 0; } -#ifdef CONFIG_FEATURE_IPCALC_FANCY +#if ENABLE_FEATURE_IPCALC_FANCY static int get_prefix(unsigned long netmask) { unsigned long msk = 0x80000000; int ret = 0; netmask = htonl(netmask); - while(msk) { + while (msk) { if (netmask & msk) ret++; msk >>= 1; @@ -63,19 +62,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' }, + static const char ipcalc_longopts[] ALIGN1 = + "netmask\0" No_argument "m" + "broadcast\0" No_argument "b" + "network\0" No_argument "n" # if ENABLE_FEATURE_IPCALC_FANCY - { "prefix", no_argument, NULL, 'p' }, - { "hostname", no_argument, NULL, 'h' }, - { "silent", no_argument, NULL, 's' }, + "prefix\0" No_argument "p" + "hostname\0" No_argument "h" + "silent\0" No_argument "s" # endif - { NULL, 0, NULL, 0 } - }; + ; #endif +int ipcalc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int ipcalc_main(int argc, char **argv) { unsigned opt; @@ -85,9 +84,9 @@ int ipcalc_main(int argc, char **argv) char *ipstr; #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS - applet_long_options = long_options; + applet_long_options = ipcalc_longopts; #endif - opt = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs")); + opt = getopt32(argv, "mbn" IF_FEATURE_IPCALC_FANCY("phs")); argc -= optind; argv += optind; if (opt & (BROADCAST | NETWORK | NETPREFIX)) { @@ -176,15 +175,12 @@ int ipcalc_main(int argc, char **argv) if (opt & HOSTNAME) { struct hostent *hostinfo; - int x; hostinfo = gethostbyaddr((char *) &ipaddr, sizeof(ipaddr), AF_INET); if (!hostinfo) { - bb_herror_msg_and_die("cannot find hostname for %s", argv[0]); - } - for (x = 0; hostinfo->h_name[x]; x++) { - hostinfo->h_name[x] = tolower(hostinfo->h_name[x]); + bb_herror_msg_and_die("can't find hostname for %s", argv[0]); } + str_tolower(hostinfo->h_name); printf("HOSTNAME=%s\n", hostinfo->h_name); }