Add PCICAP_{ID,NEXTPTR} to avoid using magic number
[dragonfly.git] / usr.sbin / portmap / pmap_set / pmap_set.c
blobdd505ea1c1139997d37c363d9cdfdac1d85afaa5
1 /*
2 * pmap_set - set portmapper table from data produced by pmap_dump
4 * Author: Wietse Venema (wietse@wzv.win.tue.nl), dept. of Mathematics and
5 * Computing Science, Eindhoven University of Technology, The Netherlands.
6 */
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.4 2004/03/30 02:59:00 cpressey Exp $
14 #include <sys/types.h>
15 #ifdef SYSV40
16 #include <netinet/in.h>
17 #endif
18 #include <rpc/rpc.h>
19 #include <rpc/pmap_clnt.h>
21 #include <err.h>
22 #include <stdio.h>
24 static int parse_line(char *, u_long *, u_long *, int *, unsigned *);
26 int
27 main(int argc, char **argv)
29 struct sockaddr_in addr;
30 char buf[BUFSIZ];
31 u_long prog;
32 u_long vers;
33 int prot;
34 unsigned port;
36 get_myaddress(&addr);
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);
43 if (pmap_set(prog, vers, prot, (unsigned short)port) == 0)
44 warnx("not registered: %s", buf);
46 return (0);
49 /* parse_line - convert line to numbers */
51 static int
52 parse_line(char *buf, u_long *prog, u_long *vers, int *prot,
53 unsigned int *port)
55 char proto_name[BUFSIZ];
57 if (sscanf(buf, "%lu %lu %s %u", prog, vers, proto_name, port) != 4) {
58 return (0);
60 if (strcmp(proto_name, "tcp") == 0) {
61 *prot = IPPROTO_TCP;
62 return (1);
64 if (strcmp(proto_name, "udp") == 0) {
65 *prot = IPPROTO_UDP;
66 return (1);
68 if (sscanf(proto_name, "%d", prot) == 1) {
69 return (1);
71 return (0);