xref: /titanic_44/usr/src/cmd/ipf/lib/common/getportproto.c (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 #include <ctype.h>
2 #include "ipf.h"
3 
4 int getportproto(name, proto)
5 char *name;
6 int proto;
7 {
8 	struct servent *s;
9 	struct protoent *p;
10 
11 	if (isdigit(*name) && atoi(name) > 0)
12 		return htons(atoi(name) & 65535);
13 
14 	p = getprotobynumber(proto);
15 	if (p != NULL) {
16 		s = getservbyname(name, p->p_name);
17 		if (s != NULL)
18 			return s->s_port;
19 	}
20 	return 0;
21 }
22