xref: /netbsd-src/external/bsd/ipf/dist/lib/printhostmask.c (revision f44489f8dc8d71cd25a1bf30a50ca8ed13a40da3)
1*f44489f8Sprlw1 /*	$NetBSD: printhostmask.c,v 1.3 2014/12/20 13:15:48 prlw1 Exp $	*/
2bc4097aaSchristos 
3bc4097aaSchristos /*
4c9d5dc6cSdarrenr  * Copyright (C) 2012 by Darren Reed.
5bc4097aaSchristos  *
6bc4097aaSchristos  * See the IPFILTER.LICENCE file for details on licencing.
7bc4097aaSchristos  *
813885a66Sdarrenr  * Id: printhostmask.c,v 1.1.1.2 2012/07/22 13:44:40 darrenr Exp $
9bc4097aaSchristos  */
10bc4097aaSchristos 
11bc4097aaSchristos #include "ipf.h"
12bc4097aaSchristos 
13bc4097aaSchristos 
14bc4097aaSchristos void
printhostmask(family,addr,mask)15bc4097aaSchristos printhostmask(family, addr, mask)
16bc4097aaSchristos 	int	family;
17bc4097aaSchristos 	u_32_t	*addr, *mask;
18bc4097aaSchristos {
19bc4097aaSchristos #ifdef  USE_INET6
20bc4097aaSchristos 	char ipbuf[64];
21bc4097aaSchristos #else
22bc4097aaSchristos 	struct in_addr ipa;
23bc4097aaSchristos #endif
24bc4097aaSchristos 
25bc4097aaSchristos 	if ((family == -1) || ((!addr || !*addr) && (!mask || !*mask)))
26bc4097aaSchristos 		PRINTF("any");
27bc4097aaSchristos 	else {
28*f44489f8Sprlw1 #ifdef  USE_INET6
29bc4097aaSchristos 		void *ptr = addr;
30bc4097aaSchristos 
31bc4097aaSchristos 		PRINTF("%s", inet_ntop(family, ptr, ipbuf, sizeof(ipbuf)));
32bc4097aaSchristos #else
33bc4097aaSchristos 		ipa.s_addr = *addr;
34bc4097aaSchristos 		PRINTF("%s", inet_ntoa(ipa));
35bc4097aaSchristos #endif
36bc4097aaSchristos 		if (mask != NULL)
37bc4097aaSchristos 			printmask(family, mask);
38bc4097aaSchristos 	}
39bc4097aaSchristos }
40