1 #include <sys/ioctl.h>
2 #include <stdio.h>
3 #include <netdb.h>
4 #include <errno.h>
5 #include <fcntl.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <rpc/rpc.h>
9 #include "librpc01.h"
10
11 int debug = 0;
12 int program = 2000333;
13 int version = 10;
14
15 void breakpoint(void);
16 void service_request(struct svc_req *rqstp, SVCXPRT * transp);
17
main(int argc,char * argv[])18 int main(int argc, char *argv[])
19 {
20 SVCXPRT *transp;
21 int i, n;
22
23 for (i = 1; i < argc; i++) {
24 if (!strcmp(argv[i], "-d"))
25 debug = 1;
26 if (!strcmp(argv[i], "-p")) {
27 if (++i >= argc) {
28 fprintf(stderr, "%s: -p requires an argument\n",
29 argv[0]);
30 exit(1);
31 }
32 n = sscanf(argv[i], "%d", &program);
33 if (n != 1) {
34 fprintf(stderr,
35 "%s: -p requires an numeric argument\n",
36 argv[0]);
37 exit(1);
38 }
39 }
40 if (!strcmp(argv[i], "-v")) {
41 if (++i >= argc) {
42 fprintf(stderr, "%s: -v requires an argument\n",
43 argv[0]);
44 exit(1);
45 }
46 n = sscanf(argv[i], "%d", &version);
47 if (n != 1) {
48 fprintf(stderr,
49 "%s: -v requires an numeric argument\n",
50 argv[0]);
51 exit(1);
52 }
53 }
54 }
55
56 if (!debug) {
57 if ((n = fork()) < 0) {
58 fprintf(stderr, "%s: Can't fork\n", argv[0]);
59 exit(1);
60 }
61
62 if (n > 0)
63 exit(0);
64
65 i = 50;
66 while (--i >= 0)
67 close(i);
68 open("/dev/null", O_RDONLY);
69 open("/dev/null", O_WRONLY);
70 i = dup(1);
71
72 if ((i = open("/dev/tty", O_RDWR)) >= 0) {
73 ioctl(i, TIOCNOTTY, 0);
74 close(i);
75 }
76 }
77
78 pmap_unset(program, version);
79 transp = svcudp_create(RPC_ANYSOCK);
80 svc_register(transp, program, version, service_request, IPPROTO_UDP);
81 transp = svctcp_create(RPC_ANYSOCK, 0, 0);
82 svc_register(transp, program, version, service_request, IPPROTO_TCP);
83 svc_run();
84 exit(1);
85 }
86
service_request(struct svc_req * rqstp,SVCXPRT * transp)87 void service_request(struct svc_req *rqstp, SVCXPRT * transp)
88 {
89 struct data *buffer;
90
91 switch (rqstp->rq_proc) {
92 case 0:
93 svc_sendreply(transp, (xdrproc_t)xdr_void, NULL);
94 breakpoint();
95 return;
96
97 case 99:
98 exit(0);
99
100 case 1:
101 svc_getargs(transp, (xdrproc_t)xdr_receive_data,
102 (char *)&buffer);
103 svc_sendreply(transp, (xdrproc_t)xdr_send_data,
104 (char *)buffer);
105 free(buffer->data);
106 free(buffer);
107 return;
108
109 default:
110 svcerr_noproc(transp);
111 return;
112 }
113 }
114
breakpoint(void)115 void breakpoint(void)
116 {
117 if (debug)
118 printf("breakpoint\n");
119 }
120