xref: /trueos/contrib/ipfilter/lib/printproto.c (revision d5d1038c7e8fb81fcbf4d3e4d444d685e4af1e4b)
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
printproto(pr,p,np)16 printproto(pr, p, np)
17 	struct protoent *pr;
18 	int p;
19 	ipnat_t *np;
20 {
21 	if (np != NULL) {
22 		if ((np->in_flags & IPN_TCPUDP) == IPN_TCPUDP)
23 			PRINTF("tcp/udp");
24 		else if (np->in_flags & IPN_TCP)
25 			PRINTF("tcp");
26 		else if (np->in_flags & IPN_UDP)
27 			PRINTF("udp");
28 		else if (np->in_flags & IPN_ICMPQUERY)
29 			PRINTF("icmp");
30 #ifdef _AIX51
31 		/*
32 		 * To make up for "ip = 252" and "hopopt = 0" in /etc/protocols
33 		 * The IANA has doubled up on the definition of 0 - it is now
34 		 * also used for IPv6 hop-opts, so we can no longer rely on
35 		 * /etc/protocols providing the correct name->number mapping.
36 		 */
37 #endif
38 		else if (np->in_pr[0] == 0)
39 			PRINTF("ip");
40 		else if (pr != NULL)
41 			PRINTF("%s", pr->p_name);
42 		else
43 			PRINTF("%d", np->in_pr[0]);
44 	} else {
45 #ifdef _AIX51
46 		if (p == 0)
47 			PRINTF("ip");
48 		else
49 #endif
50 		if (pr != NULL)
51 			PRINTF("%s", pr->p_name);
52 		else
53 			PRINTF("%d", p);
54 	}
55 }
56