xref: /freebsd/sbin/ipf/libipf/printip.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
printip(int family,u_32_t * addr)14*efeb8bffSCy Schubert printip(int family, u_32_t *addr)
1541edb306SCy Schubert {
1641edb306SCy Schubert 	struct in_addr ipa;
1741edb306SCy Schubert 
1841edb306SCy Schubert 	if (family == AF_INET) {
1941edb306SCy Schubert 		ipa.s_addr = *addr;
2041edb306SCy Schubert 		if (ntohl(ipa.s_addr) < 256)
2141edb306SCy Schubert 			PRINTF("%lu", (u_long)ntohl(ipa.s_addr));
2241edb306SCy Schubert 		else
2341edb306SCy Schubert 			PRINTF("%s", inet_ntoa(ipa));
2441edb306SCy Schubert 	}
2541edb306SCy Schubert #ifdef USE_INET6
2641edb306SCy Schubert 	else if (family == AF_INET6) {
2741edb306SCy Schubert 		char buf[INET6_ADDRSTRLEN + 1];
2841edb306SCy Schubert 		const char *str;
2941edb306SCy Schubert 
3041edb306SCy Schubert 		buf[0] = '\0';
3141edb306SCy Schubert 		str = inet_ntop(AF_INET6, addr, buf, sizeof(buf) - 1);
3241edb306SCy Schubert 		if (str != NULL)
3341edb306SCy Schubert 			PRINTF("%s", str);
3441edb306SCy Schubert 		else
3541edb306SCy Schubert 			PRINTF("???");
3641edb306SCy Schubert 	}
3741edb306SCy Schubert #endif
3841edb306SCy Schubert 	else
3941edb306SCy Schubert 		PRINTF("?(%d)?", family);
4041edb306SCy Schubert }
41