NetBSD/dist/ipf/lib/getportproto.c

22 lines
403 B
C
Raw Normal View History

/* $NetBSD: getportproto.c,v 1.4 2004/11/13 19:16:10 he Exp $ */
2004-03-28 12:55:20 +04:00
#include <ctype.h>
#include "ipf.h"
int getportproto(name, proto)
char *name;
int proto;
{
struct servent *s;
struct protoent *p;
if (ISDIGIT(*name) && atoi(name) > 0)
2004-03-28 12:55:20 +04:00
return htons(atoi(name) & 65535);
p = getprotobynumber(proto);
2004-07-23 09:33:55 +04:00
s = getservbyname(name, p ? p->p_name : NULL);
if (s != NULL)
return s->s_port;
2004-03-28 12:55:20 +04:00
return 0;
}