1*13885a66Sdarrenr /* $NetBSD: printip.c,v 1.2 2012/07/22 14:27:36 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: printip.c,v 1.1.1.2 2012/07/22 13:44:40 darrenr Exp $
9bc4097aaSchristos */
10bc4097aaSchristos
11bc4097aaSchristos #include "ipf.h"
12bc4097aaSchristos
13bc4097aaSchristos
14bc4097aaSchristos void
printip(family,addr)15bc4097aaSchristos printip(family, addr)
16bc4097aaSchristos int family;
17bc4097aaSchristos u_32_t *addr;
18bc4097aaSchristos {
19bc4097aaSchristos struct in_addr ipa;
20bc4097aaSchristos
21bc4097aaSchristos if (family == AF_INET) {
22bc4097aaSchristos ipa.s_addr = *addr;
23bc4097aaSchristos if (ntohl(ipa.s_addr) < 256)
24bc4097aaSchristos PRINTF("%lu", (u_long)ntohl(ipa.s_addr));
25bc4097aaSchristos else
26bc4097aaSchristos PRINTF("%s", inet_ntoa(ipa));
27bc4097aaSchristos }
28bc4097aaSchristos #ifdef AF_INET6
29bc4097aaSchristos else if (family == AF_INET6) {
30bc4097aaSchristos char buf[INET6_ADDRSTRLEN + 1];
31bc4097aaSchristos const char *str;
32bc4097aaSchristos
33bc4097aaSchristos buf[0] = '\0';
34bc4097aaSchristos str = inet_ntop(AF_INET6, addr, buf, sizeof(buf) - 1);
35bc4097aaSchristos if (str != NULL)
36bc4097aaSchristos PRINTF("%s", str);
37bc4097aaSchristos else
38bc4097aaSchristos PRINTF("???");
39bc4097aaSchristos }
40bc4097aaSchristos #endif
41bc4097aaSchristos else
42bc4097aaSchristos PRINTF("?(%d)?", family);
43bc4097aaSchristos }
44