]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/portmap/pmap_set/pmap_set.c
This commit was generated by cvs2svn to compensate for changes in r55682,
[FreeBSD/FreeBSD.git] / usr.sbin / portmap / pmap_set / pmap_set.c
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   */
7
8 #ifndef lint
9 #if 0
10 static char sccsid[] = "@(#) pmap_set.c 1.1 92/06/11 22:53:16";
11 #endif
12 static const char rcsid[] =
13   "$FreeBSD$";
14 #endif
15
16 #include <err.h>
17 #include <stdio.h>
18 #include <sys/types.h>
19 #ifdef SYSV40
20 #include <netinet/in.h>
21 #endif
22 #include <rpc/rpc.h>
23 #include <rpc/pmap_clnt.h>
24
25 int parse_line __P((char *, u_long *, u_long *, int *, unsigned *));
26
27 int
28 main(argc, argv)
29 int     argc;
30 char  **argv;
31 {
32     struct sockaddr_in addr;
33     char    buf[BUFSIZ];
34     u_long  prog;
35     u_long  vers;
36     int     prot;
37     unsigned port;
38
39     get_myaddress(&addr);
40
41     while (fgets(buf, sizeof(buf), stdin)) {
42         if (parse_line(buf, &prog, &vers, &prot, &port) == 0) {
43             warnx("malformed line: %s", buf);
44             return (1);
45         }
46         if (pmap_set(prog, vers, prot, (unsigned short) port) == 0)
47             warnx("not registered: %s", buf);
48     }
49     return (0);
50 }
51
52 /* parse_line - convert line to numbers */
53
54 int
55 parse_line(buf, prog, vers, prot, port)
56 char   *buf;
57 u_long *prog;
58 u_long *vers;
59 int    *prot;
60 unsigned *port;
61 {
62     char    proto_name[BUFSIZ];
63
64     if (sscanf(buf, "%lu %lu %s %u", prog, vers, proto_name, port) != 4) {
65         return (0);
66     }
67     if (strcmp(proto_name, "tcp") == 0) {
68         *prot = IPPROTO_TCP;
69         return (1);
70     }
71     if (strcmp(proto_name, "udp") == 0) {
72         *prot = IPPROTO_UDP;
73         return (1);
74     }
75     if (sscanf(proto_name, "%d", prot) == 1) {
76         return (1);
77     }
78     return (0);
79 }