xref: /freebsd/sbin/ipf/libipf/printaddr.c (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1 /*
2  * Copyright (C) 2012 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id$
7  */
8 
9 #include "ipf.h"
10 
11 void
12 printaddr(int family, int type, char *base, int ifidx, u_32_t *addr,
13 	u_32_t *mask)
14 {
15 	char *suffix;
16 
17 	switch (type)
18 	{
19 	case FRI_BROADCAST :
20 		suffix = "bcast";
21 		break;
22 
23 	case FRI_DYNAMIC :
24 		PRINTF("%s", base + ifidx);
25 		printmask(family, mask);
26 		suffix = NULL;
27 		break;
28 
29 	case FRI_NETWORK :
30 		suffix = "net";
31 		break;
32 
33 	case FRI_NETMASKED :
34 		suffix = "netmasked";
35 		break;
36 
37 	case FRI_PEERADDR :
38 		suffix = "peer";
39 		break;
40 
41 	case FRI_LOOKUP :
42 		suffix = NULL;
43 		printlookup(base, (i6addr_t *)addr, (i6addr_t *)mask);
44 		break;
45 
46 	case FRI_NONE :
47 	case FRI_NORMAL :
48 		printhostmask(family, addr, mask);
49 		suffix = NULL;
50 		break;
51 	case FRI_RANGE :
52 		printhost(family, addr);
53 		putchar('-');
54 		printhost(family, mask);
55 		suffix = NULL;
56 		break;
57 	case FRI_SPLIT :
58 		printhost(family, addr);
59 		putchar(',');
60 		printhost(family, mask);
61 		suffix = NULL;
62 		break;
63 	default :
64 		PRINTF("<%d>", type);
65 		printmask(family, mask);
66 		suffix = NULL;
67 		break;
68 	}
69 
70 	if (suffix != NULL) {
71 		PRINTF("%s/%s", base + ifidx, suffix);
72 	}
73 }
74