xref: /netbsd-src/external/bsd/ipf/dist/lib/printmask.c (revision 13885a665959c62f13a82b3caedf986eaa17aa31)
1*13885a66Sdarrenr /*	$NetBSD: printmask.c,v 1.2 2012/07/22 14:27:37 darrenr Exp $	*/
2bc4097aaSchristos 
3bc4097aaSchristos /*
4c9d5dc6cSdarrenr  * Copyright (C) 2012 by Darren Reed.
5bc4097aaSchristos  *
6bc4097aaSchristos  * See the IPFILTER.LICENCE file for details on licencing.
7bc4097aaSchristos  *
8*13885a66Sdarrenr  * Id: printmask.c,v 1.1.1.2 2012/07/22 13:44:41 darrenr Exp $
9bc4097aaSchristos  */
10bc4097aaSchristos 
11bc4097aaSchristos #include "ipf.h"
12bc4097aaSchristos 
13bc4097aaSchristos 
14bc4097aaSchristos void
printmask(family,mask)15bc4097aaSchristos printmask(family, mask)
16bc4097aaSchristos 	int	family;
17bc4097aaSchristos 	u_32_t	*mask;
18bc4097aaSchristos {
19bc4097aaSchristos 	struct in_addr ipa;
20bc4097aaSchristos 	int ones;
21bc4097aaSchristos 
22c9d5dc6cSdarrenr 	if (family == AF_INET6) {
23bc4097aaSchristos 		PRINTF("/%d", count6bits(mask));
24bc4097aaSchristos 	} else if ((ones = count4bits(*mask)) == -1) {
25bc4097aaSchristos 		ipa.s_addr = *mask;
26bc4097aaSchristos 		PRINTF("/%s", inet_ntoa(ipa));
27bc4097aaSchristos 	} else {
28bc4097aaSchristos 		PRINTF("/%d", ones);
29bc4097aaSchristos 	}
30bc4097aaSchristos }
31