printf("replacing list %s\n", blacklists[index].tag);
printf("replacing list %s; %d new entries\n", blacklists[index].tag, addrc);
sdl_add(char *sdname, char *sdstring, char ** addrs, int addrc){	int i, index = -1;	char astring[40];	unsigned int maskbits;	struct sdaddr *m, *n;	/*	 * if a blacklist of same tag name is already there, replace it,	 * otherwise append.	 */	for (i = 0; i < blu; i++) {		if (strcmp(blacklists[i].tag, sdname) == 0) {			index = i;			break;		}	}	if (index != -1) {		if (debug > 0)			printf("replacing list %s\n", blacklists[index].tag);		sdl_free(&blacklists[index]);	} else {		if (debug > 0)			printf("adding list %s\n", sdname);		index = blu;	}	if (index == blu && blu == blc) {		struct sdlist *tmp;		tmp = realloc(blacklists, (blc + 128) *		    sizeof(struct sdlist));		if (tmp == NULL)			return (-1);		blacklists = tmp;		blc += 128;		sdl_clear(&blacklists[index]);	}	if ((blacklists[index].tag = strdup(sdname)) == NULL)		goto misc_error;	if ((blacklists[index].string = strdup(sdstring)) == NULL)		goto misc_error;	blacklists[index].naddrs = addrc;	/*	 * Cycle through addrs, converting. We assume they are correctly	 * formatted v4 and v6 addrs, if they don't all convert correctly, the	 * add fails. Each address should be address/maskbits	 */	blacklists[index].addrs = malloc(addrc * sizeof(struct sdentry));	if (blacklists[index].addrs == NULL)		goto misc_error;	for(i = 0; i < addrc; i++) {		int j, k, af;		n = &blacklists[index].addrs[i].sda;		m = &blacklists[index].addrs[i].sdm;		j = sscanf(addrs[i], "%39[^/]/%u", astring, &maskbits);		if (j != 2)			goto parse_error;		if (maskbits > 128)			goto parse_error;		/*		 * sanity check! we don't allow a 0 mask -		 * don't blacklist the entire net.		 */		if (maskbits == 0)			goto parse_error;		if (strchr(astring, ':') != NULL)			af = AF_INET6;		else			af = AF_INET;		if (af == AF_INET && maskbits > 32)			goto parse_error;		j = inet_pton(af, astring, n);		if (j != 1)			goto parse_error;		if (debug > 0)			printf("added %s/%u\n", astring, maskbits);		/* set mask, borrowed from pf */		k = 0;		for (j = 0; j < 4; j++)			m->addr32[j] = 0;		while (maskbits >= 32) {			m->addr32[k++] = 0xffffffff;			maskbits -= 32;		}		for (j = 31; j > 31 - maskbits; --j)			m->addr32[k] |= (1 << j);		if (maskbits)			m->addr32[k] = htonl(m->addr32[k]);		/* mask off address bits that won't ever be used */		for (j = 0; j < 4; j++)			n->addr32[j] = n->addr32[j] & m->addr32[j];	}	if (index == blu) {		blu++;		blacklists[blu].tag = NULL;	}	return (0); parse_error:	if (debug > 0)		printf("sdl_add: parse error, \"%s\"\n", addrs[i]); misc_error:	sdl_free(&blacklists[index]);	return (-1);}