1 /* vi: set sw=4 ts=4: */
3 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
14 int dumpleases_main(int argc, char *argv[]);
15 int dumpleases_main(int argc, char *argv[])
18 int i, c, mode = REMAINING;
19 unsigned long expires;
20 const char *file = LEASES_FILE;
21 struct dhcpOfferedAddr lease;
24 static const struct option options[] = {
25 {"absolute", 0, 0, 'a'},
26 {"remaining", 0, 0, 'r'},
33 c = getopt_long(argc, argv, "arf:", options, &option_index);
37 case 'a': mode = ABSOLUTE; break;
38 case 'r': mode = REMAINING; break;
47 fp = xopen(file, O_RDONLY);
49 printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at");
50 /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */
51 while (full_read(fp, &lease, sizeof(lease)) == sizeof(lease)) {
52 printf(":%02x"+1, lease.chaddr[0]);
53 for (i = 1; i < 6; i++) {
54 printf(":%02x", lease.chaddr[i]);
56 addr.s_addr = lease.yiaddr;
57 printf(" %-15s ", inet_ntoa(addr));
58 expires = ntohl(lease.expires);
59 if (mode == REMAINING) {
64 d = expires / (24*60*60); expires %= (24*60*60);
65 h = expires / (60*60); expires %= (60*60);
66 m = expires / 60; expires %= 60;
67 if (d) printf("%u days ", d);
68 printf("%02u:%02u:%02u\n", h, m, (unsigned)expires);
70 } else fputs(ctime(&expires), stdout);