Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.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 /*
9  * @(#) pmap_set.c 1.1 92/06/11 22:53:16
10  * $FreeBSD: src/usr.sbin/portmap/pmap_set/pmap_set.c,v 1.6 2000/01/15 23:08:30 brian Exp $
11  * $DragonFly: src/usr.sbin/portmap/pmap_set/pmap_set.c,v 1.2 2003/06/17 04:30:00 dillon Exp $
12  */
13 #include <err.h>
14 #include <stdio.h>
15 #include <sys/types.h>
16 #ifdef SYSV40
17 #include <netinet/in.h>
18 #endif
19 #include <rpc/rpc.h>
20 #include <rpc/pmap_clnt.h>
21
22 static int parse_line __P((char *, u_long *, u_long *, int *, unsigned *));
23
24 int
25 main(argc, argv)
26     int argc;
27     char **argv;
28 {
29     struct sockaddr_in addr;
30     char    buf[BUFSIZ];
31     u_long  prog;
32     u_long  vers;
33     int     prot;
34     unsigned port;
35
36     get_myaddress(&addr);
37
38     while (fgets(buf, sizeof(buf), stdin)) {
39         if (parse_line(buf, &prog, &vers, &prot, &port) == 0) {
40             warnx("malformed line: %s", buf);
41             return (1);
42         }
43         if (pmap_set(prog, vers, prot, (unsigned short) port) == 0)
44             warnx("not registered: %s", buf);
45     }
46     return (0);
47 }
48
49 /* parse_line - convert line to numbers */
50
51 static int
52 parse_line(buf, prog, vers, prot, port)
53     char *buf;
54     u_long *prog, *vers;
55     int *prot;
56     unsigned *port;
57 {
58     char    proto_name[BUFSIZ];
59
60     if (sscanf(buf, "%lu %lu %s %u", prog, vers, proto_name, port) != 4) {
61         return (0);
62     }
63     if (strcmp(proto_name, "tcp") == 0) {
64         *prot = IPPROTO_TCP;
65         return (1);
66     }
67     if (strcmp(proto_name, "udp") == 0) {
68         *prot = IPPROTO_UDP;
69         return (1);
70     }
71     if (sscanf(proto_name, "%d", prot) == 1) {
72         return (1);
73     }
74     return (0);
75 }