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