xref: /freebsd/sbin/ipf/libipf/printaddr.c (revision efeb8bffe34422937c7f8df836afb5b817366d16)
141edb306SCy Schubert /*
241edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
341edb306SCy Schubert  *
441edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
541edb306SCy Schubert  *
641edb306SCy Schubert  * $Id$
741edb306SCy Schubert  */
841edb306SCy Schubert 
941edb306SCy Schubert #include "ipf.h"
1041edb306SCy Schubert 
1141edb306SCy Schubert void
printaddr(int family,int type,char * base,int ifidx,u_32_t * addr,u_32_t * mask)12*efeb8bffSCy Schubert printaddr(int family, int type, char *base, int ifidx, u_32_t *addr,
13*efeb8bffSCy Schubert 	u_32_t *mask)
1441edb306SCy Schubert {
1541edb306SCy Schubert 	char *suffix;
1641edb306SCy Schubert 
1741edb306SCy Schubert 	switch (type)
1841edb306SCy Schubert 	{
1941edb306SCy Schubert 	case FRI_BROADCAST :
2041edb306SCy Schubert 		suffix = "bcast";
2141edb306SCy Schubert 		break;
2241edb306SCy Schubert 
2341edb306SCy Schubert 	case FRI_DYNAMIC :
2441edb306SCy Schubert 		PRINTF("%s", base + ifidx);
2541edb306SCy Schubert 		printmask(family, mask);
2641edb306SCy Schubert 		suffix = NULL;
2741edb306SCy Schubert 		break;
2841edb306SCy Schubert 
2941edb306SCy Schubert 	case FRI_NETWORK :
3041edb306SCy Schubert 		suffix = "net";
3141edb306SCy Schubert 		break;
3241edb306SCy Schubert 
3341edb306SCy Schubert 	case FRI_NETMASKED :
3441edb306SCy Schubert 		suffix = "netmasked";
3541edb306SCy Schubert 		break;
3641edb306SCy Schubert 
3741edb306SCy Schubert 	case FRI_PEERADDR :
3841edb306SCy Schubert 		suffix = "peer";
3941edb306SCy Schubert 		break;
4041edb306SCy Schubert 
4141edb306SCy Schubert 	case FRI_LOOKUP :
4241edb306SCy Schubert 		suffix = NULL;
4341edb306SCy Schubert 		printlookup(base, (i6addr_t *)addr, (i6addr_t *)mask);
4441edb306SCy Schubert 		break;
4541edb306SCy Schubert 
4641edb306SCy Schubert 	case FRI_NONE :
4741edb306SCy Schubert 	case FRI_NORMAL :
4841edb306SCy Schubert 		printhostmask(family, addr, mask);
4941edb306SCy Schubert 		suffix = NULL;
5041edb306SCy Schubert 		break;
5141edb306SCy Schubert 	case FRI_RANGE :
5241edb306SCy Schubert 		printhost(family, addr);
5341edb306SCy Schubert 		putchar('-');
5441edb306SCy Schubert 		printhost(family, mask);
5541edb306SCy Schubert 		suffix = NULL;
5641edb306SCy Schubert 		break;
5741edb306SCy Schubert 	case FRI_SPLIT :
5841edb306SCy Schubert 		printhost(family, addr);
5941edb306SCy Schubert 		putchar(',');
6041edb306SCy Schubert 		printhost(family, mask);
6141edb306SCy Schubert 		suffix = NULL;
6241edb306SCy Schubert 		break;
6341edb306SCy Schubert 	default :
6441edb306SCy Schubert 		PRINTF("<%d>", type);
6541edb306SCy Schubert 		printmask(family, mask);
6641edb306SCy Schubert 		suffix = NULL;
6741edb306SCy Schubert 		break;
6841edb306SCy Schubert 	}
6941edb306SCy Schubert 
7041edb306SCy Schubert 	if (suffix != NULL) {
7141edb306SCy Schubert 		PRINTF("%s/%s", base + ifidx, suffix);
7241edb306SCy Schubert 	}
7341edb306SCy Schubert }
74