xref: /titanic_41/usr/src/cmd/ipf/lib/common/getportproto.c (revision 25cf1a301a396c38e8adf52c15f537b80d2483f7)
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