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
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]
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>
39 #include <netinet/in.h>
43 #define TIMEBUF_SIZE 26
50 static char buf
[TIMEBUF_SIZE
];
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
59 buf
[TIMEBUF_SIZE
- 2] = '\r';
60 buf
[TIMEBUF_SIZE
- 1] = '\n';
67 daytime_dg(int s
, const struct sockaddr
*sap
, int sa_size
, const void *buf
,
70 (void) safe_sendto(s
, daytime(), TIMEBUF_SIZE
, 0, sap
, sa_size
);
74 main(int argc
, char *argv
[])
76 opterr
= 0; /* disable getopt error msgs */
77 switch (getopt(argc
, argv
, "ds")) {
79 dg_template(daytime_dg
, STDIN_FILENO
, NULL
, 0);
82 (void) safe_write(STDIN_FILENO
, daytime(), TIMEBUF_SIZE
);