Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / portmap / pmap_set.c
blob017a3593690b8c7e42432a7da99a9dc88e0ef54b
1 /*
2 * pmap_set - set portmapper table from data produced by pmap_dump
3 *
4 * Author: Wietse Venema (wietse@wzv.win.tue.nl), dept. of Mathematics and
5 * Computing Science, Eindhoven University of Technology, The Netherlands.
6 */
8 #include <stdio.h>
9 #include <sys/types.h>
10 #ifdef SYSV40
11 #include <netinet/in.h>
12 #endif
13 #include <rpc/rpc.h>
14 #include <rpc/pmap_clnt.h>
16 static int
17 parse_line(char *buf, u_long *prog, u_long *vers,
18 int *prot, unsigned *port);
20 int
21 main(int argc, char **argv)
23 char buf[BUFSIZ];
24 u_long prog;
25 u_long vers;
26 int prot;
27 unsigned port;
29 while (fgets(buf, sizeof(buf), stdin)) {
30 if (parse_line(buf, &prog, &vers, &prot, &port) == 0) {
31 fprintf(stderr, "%s: malformed line: %s", argv[0], buf);
32 return (1);
34 if (pmap_set(prog, vers, prot, (unsigned short) port) == 0)
35 fprintf(stderr, "not registered: %s", buf);
37 return (0);
40 /* parse_line - convert line to numbers */
42 static int
43 parse_line(char *buf, u_long *prog, u_long *vers,
44 int *prot, unsigned *port)
46 char proto_name[256];
48 if (sscanf(buf, "%lu %lu %255s %u", prog, vers, proto_name, port) != 4) {
49 return (0);
51 if (strcmp(proto_name, "tcp") == 0) {
52 *prot = IPPROTO_TCP;
53 return (1);
55 if (strcmp(proto_name, "udp") == 0) {
56 *prot = IPPROTO_UDP;
57 return (1);
59 if (sscanf(proto_name, "%d", prot) == 1) {
60 return (1);
62 return (0);