*/
//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"
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;
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 */
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]);
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;