1 /* $Slackware: inetd.c 1.79s 2001/02/06 13:18:00 volkerdi Exp $ */
2 /* $OpenBSD: inetd.c,v 1.79 2001/01/30 08:30:57 deraadt Exp $ */
3 /* $NetBSD: inetd.c,v 1.11 1996/02/22 11:14:41 mycroft Exp $ */
4 /* Busybox port by Vladimir Oleynik (C) 2001-2005 <dzo@simtreas.ru> */
6 * Copyright (c) 1983,1991 The Regents of the University of California.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * Inetd - Internet super-server
41 * This program invokes all internet services as needed.
42 * connection-oriented services are invoked each time a
43 * connection is made, by creating a process. This process
44 * is passed the connection as file descriptor 0 and is
45 * expected to do a getpeername to find out the source host
48 * Datagram oriented services are invoked when a datagram
49 * arrives; a process is created and passed a pending message
50 * on file descriptor 0. Datagram servers may either connect
51 * to their peer, freeing up the original socket for inetd
52 * to receive further messages on, or ``take over the socket'',
53 * processing all arriving datagrams and, eventually, timing
54 * out. The first type of server is said to be ``multi-threaded'';
55 * the second type of server ``single-threaded''.
57 * Inetd uses a configuration file which is read at startup
58 * and, possibly, at some later time in response to a hangup signal.
59 * The configuration file is ``free format'' with fields given in the
60 * order shown below. Continuation lines for an entry must begin with
61 * a space or tab. All fields must be present in each entry.
63 * service name must be in /etc/services
64 * socket type stream/dgram/raw/rdm/seqpacket
65 * protocol must be in /etc/protocols
66 * wait/nowait[.max] single-threaded/multi-threaded, max #
67 * user[.group] or user[:group] user/group to run daemon as
68 * server program full path name
69 * server program arguments maximum of MAXARGS (20)
72 * service name/version must be in /etc/rpc
73 * socket type stream/dgram/raw/rdm/seqpacket
74 * protocol must be in /etc/protocols
75 * wait/nowait[.max] single-threaded/multi-threaded
76 * user[.group] or user[:group] user to run daemon as
77 * server program full path name
78 * server program arguments maximum of MAXARGS (20)
80 * For non-RPC services, the "service name" can be of the form
81 * hostaddress:servicename, in which case the hostaddress is used
82 * as the host portion of the address to listen on. If hostaddress
83 * consists of a single `*' character, INADDR_ANY is used.
85 * A line can also consist of just
87 * where hostaddress is as in the preceding paragraph. Such a line must
88 * have no further fields; the specified hostaddress is remembered and
89 * used for all further lines that have no hostaddress specified,
90 * until the next such line (or EOF). (This is why * is provided to
91 * allow explicit specification of INADDR_ANY.) A line
93 * is implicitly in effect at the beginning of the file.
95 * The hostaddress specifier may (and often will) contain dots;
96 * the service name must not.
98 * For RPC services, host-address specifiers are accepted and will
99 * work to some extent; however, because of limitations in the
100 * portmapper interface, it will not work to try to give more than
101 * one line for any given RPC service, even if the host-address
102 * specifiers are different.
104 * Comment lines are indicated by a `#' in column 1.
108 * Here's the scoop concerning the user[.:]group feature:
110 * 1) set-group-option off.
112 * a) user = root: NO setuid() or setgid() is done
114 * b) other: setgid(primary group as found in passwd)
115 * initgroups(name, primary group)
118 * 2) set-group-option on.
120 * a) user = root: setgid(specified group)
124 * b) other: setgid(specified group)
125 * initgroups(name, specified group)
130 #include <sys/param.h>
131 #include <sys/stat.h>
132 #include <sys/ioctl.h>
133 #include <sys/socket.h>
135 #include <sys/file.h>
136 #include <sys/wait.h>
137 #include <sys/time.h>
138 #include <sys/resource.h>
141 #include <netinet/in.h>
142 #include <arpa/inet.h>
157 //#define CONFIG_FEATURE_INETD_RPC
158 //#define CONFIG_FEATURE_INETD_SUPPORT_BILTIN_ECHO
159 //#define CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DISCARD
160 //#define CONFIG_FEATURE_INETD_SUPPORT_BILTIN_TIME
161 //#define CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DAYTIME
162 //#define CONFIG_FEATURE_INETD_SUPPORT_BILTIN_CHARGEN
163 //#define CONFIG_FEATURE_IPV6
165 #ifdef CONFIG_FEATURE_INETD_RPC
167 #include <rpc/pmap_clnt.h>
168 #include <rpcsvc/nfs_prot.h>
171 #define _PATH_INETDCONF "/etc/inetd.conf"
172 #define _PATH_INETDPID "/var/run/inetd.pid"
175 #define TOOMANY 0 /* don't start more than TOOMANY */
177 #define CNT_INTVL 60 /* servers in CNT_INTVL sec. */
178 #define RETRYTIME (60*10) /* retry after bind or server fail */
180 #define SIGBLOCK (sigmask(SIGCHLD)|sigmask(SIGHUP)|sigmask(SIGALRM))
182 #ifndef RLIMIT_NOFILE
183 #define RLIMIT_NOFILE RLIMIT_OFILE
190 /* Reserve some descriptors, 3 stdio + at least: 1 log, 1 conf. file */
191 #define FD_MARGIN (8)
192 static rlim_t rlim_ofile_cur = OPEN_MAX;
193 static struct rlimit rlim_ofile;
196 /* Check unsupporting builtin */
197 #if defined CONFIG_FEATURE_INETD_SUPPORT_BILTIN_ECHO || \
198 defined CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DISCARD || \
199 defined CONFIG_FEATURE_INETD_SUPPORT_BILTIN_TIME || \
200 defined CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DAYTIME || \
201 defined CONFIG_FEATURE_INETD_SUPPORT_BILTIN_CHARGEN
202 # define INETD_FEATURE_ENABLED
205 #if defined CONFIG_FEATURE_INETD_SUPPORT_BILTIN_ECHO || \
206 defined CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DISCARD || \
207 defined CONFIG_FEATURE_INETD_SUPPORT_BILTIN_CHARGEN
208 # define INETD_SETPROCTITLE
211 typedef struct servtab
213 char *se_hostaddr; /* host address to listen on */
214 char *se_service; /* name of service */
215 int se_socktype; /* type of socket to use */
216 int se_family; /* address family */
217 char *se_proto; /* protocol used */
218 #ifdef CONFIG_FEATURE_INETD_RPC
219 int se_rpcprog; /* rpc program number */
220 int se_rpcversl; /* rpc program lowest version */
221 int se_rpcversh; /* rpc program highest version */
222 #define isrpcservice(sep) ((sep)->se_rpcversl != 0)
224 #define isrpcservice(sep) 0
226 pid_t se_wait; /* single threaded server */
227 short se_checked; /* looked at during merge */
228 char *se_user; /* user name to run as */
229 char *se_group; /* group name to run as */
230 #ifdef INETD_FEATURE_ENABLED
231 const struct biltin *se_bi; /* if built-in, description */
233 char *se_server; /* server program */
235 char *se_argv[MAXARGV + 1]; /* program arguments */
236 int se_fd; /* open descriptor */
239 struct sockaddr se_un_ctrladdr;
240 struct sockaddr_in se_un_ctrladdr_in;
241 #ifdef CONFIG_FEATURE_IPV6
242 struct sockaddr_in6 se_un_ctrladdr_in6;
244 struct sockaddr_un se_un_ctrladdr_un;
245 } se_un; /* bound address */
246 #define se_ctrladdr se_un.se_un_ctrladdr
247 #define se_ctrladdr_in se_un.se_un_ctrladdr_in
248 #define se_ctrladdr_in6 se_un.se_un_ctrladdr_in6
249 #define se_ctrladdr_un se_un.se_un_ctrladdr_un
250 int se_ctrladdr_size;
251 int se_max; /* max # of instances of this service */
252 int se_count; /* number started since se_time */
253 struct timeval se_time; /* start of se_count */
254 struct servtab *se_next;
257 static servtab_t *servtab;
259 #ifdef INETD_FEATURE_ENABLED
262 const char *bi_service; /* internally provided service name */
263 int bi_socktype; /* type of socket supported */
264 short bi_fork; /* 1 if should fork before call */
265 short bi_wait; /* 1 if should wait for child */
266 void (*bi_fn) (int, servtab_t *);
269 /* Echo received data */
270 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_ECHO
271 static void echo_stream (int, servtab_t *);
272 static void echo_dg (int, servtab_t *);
274 /* Internet /dev/null */
275 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DISCARD
276 static void discard_stream (int, servtab_t *);
277 static void discard_dg (int, servtab_t *);
279 /* Return 32 bit time since 1900 */
280 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_TIME
281 static void machtime_stream (int, servtab_t *);
282 static void machtime_dg (int, servtab_t *);
284 /* Return human-readable time */
285 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DAYTIME
286 static void daytime_stream (int, servtab_t *);
287 static void daytime_dg (int, servtab_t *);
289 /* Familiar character generator */
290 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_CHARGEN
291 static void chargen_stream (int, servtab_t *);
292 static void chargen_dg (int, servtab_t *);
295 static const struct biltin biltins[] = {
296 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_ECHO
297 /* Echo received data */
298 {"echo", SOCK_STREAM, 1, 0, echo_stream,},
299 {"echo", SOCK_DGRAM, 0, 0, echo_dg,},
301 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DISCARD
302 /* Internet /dev/null */
303 {"discard", SOCK_STREAM, 1, 0, discard_stream,},
304 {"discard", SOCK_DGRAM, 0, 0, discard_dg,},
306 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_TIME
307 /* Return 32 bit time since 1900 */
308 {"time", SOCK_STREAM, 0, 0, machtime_stream,},
309 {"time", SOCK_DGRAM, 0, 0, machtime_dg,},
311 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DAYTIME
312 /* Return human-readable time */
313 {"daytime", SOCK_STREAM, 0, 0, daytime_stream,},
314 {"daytime", SOCK_DGRAM, 0, 0, daytime_dg,},
316 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_CHARGEN
317 /* Familiar character generator */
318 {"chargen", SOCK_STREAM, 1, 0, chargen_stream,},
319 {"chargen", SOCK_DGRAM, 0, 0, chargen_dg,},
321 {NULL, 0, 0, 0, NULL}
323 #endif /* INETD_FEATURE_ENABLED */
325 static int global_queuelen = 128;
326 static int nsock, maxsock;
327 static fd_set allsock;
328 static int toomany = TOOMANY;
329 static int timingout;
330 static struct servent *sp;
333 static char *CONFIG = _PATH_INETDCONF;
335 static FILE *fconfig;
336 static char line[1024];
337 static char *defhost;
339 static char *newstr (char *cp)
341 if ((cp = strdup (cp ? cp : "")))
343 syslog (LOG_ERR, "strdup: %m");
347 static int setconfig (void)
350 defhost = newstr ("*");
351 if (fconfig != NULL) {
352 fseek (fconfig, 0L, SEEK_SET);
355 fconfig = fopen (CONFIG, "r");
356 return (fconfig != NULL);
359 static void endconfig (void)
362 (void) fclose (fconfig);
369 #ifdef CONFIG_FEATURE_INETD_RPC
370 static void register_rpc (servtab_t *sep)
373 struct sockaddr_in ir_sin;
376 if ((pp = getprotobyname (sep->se_proto + 4)) == NULL) {
377 syslog (LOG_ERR, "%s: getproto: %m", sep->se_proto);
381 if (getsockname (sep->se_fd, (struct sockaddr *) &ir_sin, &n) < 0) {
382 syslog (LOG_ERR, "%s/%s: getsockname: %m",
383 sep->se_service, sep->se_proto);
387 for (n = sep->se_rpcversl; n <= sep->se_rpcversh; n++) {
388 (void) pmap_unset (sep->se_rpcprog, n);
389 if (!pmap_set (sep->se_rpcprog, n, pp->p_proto, ntohs (ir_sin.sin_port)))
390 syslog (LOG_ERR, "%s %s: pmap_set: %u %u %u %u: %m",
391 sep->se_service, sep->se_proto,
392 sep->se_rpcprog, n, pp->p_proto, ntohs (ir_sin.sin_port));
396 static void unregister_rpc (servtab_t *sep)
400 for (n = sep->se_rpcversl; n <= sep->se_rpcversh; n++) {
401 if (!pmap_unset (sep->se_rpcprog, n))
402 syslog (LOG_ERR, "pmap_unset(%u, %u)", sep->se_rpcprog, n);
405 #endif /* CONFIG_FEATURE_INETD_RPC */
407 static void freeconfig (servtab_t *cp)
411 free (cp->se_hostaddr);
412 free (cp->se_service);
416 free (cp->se_server);
417 for (i = 0; i < MAXARGV; i++)
419 free (cp->se_argv[i]);
422 static int bump_nofile (void)
428 if (getrlimit (RLIMIT_NOFILE, &rl) < 0) {
429 syslog (LOG_ERR, "getrlimit: %m");
432 rl.rlim_cur = MIN (rl.rlim_max, rl.rlim_cur + FD_CHUNK);
433 rl.rlim_cur = MIN (FD_SETSIZE, rl.rlim_cur + FD_CHUNK);
434 if (rl.rlim_cur <= rlim_ofile_cur) {
435 syslog (LOG_ERR, "bump_nofile: cannot extend file limit, max = %d",
440 if (setrlimit (RLIMIT_NOFILE, &rl) < 0) {
441 syslog (LOG_ERR, "setrlimit: %m");
445 rlim_ofile_cur = rl.rlim_cur;
449 static void setup (servtab_t *sep)
454 if ((sep->se_fd = socket (sep->se_family, sep->se_socktype, 0)) < 0) {
455 syslog (LOG_ERR, "%s/%s: socket: %m", sep->se_service, sep->se_proto);
458 #define turnon(fd, opt) \
459 setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (on))
460 if (turnon (sep->se_fd, SO_REUSEADDR) < 0)
461 syslog (LOG_ERR, "setsockopt (SO_REUSEADDR): %m");
464 #ifdef CONFIG_FEATURE_INETD_RPC
465 if (isrpcservice (sep)) {
469 * for RPC services, attempt to use a reserved port
470 * if they are going to be running as root.
472 * Also, zero out the port for all RPC services; let bind()
475 sep->se_ctrladdr_in.sin_port = 0;
476 if (sep->se_user && (pwd = getpwnam (sep->se_user)) &&
477 pwd->pw_uid == 0 && uid == 0)
478 r = bindresvport (sep->se_fd, &sep->se_ctrladdr_in);
480 r = bind (sep->se_fd, &sep->se_ctrladdr, sep->se_ctrladdr_size);
482 int len = sep->se_ctrladdr_size;
483 int saveerrno = errno;
485 /* update se_ctrladdr_in.sin_port */
486 r = getsockname (sep->se_fd, &sep->se_ctrladdr, &len);
493 r = bind (sep->se_fd, &sep->se_ctrladdr, sep->se_ctrladdr_size);
495 syslog (LOG_ERR, "%s/%s (%d): bind: %m",
496 sep->se_service, sep->se_proto, sep->se_ctrladdr.sa_family);
505 if (sep->se_socktype == SOCK_STREAM)
506 listen (sep->se_fd, global_queuelen);
508 FD_SET (sep->se_fd, &allsock);
510 if (sep->se_fd > maxsock) {
511 maxsock = sep->se_fd;
512 if ((rlim_t)maxsock > rlim_ofile_cur - FD_MARGIN)
517 static char *nextline (void)
522 if (fgets (line, sizeof (line), fd) == NULL)
524 cp = strchr (line, '\n');
530 static char *skip (char **cpp) /* int report; */
538 /* syslog(LOG_ERR, "syntax error in inetd config file"); */
543 while (*cp == ' ' || *cp == '\t')
549 (void) ungetc (c, fconfig);
550 if (c == ' ' || c == '\t')
551 if ((cp = nextline ()))
558 while (*cp && *cp != ' ' && *cp != '\t')
562 /* if ((*cpp = cp) == NULL) */
569 static servtab_t *new_servtab(void)
573 sep = (servtab_t *) malloc (sizeof (servtab_t));
575 syslog (LOG_ERR, bb_msg_memory_exhausted);
581 static servtab_t *dupconfig (servtab_t *sep)
586 newtab = new_servtab();
587 memset (newtab, 0, sizeof (servtab_t));
588 newtab->se_service = sep->se_service ? newstr (sep->se_service) : NULL;
589 newtab->se_socktype = sep->se_socktype;
590 newtab->se_family = sep->se_family;
591 newtab->se_proto = sep->se_proto ? newstr (sep->se_proto) : NULL;
592 #ifdef CONFIG_FEATURE_INETD_RPC
593 newtab->se_rpcprog = sep->se_rpcprog;
594 newtab->se_rpcversl = sep->se_rpcversl;
595 newtab->se_rpcversh = sep->se_rpcversh;
597 newtab->se_wait = sep->se_wait;
598 newtab->se_user = sep->se_user ? newstr (sep->se_user) : NULL;
599 newtab->se_group = sep->se_group ? newstr (sep->se_group) : NULL;
600 #ifdef INETD_FEATURE_ENABLED
601 newtab->se_bi = sep->se_bi;
603 newtab->se_server = sep->se_server ? newstr (sep->se_server) : 0;
605 for (argc = 0; argc <= MAXARGV; argc++)
606 newtab->se_argv[argc] = sep->se_argv[argc] ?
607 newstr (sep->se_argv[argc]) : NULL;
608 newtab->se_max = sep->se_max;
613 static servtab_t *getconfigent (void)
624 /* memset(sep, 0, sizeof *sep); */
626 /* freeconfig(sep); */
628 while ((cp = nextline ()) && *cp == '#');
634 memset ((char *) sep, 0, sizeof *sep);
641 /* Check for a host name. */
642 hostdelim = strrchr (arg, ':');
645 sep->se_hostaddr = newstr (arg);
648 * If the line is of the form `host:', then just change the
649 * default host for the following lines.
655 defhost = sep->se_hostaddr;
660 sep->se_hostaddr = newstr (defhost);
662 sep->se_service = newstr (arg);
665 if (strcmp (arg, "stream") == 0)
666 sep->se_socktype = SOCK_STREAM;
667 else if (strcmp (arg, "dgram") == 0)
668 sep->se_socktype = SOCK_DGRAM;
669 else if (strcmp (arg, "rdm") == 0)
670 sep->se_socktype = SOCK_RDM;
671 else if (strcmp (arg, "seqpacket") == 0)
672 sep->se_socktype = SOCK_SEQPACKET;
673 else if (strcmp (arg, "raw") == 0)
674 sep->se_socktype = SOCK_RAW;
676 sep->se_socktype = -1;
678 sep->se_proto = newstr (skip (&cp));
680 if (strcmp (sep->se_proto, "unix") == 0) {
681 sep->se_family = AF_UNIX;
683 sep->se_family = AF_INET;
684 if (sep->se_proto[strlen (sep->se_proto) - 1] == '6')
685 #ifdef CONFIG_FEATURE_IPV6
686 sep->se_family = AF_INET6;
688 syslog (LOG_ERR, "%s: IPV6 not supported", sep->se_proto);
690 if (strncmp (sep->se_proto, "rpc/", 4) == 0) {
691 #ifdef CONFIG_FEATURE_INETD_RPC
695 p = strchr (sep->se_service, '/');
697 syslog (LOG_ERR, "%s: no rpc version", sep->se_service);
701 l = strtol (p, &ccp, 0);
702 if (ccp == p || l < 0 || l > INT_MAX) {
704 syslog (LOG_ERR, "%s/%s: bad rpc version", sep->se_service, p);
707 sep->se_rpcversl = sep->se_rpcversh = l;
710 l = strtol (p, &ccp, 0);
711 if (ccp == p || l < 0 || l > INT_MAX || l < sep->se_rpcversl || *ccp)
713 sep->se_rpcversh = l;
714 } else if (*ccp != '\0')
717 syslog (LOG_ERR, "%s: rpc services not supported", sep->se_service);
726 char *s = strchr (arg, '.');
729 sep->se_max = atoi (s);
731 sep->se_max = toomany;
733 sep->se_wait = strcmp (arg, "wait") == 0;
734 /* if ((arg = skip(&cp, 1)) == NULL) */
736 sep->se_user = newstr (skip (&cp));
737 arg = strchr (sep->se_user, '.');
739 arg = strchr (sep->se_user, ':');
742 sep->se_group = newstr (arg);
744 /* if ((arg = skip(&cp, 1)) == NULL) */
747 sep->se_server = newstr (skip (&cp));
748 if (strcmp (sep->se_server, "internal") == 0) {
749 #ifdef INETD_FEATURE_ENABLED
750 const struct biltin *bi;
752 for (bi = biltins; bi->bi_service; bi++)
753 if (bi->bi_socktype == sep->se_socktype &&
754 strcmp (bi->bi_service, sep->se_service) == 0)
756 if (bi->bi_service == 0) {
757 syslog (LOG_ERR, "internal service %s unknown", sep->se_service);
761 sep->se_wait = bi->bi_wait;
763 syslog (LOG_ERR, "internal service %s unknown", sep->se_service);
767 #ifdef INETD_FEATURE_ENABLED
772 for (arg = skip (&cp); cp; arg = skip (&cp)) {
774 sep->se_argv[argc++] = newstr (arg);
776 while (argc <= MAXARGV)
777 sep->se_argv[argc++] = NULL;
780 * Now that we've processed the entire line, check if the hostname
781 * specifier was a comma separated list of hostnames. If so
782 * we'll make new entries for each address.
784 while ((hostdelim = strrchr (sep->se_hostaddr, ',')) != NULL) {
785 nsep = dupconfig (sep);
788 * NULL terminate the hostname field of the existing entry,
789 * and make a dup for the new entry.
792 nsep->se_hostaddr = newstr (hostdelim);
794 nsep->se_next = sep->se_next;
799 while (nsep != NULL) {
800 nsep->se_checked = 1;
801 if (nsep->se_family == AF_INET) {
802 if (!strcmp (nsep->se_hostaddr, "*"))
803 nsep->se_ctrladdr_in.sin_addr.s_addr = INADDR_ANY;
804 else if (!inet_aton (nsep->se_hostaddr, &nsep->se_ctrladdr_in.sin_addr)) {
807 hp = gethostbyname (nsep->se_hostaddr);
809 syslog (LOG_ERR, "%s: unknown host", nsep->se_hostaddr);
810 nsep->se_checked = 0;
812 } else if (hp->h_addrtype != AF_INET) {
814 "%s: address isn't an Internet "
815 "address", nsep->se_hostaddr);
816 nsep->se_checked = 0;
821 memmove (&nsep->se_ctrladdr_in.sin_addr,
822 hp->h_addr_list[0], sizeof (struct in_addr));
823 while (hp->h_addr_list[i] != NULL) {
824 psep = dupconfig (nsep);
825 psep->se_hostaddr = newstr (nsep->se_hostaddr);
826 psep->se_checked = 1;
827 memmove (&psep->se_ctrladdr_in.sin_addr,
828 hp->h_addr_list[i], sizeof (struct in_addr));
829 psep->se_ctrladdr_size = sizeof (psep->se_ctrladdr_in);
831 /* Prepend to list, don't want to look up its */
832 /* hostname again. */
839 /* XXX BUG?: is this skip: label supposed to remain? */
841 nsep = nsep->se_next;
845 * Finally, free any entries which failed the gethostbyname
850 while (nsep != NULL) {
853 if (nsep->se_checked == 0) {
859 nsep = nsep->se_next;
860 psep->se_next = nsep;
864 nsep->se_checked = 0;
866 nsep = nsep->se_next;
873 static servtab_t *enter (servtab_t *cp)
881 #ifdef CONFIG_FEATURE_INETD_RPC
882 sep->se_rpcprog = -1;
884 omask = sigblock (SIGBLOCK);
885 sep->se_next = servtab;
891 static int matchconf (servtab_t *old, servtab_t *new)
893 if (strcmp (old->se_service, new->se_service) != 0)
896 if (strcmp (old->se_hostaddr, new->se_hostaddr) != 0)
899 if (strcmp (old->se_proto, new->se_proto) != 0)
903 * If the new servtab is bound to a specific address, check that the
904 * old servtab is bound to the same entry. If the new service is not
905 * bound to a specific address then the check of se_hostaddr above
909 if (old->se_family == AF_INET && new->se_family == AF_INET &&
910 memcmp (&old->se_ctrladdr_in.sin_addr,
911 &new->se_ctrladdr_in.sin_addr,
912 sizeof (new->se_ctrladdr_in.sin_addr)) != 0)
915 #ifdef CONFIG_FEATURE_IPV6
916 if (old->se_family == AF_INET6 && new->se_family == AF_INET6 &&
917 memcmp (&old->se_ctrladdr_in6.sin6_addr,
918 &new->se_ctrladdr_in6.sin6_addr,
919 sizeof (new->se_ctrladdr_in6.sin6_addr)) != 0)
925 static void config (int sig __attribute__((unused)))
927 servtab_t *sep, *cp, **sepp;
934 syslog (LOG_ERR, "%s: %m", CONFIG);
937 for (sep = servtab; sep; sep = sep->se_next)
939 cp = getconfigent ();
941 for (sep = servtab; sep; sep = sep->se_next)
942 if (matchconf (sep, cp))
948 #define SWAP(type, a, b) {type c=(type)a; (type)a=(type)b; (type)b=(type)c;}
950 omask = sigblock (SIGBLOCK);
952 * sep->se_wait may be holding the pid of a daemon
953 * that we're waiting for. If so, don't overwrite
954 * it unless the config file explicitly says don't
958 #ifdef INETD_FEATURE_ENABLED
961 (sep->se_wait == 1 || cp->se_wait == 0))
962 sep->se_wait = cp->se_wait;
963 SWAP (int, cp->se_max, sep->se_max);
964 SWAP (char *, sep->se_user, cp->se_user);
965 SWAP (char *, sep->se_group, cp->se_group);
966 SWAP (char *, sep->se_server, cp->se_server);
967 for (i = 0; i < MAXARGV; i++)
968 SWAP (char *, sep->se_argv[i], cp->se_argv[i]);
971 #ifdef CONFIG_FEATURE_INETD_RPC
972 if (isrpcservice (sep))
973 unregister_rpc (sep);
974 sep->se_rpcversl = cp->se_rpcversl;
975 sep->se_rpcversh = cp->se_rpcversh;
985 switch (sep->se_family) {
987 if (sep->se_fd != -1)
989 (void) unlink (sep->se_service);
990 n = strlen (sep->se_service);
991 if (n > sizeof sep->se_ctrladdr_un.sun_path - 1)
992 n = sizeof sep->se_ctrladdr_un.sun_path - 1;
993 safe_strncpy (sep->se_ctrladdr_un.sun_path, sep->se_service, n + 1);
994 sep->se_ctrladdr_un.sun_family = AF_UNIX;
995 sep->se_ctrladdr_size = n + sizeof sep->se_ctrladdr_un.sun_family;
999 sep->se_ctrladdr_in.sin_family = AF_INET;
1000 /* se_ctrladdr_in was set in getconfigent */
1001 sep->se_ctrladdr_size = sizeof sep->se_ctrladdr_in;
1003 #ifdef CONFIG_FEATURE_INETD_RPC
1004 if (isrpcservice (sep)) {
1007 sep->se_rpcprog = atoi (sep->se_service);
1008 if (sep->se_rpcprog == 0) {
1009 rp = getrpcbyname (sep->se_service);
1011 syslog (LOG_ERR, "%s: unknown rpc service", sep->se_service);
1014 sep->se_rpcprog = rp->r_number;
1016 if (sep->se_fd == -1)
1018 if (sep->se_fd != -1)
1023 u_short port = htons (atoi (sep->se_service));
1026 /*XXX*/ strncpy (protoname, sep->se_proto, sizeof (protoname));
1027 if (isdigit (protoname[strlen (protoname) - 1]))
1028 protoname[strlen (protoname) - 1] = '\0';
1029 sp = getservbyname (sep->se_service, protoname);
1032 "%s/%s: unknown service", sep->se_service, sep->se_proto);
1037 if (port != sep->se_ctrladdr_in.sin_port) {
1038 sep->se_ctrladdr_in.sin_port = port;
1039 if (sep->se_fd != -1) {
1040 FD_CLR (sep->se_fd, &allsock);
1042 (void) close (sep->se_fd);
1046 if (sep->se_fd == -1)
1050 #ifdef CONFIG_FEATURE_IPV6
1052 sep->se_ctrladdr_in6.sin6_family = AF_INET6;
1053 /* se_ctrladdr_in was set in getconfigent */
1054 sep->se_ctrladdr_size = sizeof sep->se_ctrladdr_in6;
1056 #ifdef CONFIG_FEATURE_INETD_RPC
1057 if (isrpcservice (sep)) {
1060 sep->se_rpcprog = atoi (sep->se_service);
1061 if (sep->se_rpcprog == 0) {
1062 rp = getrpcbyname (sep->se_service);
1064 syslog (LOG_ERR, "%s: unknown rpc service", sep->se_service);
1067 sep->se_rpcprog = rp->r_number;
1069 if (sep->se_fd == -1)
1071 if (sep->se_fd != -1)
1076 u_short port = htons (atoi (sep->se_service));
1079 /*XXX*/ strncpy (protoname, sep->se_proto, sizeof (protoname));
1080 if (isdigit (protoname[strlen (protoname) - 1]))
1081 protoname[strlen (protoname) - 1] = '\0';
1082 sp = getservbyname (sep->se_service, protoname);
1085 "%s/%s: unknown service", sep->se_service, sep->se_proto);
1090 if (port != sep->se_ctrladdr_in6.sin6_port) {
1091 sep->se_ctrladdr_in6.sin6_port = port;
1092 if (sep->se_fd != -1) {
1093 FD_CLR (sep->se_fd, &allsock);
1095 (void) close (sep->se_fd);
1099 if (sep->se_fd == -1)
1103 #endif /* CONFIG_FEATURE_IPV6 */
1106 if (cp->se_next != NULL) {
1107 servtab_t *tmp = cp;
1113 cp = getconfigent ();
1118 * Purge anything not looked at above.
1120 omask = sigblock (SIGBLOCK);
1122 while ((sep = *sepp)) {
1123 if (sep->se_checked) {
1124 sepp = &sep->se_next;
1127 *sepp = sep->se_next;
1128 if (sep->se_fd != -1) {
1129 FD_CLR (sep->se_fd, &allsock);
1131 (void) close (sep->se_fd);
1133 #ifdef CONFIG_FEATURE_INETD_RPC
1134 if (isrpcservice (sep))
1135 unregister_rpc (sep);
1137 if (sep->se_family == AF_UNIX)
1138 (void) unlink (sep->se_service);
1142 (void) sigsetmask (omask);
1146 static void reapchild (int sig __attribute__((unused)))
1149 int save_errno = errno, status;
1153 pid = wait3 (&status, WNOHANG, NULL);
1156 for (sep = servtab; sep; sep = sep->se_next)
1157 if (sep->se_wait == pid) {
1158 if (WIFEXITED (status) && WEXITSTATUS (status))
1159 syslog (LOG_WARNING,
1160 "%s: exit status 0x%x",
1161 sep->se_server, WEXITSTATUS (status));
1162 else if (WIFSIGNALED (status))
1163 syslog (LOG_WARNING,
1164 "%s: exit signal 0x%x", sep->se_server, WTERMSIG (status));
1166 FD_SET (sep->se_fd, &allsock);
1173 static void retry (int sig __attribute__((unused)))
1178 for (sep = servtab; sep; sep = sep->se_next) {
1179 if (sep->se_fd == -1) {
1180 switch (sep->se_family) {
1183 #ifdef CONFIG_FEATURE_IPV6
1187 #ifdef CONFIG_FEATURE_INETD_RPC
1188 if (sep->se_fd != -1 && isrpcservice (sep))
1197 static void goaway (int sig __attribute__((unused)))
1201 /* XXX signal race walking sep list */
1202 for (sep = servtab; sep; sep = sep->se_next) {
1203 if (sep->se_fd == -1)
1206 switch (sep->se_family) {
1208 (void) unlink (sep->se_service);
1211 #ifdef CONFIG_FEATURE_IPV6
1214 #ifdef CONFIG_FEATURE_INETD_RPC
1215 if (sep->se_wait == 1 && isrpcservice (sep))
1216 unregister_rpc (sep); /* XXX signal race */
1220 (void) close (sep->se_fd);
1222 (void) unlink (_PATH_INETDPID);
1227 #ifdef INETD_SETPROCTITLE
1229 static char *LastArg;
1232 inetd_setproctitle (char *a, int s)
1236 struct sockaddr_in prt_sin;
1240 size = sizeof (prt_sin);
1241 (void) snprintf (buf, sizeof buf, "-%s", a);
1242 if (getpeername (s, (struct sockaddr *) &prt_sin, &size) == 0) {
1243 char *sa = inet_ntoa (prt_sin.sin_addr);
1245 buf[sizeof (buf) - 1 - strlen (sa) - 3] = '\0';
1250 strncpy (cp, buf, LastArg - cp);
1252 while (cp < LastArg)
1259 inetd_main (int argc, char *argv[])
1263 struct group *grp = NULL;
1265 struct sigaction sa, sapipe;
1271 #ifdef INETD_SETPROCTITLE
1272 extern char **environ;
1273 char **envp = environ;
1276 if (envp == 0 || *envp == 0)
1280 LastArg = envp[-1] + strlen (envp[-1]);
1283 openlog (bb_applet_name, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
1285 opt = bb_getopt_ulflags (argc, argv, "R:f", &stoomany);
1289 toomany = strtoul (stoomany, &e, 0);
1290 if (!(toomany >= 0 && *e == '\0')) {
1292 syslog (LOG_ERR, "-R %s: bad value for service invocation rate", stoomany);
1304 bb_error_msg_and_die ("non-root must specify a config file");
1307 #if defined(__uClinux__)
1308 /* reexec for vfork() do continue parent */
1309 vfork_daemon_rexec (0, 0, argc, argv, "-f");
1312 #endif /* uClinux */
1318 gid_t gid = getgid ();
1320 /* If run by hand, ensure groups vector gets trashed */
1321 setgroups (1, &gid);
1327 if ((fp = fopen (_PATH_INETDPID, "w")) != NULL) {
1328 fprintf (fp, "%u\n", getpid ());
1333 if (getrlimit (RLIMIT_NOFILE, &rlim_ofile) < 0) {
1334 syslog (LOG_ERR, "getrlimit: %m");
1336 rlim_ofile_cur = rlim_ofile.rlim_cur;
1337 if (rlim_ofile_cur == RLIM_INFINITY) /* ! */
1338 rlim_ofile_cur = OPEN_MAX;
1341 memset ((char *) &sa, 0, sizeof (sa));
1342 sigemptyset (&sa.sa_mask);
1343 sigaddset (&sa.sa_mask, SIGALRM);
1344 sigaddset (&sa.sa_mask, SIGCHLD);
1345 sigaddset (&sa.sa_mask, SIGHUP);
1346 sa.sa_handler = retry;
1347 sigaction (SIGALRM, &sa, NULL);
1350 sa.sa_handler = config;
1351 sigaction (SIGHUP, &sa, NULL);
1352 sa.sa_handler = reapchild;
1353 sigaction (SIGCHLD, &sa, NULL);
1354 sa.sa_handler = goaway;
1355 sigaction (SIGTERM, &sa, NULL);
1356 sa.sa_handler = goaway;
1357 sigaction (SIGINT, &sa, NULL);
1358 sa.sa_handler = SIG_IGN;
1359 sigaction (SIGPIPE, &sa, &sapipe);
1362 /* space for daemons to overwrite environment for ps */
1363 #define DUMMYSIZE 100
1364 char dummy[DUMMYSIZE];
1366 (void) memset (dummy, 'x', DUMMYSIZE - 1);
1367 dummy[DUMMYSIZE - 1] = '\0';
1369 (void) setenv ("inetd_dummy", dummy, 1);
1377 (void) sigblock (SIGBLOCK);
1380 (void) sigsetmask (0L);
1384 if ((n = select (maxsock + 1, &readable, NULL, NULL, NULL)) <= 0) {
1385 if (n < 0 && errno != EINTR) {
1386 syslog (LOG_WARNING, "select: %m");
1391 for (sep = servtab; n && sep; sep = sep->se_next)
1392 if (sep->se_fd != -1 && FD_ISSET (sep->se_fd, &readable)) {
1394 if (!sep->se_wait && sep->se_socktype == SOCK_STREAM) {
1395 ctrl = accept (sep->se_fd, NULL, NULL);
1399 syslog (LOG_WARNING, "accept (for %s): %m", sep->se_service);
1402 if (sep->se_family == AF_INET && sep->se_socktype == SOCK_STREAM) {
1403 struct sockaddr_in peer;
1404 int plen = sizeof (peer);
1406 if (getpeername (ctrl, (struct sockaddr *) &peer, &plen) < 0) {
1407 syslog (LOG_WARNING, "could not getpeername");
1411 if (ntohs (peer.sin_port) == 20) {
1412 /* XXX ftp bounce */
1419 (void) sigblock (SIGBLOCK);
1421 #ifdef INETD_FEATURE_ENABLED
1422 if (sep->se_bi == 0 || sep->se_bi->bi_fork)
1425 if (sep->se_count++ == 0)
1426 (void) gettimeofday (&sep->se_time, NULL);
1427 else if (toomany > 0 && sep->se_count >= sep->se_max) {
1430 (void) gettimeofday (&now, NULL);
1431 if (now.tv_sec - sep->se_time.tv_sec > CNT_INTVL) {
1435 if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
1437 if (sep->se_family == AF_INET &&
1438 ntohs (sep->se_ctrladdr_in.sin_port) >= IPPORT_RESERVED) {
1440 * Cannot close it -- there are
1441 * thieves on the system.
1442 * Simply ignore the connection.
1448 "%s/%s server failing (looping), service terminated",
1449 sep->se_service, sep->se_proto);
1450 if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
1452 FD_CLR (sep->se_fd, &allsock);
1453 (void) close (sep->se_fd);
1468 syslog (LOG_ERR, "fork: %m");
1469 if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
1475 if (pid && sep->se_wait) {
1477 FD_CLR (sep->se_fd, &allsock);
1482 #ifdef INETD_FEATURE_ENABLED
1484 (*sep->se_bi->bi_fn) (ctrl, sep);
1488 if ((pwd = getpwnam (sep->se_user)) == NULL) {
1489 syslog (LOG_ERR, "getpwnam: %s: No such user", sep->se_user);
1490 if (sep->se_socktype != SOCK_STREAM)
1491 recv (0, buf, sizeof (buf), 0);
1495 syslog (LOG_ERR, "%s: setsid: %m", sep->se_service);
1496 if (sep->se_group && (grp = getgrnam (sep->se_group)) == NULL) {
1497 syslog (LOG_ERR, "getgrnam: %s: No such group", sep->se_group);
1498 if (sep->se_socktype != SOCK_STREAM)
1499 recv (0, buf, sizeof (buf), 0);
1503 /* a user running private inetd */
1504 if (uid != pwd->pw_uid)
1506 } else if (pwd->pw_uid) {
1507 if (sep->se_group) {
1508 pwd->pw_gid = grp->gr_gid;
1510 setgid ((gid_t) pwd->pw_gid);
1511 initgroups (pwd->pw_name, pwd->pw_gid);
1512 setuid ((uid_t) pwd->pw_uid);
1513 } else if (sep->se_group) {
1514 setgid (grp->gr_gid);
1515 setgroups (1, &grp->gr_gid);
1521 if (rlim_ofile.rlim_cur != rlim_ofile_cur)
1522 if (setrlimit (RLIMIT_NOFILE, &rlim_ofile) < 0)
1523 syslog (LOG_ERR, "setrlimit: %m");
1525 for (tmpint = rlim_ofile_cur - 1; --tmpint > 2;)
1526 (void) close (tmpint);
1527 sigaction (SIGPIPE, &sapipe, NULL);
1528 execv (sep->se_server, sep->se_argv);
1529 if (sep->se_socktype != SOCK_STREAM)
1530 recv (0, buf, sizeof (buf), 0);
1531 syslog (LOG_ERR, "execv %s: %m", sep->se_server);
1535 if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
1542 * Internet services provided internally by inetd:
1544 #define BUFSIZE 4096
1546 #if defined(CONFIG_FEATURE_INETD_SUPPORT_BILTIN_ECHO) || \
1547 defined(CONFIG_FEATURE_INETD_SUPPORT_BILTIN_CHARGEN) || \
1548 defined(CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DAYTIME)
1549 static int dg_badinput (struct sockaddr_in *dg_sin)
1551 if (ntohs (dg_sin->sin_port) < IPPORT_RESERVED)
1553 if (dg_sin->sin_addr.s_addr == htonl (INADDR_BROADCAST))
1555 /* XXX compare against broadcast addresses in SIOCGIFCONF list? */
1560 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_ECHO
1561 /* Echo service -- echo data back */
1564 echo_stream (int s, servtab_t *sep)
1566 char buffer[BUFSIZE];
1569 inetd_setproctitle (sep->se_service, s);
1570 while ((i = read (s, buffer, sizeof (buffer))) > 0 &&
1571 write (s, buffer, i) > 0);
1575 /* Echo service -- echo data back */
1578 echo_dg (int s, servtab_t *sep __attribute__((unused)))
1580 char buffer[BUFSIZE];
1582 /* struct sockaddr_storage ss; */
1586 if ((i = recvfrom (s, buffer, sizeof (buffer), 0, &sa, &size)) < 0)
1588 if (dg_badinput ((struct sockaddr_in *) &sa))
1590 (void) sendto (s, buffer, i, 0, &sa, sizeof (sa));
1592 #endif /* CONFIG_FEATURE_INETD_SUPPORT_BILTIN_ECHO */
1594 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DISCARD
1595 /* Discard service -- ignore data */
1598 discard_stream (int s, servtab_t *sep)
1600 char buffer[BUFSIZE];
1602 inetd_setproctitle (sep->se_service, s);
1603 while ((errno = 0, read (s, buffer, sizeof (buffer)) > 0) ||
1608 /* Discard service -- ignore data */
1611 discard_dg (int s, servtab_t *sep __attribute__((unused)))
1613 char buffer[BUFSIZE];
1615 (void) read (s, buffer, sizeof (buffer));
1617 #endif /* CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DISCARD */
1620 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_CHARGEN
1622 static char ring[128];
1623 static char *endring;
1632 for (i = 0; i <= 128; ++i)
1637 /* Character generator */
1640 chargen_stream (int s, servtab_t *sep)
1644 char text[LINESIZ + 2];
1646 inetd_setproctitle (sep->se_service, s);
1653 text[LINESIZ] = '\r';
1654 text[LINESIZ + 1] = '\n';
1656 if ((len = endring - rs) >= LINESIZ)
1657 memmove (text, rs, LINESIZ);
1659 memmove (text, rs, len);
1660 memmove (text + len, ring, LINESIZ - len);
1662 if (++rs == endring)
1664 if (write (s, text, sizeof (text)) != sizeof (text))
1670 /* Character generator */
1673 chargen_dg (int s, servtab_t *sep __attribute__((unused)))
1675 /* struct sockaddr_storage ss; */
1679 char text[LINESIZ + 2];
1687 if (recvfrom (s, text, sizeof (text), 0, &sa, &size) < 0)
1689 if (dg_badinput ((struct sockaddr_in *) &sa))
1692 if ((len = endring - rs) >= LINESIZ)
1693 memmove (text, rs, LINESIZ);
1695 memmove (text, rs, len);
1696 memmove (text + len, ring, LINESIZ - len);
1698 if (++rs == endring)
1700 text[LINESIZ] = '\r';
1701 text[LINESIZ + 1] = '\n';
1702 (void) sendto (s, text, sizeof (text), 0, &sa, sizeof (sa));
1704 #endif /* CONFIG_FEATURE_INETD_SUPPORT_BILTIN_CHARGEN */
1707 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_TIME
1709 * Return a machine readable date and time, in the form of the
1710 * number of seconds since midnight, Jan 1, 1900. Since gettimeofday
1711 * returns the number of seconds since midnight, Jan 1, 1970,
1712 * we must add 2208988800 seconds to this figure to make up for
1713 * some seventy years Bell Labs was asleep.
1716 static u_int machtime (void)
1720 if (gettimeofday (&tv, NULL) < 0) {
1721 fprintf (stderr, "Unable to get time of day\n");
1724 return (htonl ((u_int) tv.tv_sec + 2208988800UL));
1729 machtime_stream (int s, servtab_t *sep __attribute__((unused)))
1733 result = machtime ();
1734 (void) write (s, (char *) &result, sizeof (result));
1739 machtime_dg (int s, servtab_t *sep __attribute__((unused)))
1742 /* struct sockaddr_storage ss; */
1744 struct sockaddr_in *dg_sin;
1748 if (recvfrom (s, (char *) &result, sizeof (result), 0, &sa, &size) < 0)
1750 /* if (dg_badinput((struct sockaddr *)&ss)) */
1751 dg_sin = (struct sockaddr_in *) &sa;
1752 if (dg_sin->sin_addr.s_addr == htonl (INADDR_BROADCAST) ||
1753 ntohs (dg_sin->sin_port) < IPPORT_RESERVED / 2)
1755 result = machtime ();
1756 (void) sendto (s, (char *) &result, sizeof (result), 0, &sa, sizeof (sa));
1758 #endif /* CONFIG_FEATURE_INETD_SUPPORT_BILTIN_TIME */
1761 #ifdef CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DAYTIME
1762 /* Return human-readable time of day */
1764 static void daytime_stream (int s, servtab_t *sep __attribute__((unused)))
1771 (void) sprintf (buffer, "%.24s\r\n", ctime (&t));
1772 (void) write (s, buffer, strlen (buffer));
1775 /* Return human-readable time of day */
1778 daytime_dg (int s, servtab_t *sep __attribute__((unused)))
1782 /* struct sockaddr_storage ss; */
1786 t = time ((time_t *) 0);
1789 if (recvfrom (s, buffer, sizeof (buffer), 0, &sa, &size) < 0)
1791 if (dg_badinput ((struct sockaddr_in *) &sa))
1793 (void) sprintf (buffer, "%.24s\r\n", ctime (&t));
1794 (void) sendto (s, buffer, strlen (buffer), 0, &sa, sizeof (sa));
1796 #endif /* CONFIG_FEATURE_INETD_SUPPORT_BILTIN_DAYTIME */