Magellan Linux

Contents of /trunk/mkinitrd-magellan/busybox/networking/udhcp/dumpleases.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1714 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 /* vi: set sw=4 ts=4: */
2 /*
3 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
4 */
5 #include <getopt.h>
6
7 #include "common.h"
8 #include "dhcpd.h"
9
10
11 #define REMAINING 0
12 #define ABSOLUTE 1
13
14 int dumpleases_main(int argc, char *argv[])
15 {
16 int fp;
17 int i, c, mode = REMAINING;
18 unsigned long expires;
19 const char *file = LEASES_FILE;
20 struct dhcpOfferedAddr lease;
21 struct in_addr addr;
22
23 static const struct option options[] = {
24 {"absolute", 0, 0, 'a'},
25 {"remaining", 0, 0, 'r'},
26 {"file", 1, 0, 'f'},
27 {0, 0, 0, 0}
28 };
29
30 while (1) {
31 int option_index = 0;
32 c = getopt_long(argc, argv, "arf:", options, &option_index);
33 if (c == -1) break;
34
35 switch (c) {
36 case 'a': mode = ABSOLUTE; break;
37 case 'r': mode = REMAINING; break;
38 case 'f':
39 file = optarg;
40 break;
41 default:
42 bb_show_usage();
43 }
44 }
45
46 fp = xopen(file, O_RDONLY);
47
48 printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at");
49 /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */
50 while (full_read(fp, &lease, sizeof(lease)) == sizeof(lease)) {
51 printf(":%02x"+1, lease.chaddr[0]);
52 for (i = 1; i < 6; i++) {
53 printf(":%02x", lease.chaddr[i]);
54 }
55 addr.s_addr = lease.yiaddr;
56 printf(" %-15s ", inet_ntoa(addr));
57 expires = ntohl(lease.expires);
58 if (mode == REMAINING) {
59 if (!expires)
60 printf("expired\n");
61 else {
62 unsigned d, h, m;
63 d = expires / (24*60*60); expires %= (24*60*60);
64 h = expires / (60*60); expires %= (60*60);
65 m = expires / 60; expires %= 60;
66 if (d) printf("%u days ", d);
67 printf("%02u:%02u:%02u\n", h, m, (unsigned)expires);
68 }
69 } else fputs(ctime(&expires), stdout);
70 }
71 /* close(fp); */
72
73 return 0;
74 }