xref: /netbsd-src/external/bsd/ipf/dist/lib/printproto.c (revision 07967fb18af5b87d2d477c5b3e1e438bf0c293fb)
1*07967fb1Smrg /*	$NetBSD: printproto.c,v 1.3 2018/02/04 08:19:42 mrg Exp $	*/
2bc4097aaSchristos 
3bc4097aaSchristos /*
4c9d5dc6cSdarrenr  * Copyright (C) 2012 by Darren Reed.
5bc4097aaSchristos  *
6bc4097aaSchristos  * See the IPFILTER.LICENCE file for details on licencing.
7bc4097aaSchristos  */
8bc4097aaSchristos 
9bc4097aaSchristos #include "ipf.h"
10bc4097aaSchristos 
11bc4097aaSchristos 
12bc4097aaSchristos #if !defined(lint)
13*07967fb1Smrg static __attribute__((__used__)) const char rcsid[] = "@(#)Id: printproto.c,v 1.1.1.2 2012/07/22 13:44:42 darrenr Exp $";
14bc4097aaSchristos #endif
15bc4097aaSchristos 
16bc4097aaSchristos 
17bc4097aaSchristos void
printproto(pr,p,np)18bc4097aaSchristos printproto(pr, p, np)
19bc4097aaSchristos 	struct protoent *pr;
20bc4097aaSchristos 	int p;
21bc4097aaSchristos 	ipnat_t *np;
22bc4097aaSchristos {
23bc4097aaSchristos 	if (np != NULL) {
24bc4097aaSchristos 		if ((np->in_flags & IPN_TCPUDP) == IPN_TCPUDP)
25bc4097aaSchristos 			PRINTF("tcp/udp");
26bc4097aaSchristos 		else if (np->in_flags & IPN_TCP)
27bc4097aaSchristos 			PRINTF("tcp");
28bc4097aaSchristos 		else if (np->in_flags & IPN_UDP)
29bc4097aaSchristos 			PRINTF("udp");
30bc4097aaSchristos 		else if (np->in_flags & IPN_ICMPQUERY)
31bc4097aaSchristos 			PRINTF("icmp");
32bc4097aaSchristos #ifdef _AIX51
33bc4097aaSchristos 		/*
34bc4097aaSchristos 		 * To make up for "ip = 252" and "hopopt = 0" in /etc/protocols
35bc4097aaSchristos 		 * The IANA has doubled up on the definition of 0 - it is now
36bc4097aaSchristos 		 * also used for IPv6 hop-opts, so we can no longer rely on
37bc4097aaSchristos 		 * /etc/protocols providing the correct name->number mapping.
38bc4097aaSchristos 		 */
39bc4097aaSchristos #endif
40bc4097aaSchristos 		else if (np->in_pr[0] == 0)
41bc4097aaSchristos 			PRINTF("ip");
42bc4097aaSchristos 		else if (pr != NULL)
43bc4097aaSchristos 			PRINTF("%s", pr->p_name);
44bc4097aaSchristos 		else
45bc4097aaSchristos 			PRINTF("%d", np->in_pr[0]);
46bc4097aaSchristos 	} else {
47bc4097aaSchristos #ifdef _AIX51
48bc4097aaSchristos 		if (p == 0)
49bc4097aaSchristos 			PRINTF("ip");
50bc4097aaSchristos 		else
51bc4097aaSchristos #endif
52bc4097aaSchristos 		if (pr != NULL)
53bc4097aaSchristos 			PRINTF("%s", pr->p_name);
54bc4097aaSchristos 		else
55bc4097aaSchristos 			PRINTF("%d", p);
56bc4097aaSchristos 	}
57bc4097aaSchristos }
58