/* vi: set sw=4 ts=4 ai: */
/*
 * Mini ipcalc implementation for busybox
 *
 * By Jordan Crouse <jordan@cosmicpenguin.net>
 *    Stephan Linz  <linz@li-pro.net>
 *
 * This is a complete reimplementation of the ipcalc program
 * from Red Hat.  I didn't look at their source code, but there
 * is no denying that this is a loving reimplementation
 *
 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
 */

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <getopt.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include "busybox.h"

#define IPCALC_MSG(CMD,ALTCMD) if (mode & SILENT) {ALTCMD;} else {CMD;}

#define CLASS_A_NETMASK	ntohl(0xFF000000)
#define CLASS_B_NETMASK	ntohl(0xFFFF0000)
#define CLASS_C_NETMASK	ntohl(0xFFFFFF00)

static unsigned long get_netmask(unsigned long ipaddr)
{
	ipaddr = htonl(ipaddr);

	if ((ipaddr & 0xC0000000) == 0xC0000000)
		return CLASS_C_NETMASK;
	else if ((ipaddr & 0x80000000) == 0x80000000)
		return CLASS_B_NETMASK;
	else if ((ipaddr & 0x80000000) == 0)
		return CLASS_A_NETMASK;
	else
		return 0;
}

#ifdef CONFIG_FEATURE_IPCALC_FANCY
static int get_prefix(unsigned long netmask)
{
	unsigned long msk = 0x80000000;
	int ret = 0;

	netmask = htonl(netmask);
	while(msk) {
		if (netmask & msk)
			ret++;
		msk >>= 1;
	}
	return ret;
}
#endif

#define NETMASK   0x01
#define BROADCAST 0x02
#define NETWORK   0x04
#define NETPREFIX 0x08
#define HOSTNAME  0x10
#define SILENT    0x20


int ipcalc_main(int argc, char **argv)
{
	unsigned long mode;

	in_addr_t netmask;
	in_addr_t broadcast;
	in_addr_t network;
	in_addr_t ipaddr;
	struct in_addr a;

#ifdef CONFIG_FEATURE_IPCALC_FANCY
	unsigned long netprefix = 0;
	int have_netmask = 0;
	char *ipstr, *prefixstr;
#endif

#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}
	};

	bb_applet_long_options = long_options;
#endif
	mode = bb_getopt_ulflags(argc, argv,
#ifdef CONFIG_FEATURE_IPCALC_FANCY
			"mbnphs"
#else
			"mbn"
#endif
			);

	argc -= optind;
	argv += optind;
	if (mode & (BROADCAST | NETWORK | NETPREFIX)) {
		if (argc > 2 || argc <= 0)
			bb_show_usage();
	} else {
		if (argc != 1)
			bb_show_usage();
	}

#ifdef CONFIG_FEATURE_IPCALC_FANCY
	prefixstr = ipstr = argv[0];

	while(*prefixstr) {
		if (*prefixstr == '/') {
			*prefixstr = (char)0;
			prefixstr++;
			if (*prefixstr) {
				unsigned int msk;

				if (safe_strtoul(prefixstr, &netprefix) || netprefix > 32) {
					IPCALC_MSG(bb_error_msg_and_die("bad IP prefix: %s\n", prefixstr),
							exit(EXIT_FAILURE));
				}
				netmask = 0;
				msk = 0x80000000;
				while (netprefix > 0) {
					netmask |= msk;
					msk >>= 1;
					netprefix--;
				}
				netmask = htonl(netmask);
				/* Even if it was 0, we will signify that we have a netmask. This allows */
				/* for specification of default routes, etc which have a 0 netmask/prefix */
				have_netmask = 1;
			}
			break;
		}
		prefixstr++;
	}
	ipaddr = inet_aton(ipstr, &a);
#else
	ipaddr = inet_aton(argv[0], &a);
#endif

	if (ipaddr == 0) {
		IPCALC_MSG(bb_error_msg_and_die("bad IP address: %s", argv[0]),
				exit(EXIT_FAILURE));
	}
	ipaddr = a.s_addr;

	if (argc == 2) {
#ifdef CONFIG_FEATURE_IPCALC_FANCY
		if (have_netmask) {
			IPCALC_MSG(bb_error_msg_and_die("Both prefix and netmask were specified, use one or the other.\n"),
					exit(EXIT_FAILURE));
		}

#endif
		netmask = inet_aton(argv[1], &a);
		if (netmask == 0) {
			IPCALC_MSG(bb_error_msg_and_die("bad netmask: %s", argv[1]),
					exit(EXIT_FAILURE));
		}
		netmask = a.s_addr;
	} else {
#ifdef CONFIG_FEATURE_IPCALC_FANCY

		if (!have_netmask)
#endif
			/* JHC - If the netmask wasn't provided then calculate it */
			netmask = get_netmask(ipaddr);
	}

	if (mode & NETMASK) {
		printf("NETMASK=%s\n", inet_ntoa((*(struct in_addr *) &netmask)));
	}

	if (mode & BROADCAST) {
		broadcast = (ipaddr & netmask) | ~netmask;
		printf("BROADCAST=%s\n", inet_ntoa((*(struct in_addr *) &broadcast)));
	}

	if (mode & NETWORK) {
		network = ipaddr & netmask;
		printf("NETWORK=%s\n", inet_ntoa((*(struct in_addr *) &network)));
	}

#ifdef CONFIG_FEATURE_IPCALC_FANCY
	if (mode & NETPREFIX) {
		printf("PREFIX=%i\n", get_prefix(netmask));
	}

	if (mode & HOSTNAME) {
		struct hostent *hostinfo;
		int x;

		hostinfo = gethostbyaddr((char *) &ipaddr, sizeof(ipaddr), AF_INET);
		if (!hostinfo) {
			IPCALC_MSG(bb_herror_msg_and_die(
						"cannot find hostname for %s", argv[0]),);
			exit(EXIT_FAILURE);
		}
		for (x = 0; hostinfo->h_name[x]; x++) {
			hostinfo->h_name[x] = tolower(hostinfo->h_name[x]);
		}

		printf("HOSTNAME=%s\n", hostinfo->h_name);
	}
#endif

	return EXIT_SUCCESS;
}
