printf("PREFIX=%d\n", prefix);
int main(int argc, const char **argv) {    int showBroadcast = 0, showNetwork = 0, showHostname = 0, showNetmask = 0;    int beSilent = 0;    int rc;    poptContext optCon;    char *ipStr, *prefixStr, *netmaskStr, *hostName, *chptr;    struct in_addr ip, netmask, network, broadcast;    int prefix = 0;    char errBuf[250];    struct poptOption optionsTable[] = {	    { "broadcast", 'b', 0, &showBroadcast, 0,		"Display calculated broadcast address", },	    { "hostname", 'h', 0, &showHostname, 0,		"Show hostname determined via DNS" },	    { "netmask", 'm', 0, &showNetmask, 0,		"Display default netmask for IP (class A, B, or C)" },	    { "network", 'n', 0, &showNetwork, 0,		"Display calculated network address", },	    { "silent", 's', 0, &beSilent, 0,		"Don't ever display error messages " },	    POPT_AUTOHELP	    POPT_TABLEEND    };    optCon = poptGetContext("ipcalc", argc, argv, optionsTable, 0);    poptReadDefaultConfig(optCon, 1);    if ((rc = poptGetNextOpt(optCon)) < -1) {	if (!beSilent) {	    fprintf(stderr, "ipcalc: bad argument %s: %s\n", 		    poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 		    poptStrerror(rc));	    poptPrintHelp(optCon, stderr, 0);	}	return 1;    }    if (!(ipStr = (char *) poptGetArg(optCon))) {	if (!beSilent) {	    fprintf(stderr, "ipcalc: ip address expected\n");	    poptPrintHelp(optCon, stderr, 0);	}	return 1;    }    if (strchr(ipStr,'/') != NULL) {	prefixStr = strchr(ipStr, '/') + 1;	prefixStr--;	*prefixStr = '\0';  /* fix up ipStr */	prefixStr++;    } else	prefixStr = NULL;        if (!inet_aton(ipStr, &ip)) {	if (!beSilent)	    fprintf(stderr, "ipcalc: bad ip address: %s\n",		    ipStr);	return 1;    }    if (prefixStr != NULL) {	prefix = atoi(prefixStr);	if (prefix == 0) {	    if (!beSilent)		fprintf(stderr, "ipcalc: bad prefix: %s\n",			prefixStr);	    return 1;	}    }	    if (showBroadcast || showNetwork) {	if (!(netmaskStr = (char *) poptGetArg(optCon)) &&	    (prefix == 0)) {	    if (!beSilent) {		fprintf(stderr, "ipcalc: netmask or prefix expected\n");		poptPrintHelp(optCon, stderr, 0);	    }	    return 1;	} else if (netmaskStr) {	    if (!inet_aton(netmaskStr, &netmask)) {		if (!beSilent)		    fprintf(stderr, "ipcalc: bad netmask: %s\n",			    netmaskStr);		return 1;	    }	    prefix = mask2prefix(netmask.s_addr);	}    }    if ((chptr = (char *) poptGetArg(optCon))) {	if (!beSilent) {	    fprintf(stderr, "ipcalc: unexpected argument: %s\n", chptr);	    poptPrintHelp(optCon, stderr, 0);	}	return 1;    }    if (!inet_aton(ipStr, (struct in_addr *) &ip)) {	if (!beSilent)	    fprintf(stderr, "ipcalc: bad ip address: %s\n", ipStr);	return 1;    }    poptFreeContext(optCon);    /* we know what we want to display now, so display it. */    if (showNetmask) {	if (prefix) {	    netmask.s_addr = prefix2mask(prefix);	} else {	    netmask.s_addr = default_netmask(ip.s_addr);	    prefix = mask2prefix(netmask.s_addr);	}		printf("PREFIX=%d\n", prefix);	printf("NETMASK=%s\n", inet_ntoa(netmask));    }    if (showBroadcast) {	broadcast.s_addr = calc_broadcast(ip.s_addr, prefix);	printf("BROADCAST=%s\n", inet_ntoa(broadcast));    }    if (showNetwork) {	network.s_addr = calc_network(ip.s_addr, prefix);	printf("NETWORK=%s\n", inet_ntoa(network));    }        if (showHostname) {		if ((hostName = (char *) get_hostname(ip.s_addr)) == NULL) {	    if (!beSilent) {		sprintf(errBuf, "ipcalc: cannot find hostname for %s", ipStr);		herror(errBuf);	    }	    return 1;	}		printf("HOSTNAME=%s\n", hostName);    }	    return 0;}