2005-04-25 18:20:15 +00:00
|
|
|
/* $FreeBSD$ */
|
2005-04-25 17:31:50 +00:00
|
|
|
|
2007-06-04 02:54:36 +00:00
|
|
|
/*
|
2013-08-11 14:28:45 +00:00
|
|
|
* Copyright (C) 2012 by Darren Reed.
|
|
|
|
*
|
|
|
|
* See the IPFILTER.LICENCE file for details on licencing.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
2007-06-04 02:54:36 +00:00
|
|
|
|
2005-04-25 17:31:50 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include "ipf.h"
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
int
|
|
|
|
getportproto(char *name, int proto)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
struct servent *s;
|
|
|
|
struct protoent *p;
|
|
|
|
|
|
|
|
if (ISDIGIT(*name)) {
|
|
|
|
int number;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
for (s = name; *s != '\0'; s++)
|
|
|
|
if (!ISDIGIT(*s))
|
2022-01-04 02:49:18 +00:00
|
|
|
return (-1);
|
2005-04-25 17:31:50 +00:00
|
|
|
|
|
|
|
number = atoi(name);
|
|
|
|
if (number < 0 || number > 65535)
|
2022-01-04 02:49:18 +00:00
|
|
|
return (-1);
|
|
|
|
return (htons(number));
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p = getprotobynumber(proto);
|
|
|
|
s = getservbyname(name, p ? p->p_name : NULL);
|
|
|
|
if (s != NULL)
|
2022-01-04 02:49:18 +00:00
|
|
|
return (s->s_port);
|
|
|
|
return (-1);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|