8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / usr.lib / in.daytimed / in.daytimed.c
blob6dd9ebd094dd93bde2d82bcf25b5cf2d57da5184
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * daytime inetd service - both stream and dgram based.
31 * Return human-readable time of day.
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <unistd.h>
37 #include <stdio.h>
38 #include <strings.h>
39 #include <netinet/in.h>
40 #include <inetsvc.h>
43 #define TIMEBUF_SIZE 26
46 static const char *
47 daytime(void)
49 time_t clock;
50 static char buf[TIMEBUF_SIZE];
52 clock = time(NULL);
53 (void) strlcpy(buf, ctime(&clock), sizeof (buf));
55 * Format of ctime is "Fri Sep 13 00:00:00 1986\n\0". To conform to the
56 * required format as specified in RFCs 867 and 854 we replace the
57 * "\n\0" with "\r\n".
59 buf[TIMEBUF_SIZE - 2] = '\r';
60 buf[TIMEBUF_SIZE - 1] = '\n';
62 return (buf);
65 /* ARGSUSED3 */
66 static void
67 daytime_dg(int s, const struct sockaddr *sap, int sa_size, const void *buf,
68 size_t sz)
70 (void) safe_sendto(s, daytime(), TIMEBUF_SIZE, 0, sap, sa_size);
73 int
74 main(int argc, char *argv[])
76 opterr = 0; /* disable getopt error msgs */
77 switch (getopt(argc, argv, "ds")) {
78 case 'd':
79 dg_template(daytime_dg, STDIN_FILENO, NULL, 0);
80 break;
81 case 's':
82 (void) safe_write(STDIN_FILENO, daytime(), TIMEBUF_SIZE);
83 break;
84 default:
85 return (1);
88 return (0);