Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/networking/udhcp/dumpleases.c

    r3232 r3621  
    55
    66//usage:#define dumpleases_trivial_usage
    7 //usage:       "[-r|-a] [-f LEASEFILE]"
     7//usage:       "[-r|-a] [-d] [-f LEASEFILE]"
    88//usage:#define dumpleases_full_usage "\n\n"
    99//usage:       "Display DHCP leases granted by udhcpd\n"
     
    1212//usage:     "\n    -r,--remaining  Show remaining time"
    1313//usage:     "\n    -a,--absolute   Show expiration time"
     14//usage:     "\n    -d,--decimal    Show time in seconds"
    1415//usage:    )
    1516//usage:    IF_NOT_LONG_OPTS(
     
    1718//usage:     "\n    -r  Show remaining time"
    1819//usage:     "\n    -a  Show expiration time"
     20//usage:     "\n    -d  Show time in seconds"
    1921//usage:    )
    2022
     
    2931    int i;
    3032    unsigned opt;
    31     int64_t written_at, curr, expires_abs;
     33    int64_t written_at, curr;
    3234    const char *file = LEASES_FILE;
    3335    struct dyn_lease lease;
    34     struct in_addr addr;
    3536
    3637    enum {
     
    3839        OPT_r = 0x2, // -r
    3940        OPT_f = 0x4, // -f
     41        OPT_d = 0x8, // -d
    4042    };
    4143#if ENABLE_LONG_OPTS
     
    4446        "remaining\0" No_argument       "r"
    4547        "file\0"      Required_argument "f"
     48        "decimal\0"   No_argument       "d"
    4649        ;
    4750
     
    5154
    5255    opt_complementary = "=0:a--r:r--a";
    53     opt = getopt32(argv, "arf:", &file);
     56    opt = getopt32(argv, "arf:d", &file);
    5457
    5558    fd = xopen(file, O_RDONLY);
    5659
    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 */
    5861    /*     "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    );
    6066
    6167    xread(fd, &written_at, sizeof(written_at));
     
    6672
    6773    while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
     74        struct in_addr addr;
     75        int64_t expires_abs;
     76
    6877        const char *fmt = ":%02x" + 1;
    6978        for (i = 0; i < 6; i++) {
     
    8897            continue;
    8998        }
     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        }
    90106        if (!(opt & OPT_a)) { /* no -a */
    91107            unsigned d, h, m;
Note: See TracChangeset for help on using the changeset viewer.