2004-03-28 12:55:20 +04:00
|
|
|
#include "ipf.h"
|
|
|
|
|
2005-04-03 19:05:30 +04:00
|
|
|
int getport(fr, name, port)
|
2004-07-08 06:51:24 +04:00
|
|
|
frentry_t *fr;
|
2004-03-28 12:55:20 +04:00
|
|
|
char *name;
|
2005-04-03 19:05:30 +04:00
|
|
|
u_short *port;
|
2004-03-28 12:55:20 +04:00
|
|
|
{
|
2004-07-08 06:51:24 +04:00
|
|
|
struct protoent *p;
|
2004-03-28 12:55:20 +04:00
|
|
|
struct servent *s;
|
2004-07-08 06:51:24 +04:00
|
|
|
u_short p1;
|
|
|
|
|
|
|
|
if (fr == NULL || fr->fr_type != FR_T_IPF) {
|
|
|
|
s = getservbyname(name, NULL);
|
2005-04-03 19:05:30 +04:00
|
|
|
if (s != NULL) {
|
|
|
|
*port = s->s_port;
|
|
|
|
return 0;
|
|
|
|
}
|
2004-07-23 09:39:03 +04:00
|
|
|
return -1;
|
2004-07-08 06:51:24 +04:00
|
|
|
}
|
2004-03-28 12:55:20 +04:00
|
|
|
|
2004-07-08 06:51:24 +04:00
|
|
|
if ((fr->fr_flx & FI_TCPUDP) != 0) {
|
|
|
|
/*
|
|
|
|
* If a rule is "tcp/udp" then check that both TCP and UDP
|
|
|
|
* mappings for this protocol name match ports.
|
|
|
|
*/
|
|
|
|
s = getservbyname(name, "tcp");
|
|
|
|
if (s == NULL)
|
2004-07-23 09:39:03 +04:00
|
|
|
return -1;
|
2004-07-08 06:51:24 +04:00
|
|
|
p1 = s->s_port;
|
|
|
|
s = getservbyname(name, "udp");
|
|
|
|
if (s == NULL || s->s_port != p1)
|
2004-07-23 09:39:03 +04:00
|
|
|
return -1;
|
2005-04-03 19:05:30 +04:00
|
|
|
*port = p1;
|
|
|
|
return 0;
|
2004-07-08 06:51:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
p = getprotobynumber(fr->fr_proto);
|
|
|
|
s = getservbyname(name, p ? p->p_name : NULL);
|
2005-04-03 19:05:30 +04:00
|
|
|
if (s != NULL) {
|
|
|
|
*port = s->s_port;
|
|
|
|
return 0;
|
|
|
|
}
|
2004-07-23 09:39:03 +04:00
|
|
|
return -1;
|
2004-03-28 12:55:20 +04:00
|
|
|
}
|