Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/networking/udhcp/dumpleases.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/networking/udhcp/dumpleases.c
r3232 r3621 5 5 6 6 //usage:#define dumpleases_trivial_usage 7 //usage: "[-r|-a] [- f LEASEFILE]"7 //usage: "[-r|-a] [-d] [-f LEASEFILE]" 8 8 //usage:#define dumpleases_full_usage "\n\n" 9 9 //usage: "Display DHCP leases granted by udhcpd\n" … … 12 12 //usage: "\n -r,--remaining Show remaining time" 13 13 //usage: "\n -a,--absolute Show expiration time" 14 //usage: "\n -d,--decimal Show time in seconds" 14 15 //usage: ) 15 16 //usage: IF_NOT_LONG_OPTS( … … 17 18 //usage: "\n -r Show remaining time" 18 19 //usage: "\n -a Show expiration time" 20 //usage: "\n -d Show time in seconds" 19 21 //usage: ) 20 22 … … 29 31 int i; 30 32 unsigned opt; 31 int64_t written_at, curr , expires_abs;33 int64_t written_at, curr; 32 34 const char *file = LEASES_FILE; 33 35 struct dyn_lease lease; 34 struct in_addr addr;35 36 36 37 enum { … … 38 39 OPT_r = 0x2, // -r 39 40 OPT_f = 0x4, // -f 41 OPT_d = 0x8, // -d 40 42 }; 41 43 #if ENABLE_LONG_OPTS … … 44 46 "remaining\0" No_argument "r" 45 47 "file\0" Required_argument "f" 48 "decimal\0" No_argument "d" 46 49 ; 47 50 … … 51 54 52 55 opt_complementary = "=0:a--r:r--a"; 53 opt = getopt32(argv, "arf: ", &file);56 opt = getopt32(argv, "arf:d", &file); 54 57 55 58 fd = xopen(file, O_RDONLY); 56 59 57 printf("Mac Address IP Address Host Name Expires %s\n", (opt & OPT_a) ? "at" : "in");60 /* "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 */ 58 61 /* "00:00:00:00:00:00 255.255.255.255 ABCDEFGHIJKLMNOPQRS Wed Jun 30 21:49:08 1993" */ 59 /* "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 */ 62 printf("Mac %-14s" "IP %-13s" "Host %-15s" "Expires %s\n", 63 "Address", "Address", "Name", 64 (opt & OPT_a) ? "at" : "in" 65 ); 60 66 61 67 xread(fd, &written_at, sizeof(written_at)); … … 66 72 67 73 while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) { 74 struct in_addr addr; 75 int64_t expires_abs; 76 68 77 const char *fmt = ":%02x" + 1; 69 78 for (i = 0; i < 6; i++) { … … 88 97 continue; 89 98 } 99 if (opt & OPT_d) { 100 /* -d: decimal time */ 101 if (!(opt & OPT_a)) 102 expires_abs -= curr; 103 printf("%llu\n", (unsigned long long) expires_abs); 104 continue; 105 } 90 106 if (!(opt & OPT_a)) { /* no -a */ 91 107 unsigned d, h, m;
Note:
See TracChangeset
for help on using the changeset viewer.