xref: /freebsd/sbin/ipf/libipf/printmask.c (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
141edb306SCy Schubert 
241edb306SCy Schubert /*
341edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
441edb306SCy Schubert  *
541edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert  *
741edb306SCy Schubert  * $Id$
841edb306SCy Schubert  */
941edb306SCy Schubert 
1041edb306SCy Schubert #include "ipf.h"
1141edb306SCy Schubert 
1241edb306SCy Schubert 
1341edb306SCy Schubert void
printmask(int family,u_32_t * mask)14*efeb8bffSCy Schubert printmask(int family, u_32_t *mask)
1541edb306SCy Schubert {
1641edb306SCy Schubert 	struct in_addr ipa;
1741edb306SCy Schubert 	int ones;
1841edb306SCy Schubert 
1941edb306SCy Schubert 	if (family == AF_INET6) {
2041edb306SCy Schubert 		PRINTF("/%d", count6bits(mask));
2141edb306SCy Schubert 	} else if ((ones = count4bits(*mask)) == -1) {
2241edb306SCy Schubert 		ipa.s_addr = *mask;
2341edb306SCy Schubert 		PRINTF("/%s", inet_ntoa(ipa));
2441edb306SCy Schubert 	} else {
2541edb306SCy Schubert 		PRINTF("/%d", ones);
2641edb306SCy Schubert 	}
2741edb306SCy Schubert }
28