xref: /freebsd/sbin/ipf/libipf/printproto.c (revision 81ad6265)
1 /*
2  * Copyright (C) 2012 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  */
6 
7 #include "ipf.h"
8 
9 
10 #if !defined(lint)
11 static const char rcsid[] = "@(#)$Id$";
12 #endif
13 
14 
15 void
16 printproto(struct protoent *pr, int p, ipnat_t *np)
17 {
18 	if (np != NULL) {
19 		if ((np->in_flags & IPN_TCPUDP) == IPN_TCPUDP)
20 			PRINTF("tcp/udp");
21 		else if (np->in_flags & IPN_TCP)
22 			PRINTF("tcp");
23 		else if (np->in_flags & IPN_UDP)
24 			PRINTF("udp");
25 		else if (np->in_flags & IPN_ICMPQUERY)
26 			PRINTF("icmp");
27 		else if (np->in_pr[0] == 0)
28 			PRINTF("ip");
29 		else if (pr != NULL)
30 			PRINTF("%s", pr->p_name);
31 		else
32 			PRINTF("%d", np->in_pr[0]);
33 	} else {
34 		if (pr != NULL)
35 			PRINTF("%s", pr->p_name);
36 		else
37 			PRINTF("%d", p);
38 	}
39 }
40