summaryrefslogtreecommitdiffstats
path: root/btimed.c
diff options
context:
space:
mode:
Diffstat (limited to 'btimed.c')
-rw-r--r--btimed.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/btimed.c b/btimed.c
index 544d108..c02b0bc 100644
--- a/btimed.c
+++ b/btimed.c
@@ -22,9 +22,11 @@ main(int argc, char **argv)
{
int sd;
char inmsg[BTIME_MSGLEN];
- char outmsg[BTIME_MSGLEN];
+ char btimeonly[BTIME_MSGLEN];
+ char cookiemsg[BTIME_MSGLEN];
+ char *outmsg;
struct sockaddr_in cli_addr;
- int cli_addr_len;
+ socklen_t cli_addr_len;
ssize_t nbytes;
unsigned int local_btime;
@@ -37,13 +39,14 @@ main(int argc, char **argv)
alarm(30);
/* Generate the standard btime message */
- memset(outmsg, 0, BTIME_MSGLEN);
+ memset(btimeonly, 0, BTIME_MSGLEN);
local_btime = get_btime();
- sprintf(outmsg, "%u\n", local_btime);
+ sprintf(btimeonly, "%u\n", local_btime);
syslog(LOG_INFO, "started with btime = %u", local_btime);
for (;;) {
memset(&cli_addr, 0, sizeof cli_addr);
+ memset(inmsg, 0, BTIME_MSGLEN);
cli_addr_len = sizeof cli_addr;
nbytes = recvfrom(sd, &inmsg, BTIME_MSGLEN, MSG_WAITALL,
(struct sockaddr *)&cli_addr, &cli_addr_len);
@@ -55,8 +58,18 @@ main(int argc, char **argv)
syslog(LOG_INFO, "exitting");
exit(0);
}
+ if (inmsg[0] == 'B' && inmsg[1] == 'T' ) {
+ /* New style heartbeat with cookie */
+ /* Copy cookie to message and append timestamp */
+ memset(cookiemsg, 0, BTIME_MSGLEN);
+ memcpy(cookiemsg, inmsg, COOKIE_LEN);
+ strcpy(cookiemsg + COOKIE_LEN, btimeonly);
+ outmsg = cookiemsg;
+ } else {
+ outmsg = btimeonly;
+ }
- sendto(sd, &outmsg, BTIME_MSGLEN, MSG_DONTWAIT,
+ sendto(sd, outmsg, BTIME_MSGLEN, MSG_DONTWAIT,
(struct sockaddr *)&cli_addr, cli_addr_len);
/* We want to exit after 30 seconds of inactivity */
alarm(30);