1 /* vi: set sw=4 ts=4: */
3 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
9 int dumpleases_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
10 int dumpleases_main(int argc UNUSED_PARAM, char **argv)
16 const char *file = LEASES_FILE;
17 struct dhcpOfferedAddr lease;
25 #if ENABLE_GETOPT_LONG
26 static const char dumpleases_longopts[] ALIGN1 =
27 "absolute\0" No_argument "a"
28 "remaining\0" No_argument "r"
29 "file\0" Required_argument "f"
32 applet_long_options = dumpleases_longopts;
34 opt_complementary = "=0:a--r:r--a";
35 opt = getopt32(argv, "arf:", &file);
37 fd = xopen(file, O_RDONLY);
39 printf("Mac Address IP-Address Expires %s\n", (opt & OPT_a) ? "at" : "in");
40 /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */
41 while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
42 printf(":%02x"+1, lease.chaddr[0]);
43 for (i = 1; i < 6; i++) {
44 printf(":%02x", lease.chaddr[i]);
46 addr.s_addr = lease.yiaddr;
47 printf(" %-15s ", inet_ntoa(addr));
48 expires = ntohl(lease.expires);
49 if (!(opt & OPT_a)) { /* no -a */
54 d = expires / (24*60*60); expires %= (24*60*60);
55 h = expires / (60*60); expires %= (60*60);
56 m = expires / 60; expires %= 60;
57 if (d) printf("%u days ", d);
58 printf("%02u:%02u:%02u\n", h, m, (unsigned)expires);
61 fputs(ctime(&expires), stdout);