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 char dumpleases_longopts[] =
28 "absolute\0" No_argument "a"
29 "remaining\0" No_argument "r"
30 "file\0" Required_argument "f"
33 applet_long_options = dumpleases_longopts;
35 opt_complementary = "=0:a--r:r--a";
36 opt = getopt32(argc, argv, "arf:", &file);
38 fd = xopen(file, O_RDONLY);
40 printf("Mac Address IP-Address Expires %s\n", (opt & OPT_a) ? "at" : "in");
41 /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */
42 while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
43 printf(":%02x"+1, lease.chaddr[0]);
44 for (i = 1; i < 6; i++) {
45 printf(":%02x", lease.chaddr[i]);
47 addr.s_addr = lease.yiaddr;
48 printf(" %-15s ", inet_ntoa(addr));
49 expires = ntohl(lease.expires);
50 if (!(opt & OPT_a)) { /* no -a */
55 d = expires / (24*60*60); expires %= (24*60*60);
56 h = expires / (60*60); expires %= (60*60);
57 m = expires / 60; expires %= 60;
58 if (d) printf("%u days ", d);
59 printf("%02u:%02u:%02u\n", h, m, (unsigned)expires);
62 fputs(ctime(&expires), stdout);