diff options
-rw-r--r-- | networking/udhcp/dumpleases.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c index 64cd73e..f68e499 100644 --- a/networking/udhcp/dumpleases.c +++ b/networking/udhcp/dumpleases.c @@ -4,18 +4,20 @@ */ //usage:#define dumpleases_trivial_usage -//usage: "[-r|-a] [-f LEASEFILE]" +//usage: "[-r|-a] [-d] [-f LEASEFILE]" //usage:#define dumpleases_full_usage "\n\n" //usage: "Display DHCP leases granted by udhcpd\n" //usage: IF_LONG_OPTS( //usage: "\n -f,--file=FILE Lease file" //usage: "\n -r,--remaining Show remaining time" //usage: "\n -a,--absolute Show expiration time" +//usage: "\n -d,--decimal Show time in seconds" //usage: ) //usage: IF_NOT_LONG_OPTS( //usage: "\n -f FILE Lease file" //usage: "\n -r Show remaining time" //usage: "\n -a Show expiration time" +//usage: "\n -d Show time in seconds" //usage: ) #include "common.h" @@ -28,21 +30,22 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) int fd; int i; unsigned opt; - int64_t written_at, curr, expires_abs; + int64_t written_at, curr; const char *file = LEASES_FILE; struct dyn_lease lease; - struct in_addr addr; enum { OPT_a = 0x1, // -a OPT_r = 0x2, // -r OPT_f = 0x4, // -f + OPT_d = 0x8, // -d }; #if ENABLE_LONG_OPTS static const char dumpleases_longopts[] ALIGN1 = "absolute\0" No_argument "a" "remaining\0" No_argument "r" "file\0" Required_argument "f" + "decimal\0" No_argument "d" ; applet_long_options = dumpleases_longopts; @@ -50,11 +53,12 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) init_unicode(); opt_complementary = "=0:a--r:r--a"; - opt = getopt32(argv, "arf:", &file); + opt = getopt32(argv, "arf:d", &file); fd = xopen(file, O_RDONLY); - printf("Mac Address IP Address Host Name Expires %s\n", (opt & OPT_a) ? "at" : "in"); + printf("Mac Address IP Address Host Name Expires %s\n", + (opt & OPT_a) ? "at" : "in"); /* "00:00:00:00:00:00 255.255.255.255 ABCDEFGHIJKLMNOPQRS Wed Jun 30 21:49:08 1993" */ /* "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 */ @@ -65,6 +69,9 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) written_at = curr; /* lease file from future! :) */ while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) { + struct in_addr addr; + int64_t expires_abs; + const char *fmt = ":%02x" + 1; for (i = 0; i < 6; i++) { printf(fmt, lease.lease_mac[i]); @@ -87,6 +94,13 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) puts("expired"); continue; } + if (opt & OPT_d) { + /* -d: decimal time */ + if (!(opt & OPT_a)) + expires_abs -= curr; + printf("%llu\n", (unsigned long long) expires_abs); + continue; + } if (!(opt & OPT_a)) { /* no -a */ unsigned d, h, m; unsigned expires = expires_abs - curr; |