summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2007-09-07 07:52:15 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2007-09-07 07:52:15 +0000
commitaf92d59f0c404fa53091253c6666c5d613979e47 (patch)
tree92fe757fbffb5671dc4335c7cb74c26b48423e8e /usr.sbin
parent8ecd9f570ea5c0896b736732748ae9beb6cdec22 (diff)
add a function to print delays in hours, minutes, and seconds
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/hoststated/hoststated.h3
-rw-r--r--usr.sbin/hoststated/log.c18
-rw-r--r--usr.sbin/relayd/log.c18
-rw-r--r--usr.sbin/relayd/relayd.h3
4 files changed, 38 insertions, 4 deletions
diff --git a/usr.sbin/hoststated/hoststated.h b/usr.sbin/hoststated/hoststated.h
index b15b9acbfea..bdaf7f884db 100644
--- a/usr.sbin/hoststated/hoststated.h
+++ b/usr.sbin/hoststated/hoststated.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: hoststated.h,v 1.56 2007/09/06 19:55:45 reyk Exp $ */
+/* $OpenBSD: hoststated.h,v 1.57 2007/09/07 07:52:14 reyk Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -639,6 +639,7 @@ const char *host_status(enum host_status);
const char *table_check(enum table_check);
const char *print_availability(u_long, u_long);
const char *print_host(struct sockaddr_storage *, char *, size_t);
+const char *print_time(struct timeval *, struct timeval *, char *, size_t);
/* buffer.c */
struct buf *buf_open(size_t);
diff --git a/usr.sbin/hoststated/log.c b/usr.sbin/hoststated/log.c
index b6f8ae4cd05..5b7257a0d09 100644
--- a/usr.sbin/hoststated/log.c
+++ b/usr.sbin/hoststated/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.6 2007/09/06 19:55:45 reyk Exp $ */
+/* $OpenBSD: log.c,v 1.7 2007/09/07 07:52:14 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -230,3 +230,19 @@ print_host(struct sockaddr_storage *ss, char *buf, size_t len)
ptr = &((struct sockaddr_in6 *)ss)->sin6_addr;
return (inet_ntop(af, ptr, buf, len));
}
+
+const char *
+print_time(struct timeval *a, struct timeval *b, char *buf, size_t len)
+{
+ struct timeval tv;
+ u_long h, sec, min;
+
+ timerclear(&tv);
+ timersub(a, b, &tv);
+ sec = tv.tv_sec % 60;
+ min = tv.tv_sec / 60 % 60;
+ h = tv.tv_sec / 60 / 60;
+
+ snprintf(buf, len, "%.2lu:%.2lu:%.2lu", h, min, sec);
+ return (buf);
+}
diff --git a/usr.sbin/relayd/log.c b/usr.sbin/relayd/log.c
index b6f8ae4cd05..5b7257a0d09 100644
--- a/usr.sbin/relayd/log.c
+++ b/usr.sbin/relayd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.6 2007/09/06 19:55:45 reyk Exp $ */
+/* $OpenBSD: log.c,v 1.7 2007/09/07 07:52:14 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -230,3 +230,19 @@ print_host(struct sockaddr_storage *ss, char *buf, size_t len)
ptr = &((struct sockaddr_in6 *)ss)->sin6_addr;
return (inet_ntop(af, ptr, buf, len));
}
+
+const char *
+print_time(struct timeval *a, struct timeval *b, char *buf, size_t len)
+{
+ struct timeval tv;
+ u_long h, sec, min;
+
+ timerclear(&tv);
+ timersub(a, b, &tv);
+ sec = tv.tv_sec % 60;
+ min = tv.tv_sec / 60 % 60;
+ h = tv.tv_sec / 60 / 60;
+
+ snprintf(buf, len, "%.2lu:%.2lu:%.2lu", h, min, sec);
+ return (buf);
+}
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index 1c315716321..21b877e2bb1 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.h,v 1.56 2007/09/06 19:55:45 reyk Exp $ */
+/* $OpenBSD: relayd.h,v 1.57 2007/09/07 07:52:14 reyk Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -639,6 +639,7 @@ const char *host_status(enum host_status);
const char *table_check(enum table_check);
const char *print_availability(u_long, u_long);
const char *print_host(struct sockaddr_storage *, char *, size_t);
+const char *print_time(struct timeval *, struct timeval *, char *, size_t);
/* buffer.c */
struct buf *buf_open(size_t);