xref: /freebsd/sbin/ipf/libipf/printip.c (revision 734e82fe33aa764367791a7d603b383996c6b40b)
1 
2 /*
3  * Copyright (C) 2012 by Darren Reed.
4  *
5  * See the IPFILTER.LICENCE file for details on licencing.
6  *
7  * $Id$
8  */
9 
10 #include "ipf.h"
11 
12 
13 void
14 printip(int family, u_32_t *addr)
15 {
16 	struct in_addr ipa;
17 
18 	if (family == AF_INET) {
19 		ipa.s_addr = *addr;
20 		if (ntohl(ipa.s_addr) < 256)
21 			PRINTF("%lu", (u_long)ntohl(ipa.s_addr));
22 		else
23 			PRINTF("%s", inet_ntoa(ipa));
24 	}
25 #ifdef USE_INET6
26 	else if (family == AF_INET6) {
27 		char buf[INET6_ADDRSTRLEN + 1];
28 		const char *str;
29 
30 		buf[0] = '\0';
31 		str = inet_ntop(AF_INET6, addr, buf, sizeof(buf) - 1);
32 		if (str != NULL)
33 			PRINTF("%s", str);
34 		else
35 			PRINTF("???");
36 	}
37 #endif
38 	else
39 		PRINTF("?(%d)?", family);
40 }
41