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