Annotation of /trunk/mkinitrd-magellan/busybox/networking/udhcp/dumpleases.c
Parent Directory | Revision Log
Revision 816 -
(hide annotations)
(download)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 1697 byte(s)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 1697 byte(s)
-updated to busybox-1.13.4
1 | niro | 532 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||
3 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | ||
4 | */ | ||
5 | |||
6 | #include "common.h" | ||
7 | #include "dhcpd.h" | ||
8 | |||
9 | niro | 816 | int dumpleases_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
10 | int dumpleases_main(int argc UNUSED_PARAM, char **argv) | ||
11 | niro | 532 | { |
12 | niro | 816 | int fd; |
13 | int i; | ||
14 | unsigned opt; | ||
15 | time_t expires; | ||
16 | niro | 532 | const char *file = LEASES_FILE; |
17 | struct dhcpOfferedAddr lease; | ||
18 | struct in_addr addr; | ||
19 | |||
20 | niro | 816 | enum { |
21 | OPT_a = 0x1, // -a | ||
22 | OPT_r = 0x2, // -r | ||
23 | OPT_f = 0x4, // -f | ||
24 | niro | 532 | }; |
25 | niro | 816 | #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" | ||
30 | ; | ||
31 | niro | 532 | |
32 | niro | 816 | applet_long_options = dumpleases_longopts; |
33 | #endif | ||
34 | opt_complementary = "=0:a--r:r--a"; | ||
35 | opt = getopt32(argv, "arf:", &file); | ||
36 | niro | 532 | |
37 | niro | 816 | fd = xopen(file, O_RDONLY); |
38 | niro | 532 | |
39 | niro | 816 | printf("Mac Address IP-Address Expires %s\n", (opt & OPT_a) ? "at" : "in"); |
40 | niro | 532 | /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */ |
41 | niro | 816 | while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) { |
42 | niro | 532 | printf(":%02x"+1, lease.chaddr[0]); |
43 | for (i = 1; i < 6; i++) { | ||
44 | printf(":%02x", lease.chaddr[i]); | ||
45 | } | ||
46 | addr.s_addr = lease.yiaddr; | ||
47 | printf(" %-15s ", inet_ntoa(addr)); | ||
48 | expires = ntohl(lease.expires); | ||
49 | niro | 816 | if (!(opt & OPT_a)) { /* no -a */ |
50 | niro | 532 | if (!expires) |
51 | niro | 816 | puts("expired"); |
52 | niro | 532 | else { |
53 | unsigned d, h, m; | ||
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); | ||
59 | } | ||
60 | niro | 816 | } else /* -a */ |
61 | fputs(ctime(&expires), stdout); | ||
62 | niro | 532 | } |
63 | niro | 816 | /* close(fd); */ |
64 | niro | 532 | |
65 | return 0; | ||
66 | } |