Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 532 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 2  Line 2 
2  /*  /*
3   * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.   * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
4   */   */
 #include <getopt.h>  
5    
6  #include "common.h"  #include "common.h"
7  #include "dhcpd.h"  #include "dhcpd.h"
8    
9    int dumpleases_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
10  #define REMAINING 0  int dumpleases_main(int argc UNUSED_PARAM, char **argv)
 #define ABSOLUTE 1  
   
 int dumpleases_main(int argc, char *argv[])  
11  {  {
12   int fp;   int fd;
13   int i, c, mode = REMAINING;   int i;
14   unsigned long expires;   unsigned opt;
15     time_t expires;
16   const char *file = LEASES_FILE;   const char *file = LEASES_FILE;
17   struct dhcpOfferedAddr lease;   struct dhcpOfferedAddr lease;
18   struct in_addr addr;   struct in_addr addr;
19    
20   static const struct option options[] = {   enum {
21   {"absolute", 0, 0, 'a'},   OPT_a = 0x1, // -a
22   {"remaining", 0, 0, 'r'},   OPT_r = 0x2, // -r
23   {"file", 1, 0, 'f'},   OPT_f = 0x4, // -f
  {0, 0, 0, 0}  
24   };   };
25    #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    
32     applet_long_options = dumpleases_longopts;
33    #endif
34     opt_complementary = "=0:a--r:r--a";
35     opt = getopt32(argv, "arf:", &file);
36    
37   while (1) {   fd = xopen(file, O_RDONLY);
  int option_index = 0;  
  c = getopt_long(argc, argv, "arf:", options, &option_index);  
  if (c == -1) break;  
   
  switch (c) {  
  case 'a': mode = ABSOLUTE; break;  
  case 'r': mode = REMAINING; break;  
  case 'f':  
  file = optarg;  
  break;  
  default:  
  bb_show_usage();  
  }  
  }  
   
  fp = xopen(file, O_RDONLY);  
38    
39   printf("Mac Address       IP-Address      Expires %s\n", mode == REMAINING ? "in" : "at");   printf("Mac Address       IP-Address      Expires %s\n", (opt & OPT_a) ? "at" : "in");
40   /*     "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */   /*     "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */
41   while (full_read(fp, &lease, sizeof(lease)) == sizeof(lease)) {   while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
42   printf(":%02x"+1, lease.chaddr[0]);   printf(":%02x"+1, lease.chaddr[0]);
43   for (i = 1; i < 6; i++) {   for (i = 1; i < 6; i++) {
44   printf(":%02x", lease.chaddr[i]);   printf(":%02x", lease.chaddr[i]);
# Line 55  int dumpleases_main(int argc, char *argv Line 46  int dumpleases_main(int argc, char *argv
46   addr.s_addr = lease.yiaddr;   addr.s_addr = lease.yiaddr;
47   printf(" %-15s ", inet_ntoa(addr));   printf(" %-15s ", inet_ntoa(addr));
48   expires = ntohl(lease.expires);   expires = ntohl(lease.expires);
49   if (mode == REMAINING) {   if (!(opt & OPT_a)) { /* no -a */
50   if (!expires)   if (!expires)
51   printf("expired\n");   puts("expired");
52   else {   else {
53   unsigned d, h, m;   unsigned d, h, m;
54   d = expires / (24*60*60); expires %= (24*60*60);   d = expires / (24*60*60); expires %= (24*60*60);
# Line 66  int dumpleases_main(int argc, char *argv Line 57  int dumpleases_main(int argc, char *argv
57   if (d) printf("%u days ", d);   if (d) printf("%u days ", d);
58   printf("%02u:%02u:%02u\n", h, m, (unsigned)expires);   printf("%02u:%02u:%02u\n", h, m, (unsigned)expires);
59   }   }
60   } else fputs(ctime(&expires), stdout);   } else /* -a */
61     fputs(ctime(&expires), stdout);
62   }   }
63   /* close(fp); */   /* close(fd); */
64    
65   return 0;   return 0;
66  }  }

Legend:
Removed from v.532  
changed lines
  Added in v.816