aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/dumpleases.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/dumpleases.c')
-rw-r--r--networking/udhcp/dumpleases.c44
1 files changed, 10 insertions, 34 deletions
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c
index 014f73f9d..4c6107cf7 100644
--- a/networking/udhcp/dumpleases.c
+++ b/networking/udhcp/dumpleases.c
@@ -1,79 +1,55 @@
1#include <fcntl.h> 1#include <fcntl.h>
2#include <string.h> 2#include <string.h>
3#include <stdlib.h> 3#include <stdlib.h>
4#include <stdio.h>
5#include <sys/wait.h> 4#include <sys/wait.h>
6#include <sys/stat.h>
7#include <arpa/inet.h> 5#include <arpa/inet.h>
8#include <netdb.h> 6#include <netdb.h>
9#include <netinet/in.h> 7#include <netinet/in.h>
10#include <stdio.h> 8#include <stdio.h>
11#include <sys/types.h>
12#include <sys/socket.h> 9#include <sys/socket.h>
13#include <unistd.h> 10#include <unistd.h>
14#include <syslog.h>
15#include <signal.h>
16#include <errno.h>
17#include <getopt.h> 11#include <getopt.h>
18#include <time.h> 12#include <time.h>
19 13
20#include "libbb_udhcp.h" 14#include "leases.h"
15#include "busybox.h"
21 16
22#define REMAINING 0 17#define REMAINING 0
23#define ABSOLUTE 1 18#define ABSOLUTE 1
24 19
25struct lease_t {
26 unsigned char chaddr[16];
27 u_int32_t yiaddr;
28 u_int32_t expires;
29};
30
31#ifdef IN_BUSYBOX
32int dumpleases_main(int argc, char *argv[]) 20int dumpleases_main(int argc, char *argv[])
33#else
34int main(int argc, char *argv[])
35#endif
36{ 21{
37 FILE *fp; 22 FILE *fp;
38 int i, c, mode = REMAINING; 23 int i, c, mode = REMAINING;
39 long expires; 24 long expires;
40 char file[255] = "/var/lib/misc/udhcpd.leases"; 25 const char *file = leases_file;
41 struct lease_t lease; 26 struct dhcpOfferedAddr lease;
42 struct in_addr addr; 27 struct in_addr addr;
43 28
44 static struct option options[] = { 29 static const struct option options[] = {
45 {"absolute", 0, 0, 'a'}, 30 {"absolute", 0, 0, 'a'},
46 {"remaining", 0, 0, 'r'}, 31 {"remaining", 0, 0, 'r'},
47 {"file", 1, 0, 'f'}, 32 {"file", 1, 0, 'f'},
48 {"help", 0, 0, 'h'},
49 {0, 0, 0, 0} 33 {0, 0, 0, 0}
50 }; 34 };
51 35
52 while (1) { 36 while (1) {
53 int option_index = 0; 37 int option_index = 0;
54 c = getopt_long(argc, argv, "arf:h", options, &option_index); 38 c = getopt_long(argc, argv, "arf:", options, &option_index);
55 if (c == -1) break; 39 if (c == -1) break;
56 40
57 switch (c) { 41 switch (c) {
58 case 'a': mode = ABSOLUTE; break; 42 case 'a': mode = ABSOLUTE; break;
59 case 'r': mode = REMAINING; break; 43 case 'r': mode = REMAINING; break;
60 case 'f': 44 case 'f':
61 strncpy(file, optarg, 255); 45 file = optarg;
62 file[254] = '\0';
63 break;
64 case 'h':
65 printf("Usage: dumpleases -f <file> -[r|a]\n\n");
66 printf(" -f, --file=FILENAME Leases file to load\n");
67 printf(" -r, --remaining Interepret lease times as time remaing\n");
68 printf(" -a, --absolute Interepret lease times as expire time\n");
69 break; 46 break;
47 default:
48 bb_show_usage();
70 } 49 }
71 } 50 }
72 51
73 if (!(fp = fopen(file, "r"))) { 52 fp = bb_xfopen(file, "r");
74 perror("could not open input file");
75 return 0;
76 }
77 53
78 printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at"); 54 printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at");
79 /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */ 55 /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */