1 /* $NetBSD: sprayd.c,v 1.14 2006/05/09 20:18:07 mrg Exp $ */
4 * Copyright (c) 1994 Christos Zoulas
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
30 __RCSID("$NetBSD: sprayd.c,v 1.14 2006/05/09 20:18:07 mrg Exp $");
38 #include <sys/socket.h>
41 #include <rpcsvc/spray.h>
43 static void cleanup(int);
45 static void spray_service(struct svc_req
*, SVCXPRT
*);
47 int main(int, char *[]);
49 static int from_inetd
= 1;
57 (void)rpcb_unset(SPRAYPROG
, SPRAYVERS
, NULL
);
69 main(int argc
, char *argv
[])
72 struct sockaddr_storage from
;
76 * See if inetd started us
78 fromlen
= sizeof(from
);
79 if (getsockname(0, (struct sockaddr
*)&from
, &fromlen
) < 0)
85 (void)rpcb_unset(SPRAYPROG
, SPRAYVERS
, NULL
);
87 (void)signal(SIGINT
, cleanup
);
88 (void)signal(SIGTERM
, cleanup
);
89 (void)signal(SIGHUP
, cleanup
);
91 (void)signal(SIGALRM
, die
);
95 openlog("rpc.sprayd", LOG_PID
, LOG_DAEMON
);
98 transp
= svc_dg_create(0, 0, 0);
100 syslog(LOG_ERR
, "cannot create udp service.");
103 if (!svc_reg(transp
, SPRAYPROG
, SPRAYVERS
, spray_service
,
106 "unable to register (SPRAYPROG, SPRAYVERS).");
110 if (!svc_create(spray_service
, SPRAYPROG
, SPRAYVERS
, "udp")) {
112 "unable to register (SPRAYPROG, SPRAYVERS).");
118 syslog(LOG_ERR
, "svc_run returned");
124 spray_service(struct svc_req
*rqstp
, SVCXPRT
*transp
)
126 static spraycumul scum
;
127 static struct timeval clear
, get
;
129 switch (rqstp
->rq_proc
) {
130 case SPRAYPROC_CLEAR
:
132 (void)gettimeofday(&clear
, 0);
136 (void)svc_sendreply(transp
, xdr_void
, (char *)NULL
);
139 case SPRAYPROC_SPRAY
:
144 (void)gettimeofday(&get
, 0);
145 timersub(&get
, &clear
, &get
);
146 scum
.clock
.sec
= get
.tv_sec
;
147 scum
.clock
.usec
= get
.tv_usec
;
151 svcerr_noproc(transp
);
155 if (!svc_sendreply(transp
, xdr_spraycumul
, (caddr_t
)&scum
)) {
156 svcerr_systemerr(transp
);
157 syslog(LOG_WARNING
, "bad svc_sendreply");