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