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