2 * Copyright (C) 1993-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
7 * $Id: portnum.c,v 1.6.4.1 2004/12/09 19:41:22 darrenr Exp $
16 * find the port number given by the name, either from getservbyname() or
17 * straight atoi(). Return 1 on success, 0 on failure
19 int portnum(name
, proto
, port
, linenum
)
24 struct servent
*sp
, *sp2
;
29 if (ratoi(name
, &i
, 0, USHRT_MAX
)) {
33 fprintf(stderr
, "%d: unknown port \"%s\"\n", linenum
, name
);
36 if (proto
!= NULL
&& strcasecmp(proto
, "tcp/udp") != 0) {
37 sp
= getservbyname(name
, proto
);
39 *port
= ntohs(sp
->s_port
);
42 fprintf(stderr
, "%d: unknown service \"%s\".\n", linenum
, name
);
45 sp
= getservbyname(name
, "tcp");
48 sp2
= getservbyname(name
, "udp");
50 fprintf(stderr
, "%d: unknown tcp/udp service \"%s\".\n",
54 if (p1
!= sp2
->s_port
) {
55 fprintf(stderr
, "%d: %s %d/tcp is a different port to ",
57 fprintf(stderr
, "%d: %s %d/udp\n", linenum
, name
, sp
->s_port
);