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