xref: /illumos-gate/usr/src/cmd/ipf/lib/common/getproto.c (revision ab25eeb5)
1*ab25eeb5Syz /*
2*ab25eeb5Syz  * Copyright (C) 1993-2005  by Darren Reed.
3*ab25eeb5Syz  * See the IPFILTER.LICENCE file for details on licencing.
4*ab25eeb5Syz  */
5*ab25eeb5Syz 
67c478bd9Sstevel@tonic-gate #include "ipf.h"
77c478bd9Sstevel@tonic-gate 
getproto(name)87c478bd9Sstevel@tonic-gate int getproto(name)
97c478bd9Sstevel@tonic-gate char *name;
107c478bd9Sstevel@tonic-gate {
117c478bd9Sstevel@tonic-gate 	struct protoent *p;
127c478bd9Sstevel@tonic-gate 	char *s;
137c478bd9Sstevel@tonic-gate 
147c478bd9Sstevel@tonic-gate 	for (s = name; *s != '\0'; s++)
15*ab25eeb5Syz 		if (!ISDIGIT(*s))
167c478bd9Sstevel@tonic-gate 			break;
177c478bd9Sstevel@tonic-gate 	if (*s == '\0')
187c478bd9Sstevel@tonic-gate 		return atoi(name);
197c478bd9Sstevel@tonic-gate 
20*ab25eeb5Syz #ifdef _AIX51
21*ab25eeb5Syz 	/*
22*ab25eeb5Syz 	 * For some bogus reason, "ip" is 252 in /etc/protocols on AIX 5
23*ab25eeb5Syz 	 */
24*ab25eeb5Syz 	if (!strcasecmp(name, "ip"))
25*ab25eeb5Syz 		return 0;
26*ab25eeb5Syz #endif
27*ab25eeb5Syz 
287c478bd9Sstevel@tonic-gate 	p = getprotobyname(name);
297c478bd9Sstevel@tonic-gate 	if (p != NULL)
307c478bd9Sstevel@tonic-gate 		return p->p_proto;
317c478bd9Sstevel@tonic-gate 	return -1;
327c478bd9Sstevel@tonic-gate }
33