diff options
-rw-r--r-- | networking/udhcp/dhcpc.c | 31 | ||||
-rw-r--r-- | networking/udhcp/dumpleases.c | 29 | ||||
-rw-r--r-- | networking/udhcp/libbb_udhcp.h | 26 |
3 files changed, 80 insertions, 6 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index d18a963a9..55664abf9 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -75,6 +75,35 @@ struct client_config_t client_config = { | |||
75 | arp: "\0\0\0\0\0\0", /* appease gcc-3.0 */ | 75 | arp: "\0\0\0\0\0\0", /* appease gcc-3.0 */ |
76 | }; | 76 | }; |
77 | 77 | ||
78 | #ifndef IN_BUSYBOX | ||
79 | static void __attribute__ ((noreturn)) show_usage(void) | ||
80 | { | ||
81 | printf( | ||
82 | "Usage: udhcpc [OPTIONS]\n\n" | ||
83 | " -c, --clientid=CLIENTID Client identifier\n" | ||
84 | " -H, --hostname=HOSTNAME Client hostname\n" | ||
85 | " -h Alias for -H\n" | ||
86 | " -f, --foreground Do not fork after getting lease\n" | ||
87 | " -b, --background Fork to background if lease cannot be\n" | ||
88 | " immediately negotiated.\n" | ||
89 | " -i, --interface=INTERFACE Interface to use (default: eth0)\n" | ||
90 | " -n, --now Exit with failure if lease cannot be\n" | ||
91 | " immediately negotiated.\n" | ||
92 | " -p, --pidfile=file Store process ID of daemon in file\n" | ||
93 | " -q, --quit Quit after obtaining lease\n" | ||
94 | " -r, --request=IP IP address to request (default: none)\n" | ||
95 | " -s, --script=file Run file at dhcp events (default:\n" | ||
96 | " " DEFAULT_SCRIPT ")\n" | ||
97 | " -v, --version Display version\n" | ||
98 | ); | ||
99 | exit(0); | ||
100 | } | ||
101 | #else | ||
102 | #define show_usage bb_show_usage | ||
103 | extern void show_usage(void) __attribute__ ((noreturn)); | ||
104 | #endif | ||
105 | |||
106 | |||
78 | /* just a little helper */ | 107 | /* just a little helper */ |
79 | static void change_mode(int new_mode) | 108 | static void change_mode(int new_mode) |
80 | { | 109 | { |
@@ -233,7 +262,7 @@ int udhcpc_main(int argc, char *argv[]) | |||
233 | return(0); | 262 | return(0); |
234 | break; | 263 | break; |
235 | default: | 264 | default: |
236 | bb_show_usage(); | 265 | show_usage(); |
237 | } | 266 | } |
238 | } | 267 | } |
239 | 268 | ||
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c index 4c6107cf7..5cb3a156f 100644 --- a/networking/udhcp/dumpleases.c +++ b/networking/udhcp/dumpleases.c | |||
@@ -1,6 +1,7 @@ | |||
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> | ||
4 | #include <sys/wait.h> | 5 | #include <sys/wait.h> |
5 | #include <arpa/inet.h> | 6 | #include <arpa/inet.h> |
6 | #include <netdb.h> | 7 | #include <netdb.h> |
@@ -12,12 +13,32 @@ | |||
12 | #include <time.h> | 13 | #include <time.h> |
13 | 14 | ||
14 | #include "leases.h" | 15 | #include "leases.h" |
15 | #include "busybox.h" | 16 | #include "libbb_udhcp.h" |
16 | 17 | ||
17 | #define REMAINING 0 | 18 | #define REMAINING 0 |
18 | #define ABSOLUTE 1 | 19 | #define ABSOLUTE 1 |
19 | 20 | ||
21 | |||
22 | #ifndef IN_BUSYBOX | ||
23 | static void __attribute__ ((noreturn)) show_usage(void) | ||
24 | { | ||
25 | printf( | ||
26 | "Usage: dumpleases -f <file> -[r|a]\n\n" | ||
27 | " -f, --file=FILENAME Leases file to load\n" | ||
28 | " -r, --remaining Interepret lease times as time remaing\n" | ||
29 | " -a, --absolute Interepret lease times as expire time\n"); | ||
30 | exit(0); | ||
31 | } | ||
32 | #else | ||
33 | #define show_usage bb_show_usage | ||
34 | #endif | ||
35 | |||
36 | |||
37 | #ifdef IN_BUSYBOX | ||
20 | int dumpleases_main(int argc, char *argv[]) | 38 | int dumpleases_main(int argc, char *argv[]) |
39 | #else | ||
40 | int main(int argc, char *argv[]) | ||
41 | #endif | ||
21 | { | 42 | { |
22 | FILE *fp; | 43 | FILE *fp; |
23 | int i, c, mode = REMAINING; | 44 | int i, c, mode = REMAINING; |
@@ -42,14 +63,14 @@ int dumpleases_main(int argc, char *argv[]) | |||
42 | case 'a': mode = ABSOLUTE; break; | 63 | case 'a': mode = ABSOLUTE; break; |
43 | case 'r': mode = REMAINING; break; | 64 | case 'r': mode = REMAINING; break; |
44 | case 'f': | 65 | case 'f': |
45 | file = optarg; | 66 | file = optarg; |
46 | break; | 67 | break; |
47 | default: | 68 | default: |
48 | bb_show_usage(); | 69 | show_usage(); |
49 | } | 70 | } |
50 | } | 71 | } |
51 | 72 | ||
52 | fp = bb_xfopen(file, "r"); | 73 | fp = xfopen(file, "r"); |
53 | 74 | ||
54 | printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at"); | 75 | printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at"); |
55 | /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */ | 76 | /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */ |
diff --git a/networking/udhcp/libbb_udhcp.h b/networking/udhcp/libbb_udhcp.h index e09429808..73e21464f 100644 --- a/networking/udhcp/libbb_udhcp.h +++ b/networking/udhcp/libbb_udhcp.h | |||
@@ -4,7 +4,7 @@ | |||
4 | #define _LIBBB_UDHCP_H | 4 | #define _LIBBB_UDHCP_H |
5 | 5 | ||
6 | #ifdef IN_BUSYBOX | 6 | #ifdef IN_BUSYBOX |
7 | #include "libbb.h" | 7 | #include "busybox.h" |
8 | 8 | ||
9 | #ifdef CONFIG_FEATURE_UDHCP_SYSLOG | 9 | #ifdef CONFIG_FEATURE_UDHCP_SYSLOG |
10 | #define SYSLOG | 10 | #define SYSLOG |
@@ -17,12 +17,36 @@ | |||
17 | #define COMBINED_BINARY | 17 | #define COMBINED_BINARY |
18 | #include "version.h" | 18 | #include "version.h" |
19 | 19 | ||
20 | #ifdef CONFIG_INSTALL_NO_USR | ||
21 | #define DEFAULT_SCRIPT "/share/udhcpc/default.script" | ||
22 | #else | ||
23 | #define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script" | ||
24 | #endif | ||
25 | |||
26 | #define xfopen bb_xfopen | ||
27 | |||
20 | #else /* ! BB_VER */ | 28 | #else /* ! BB_VER */ |
21 | 29 | ||
30 | #include <stdlib.h> | ||
31 | #include <stdio.h> | ||
32 | |||
22 | #define TRUE 1 | 33 | #define TRUE 1 |
23 | #define FALSE 0 | 34 | #define FALSE 0 |
24 | 35 | ||
25 | #define xmalloc malloc | 36 | #define xmalloc malloc |
37 | #define xcalloc calloc | ||
38 | |||
39 | #define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script" | ||
40 | |||
41 | static inline FILE *xfopen(const char *file, const char *mode) | ||
42 | { | ||
43 | FILE *fp; | ||
44 | if (!(fp = fopen(file, mode))) { | ||
45 | perror("could not open input file"); | ||
46 | exit(0); | ||
47 | } | ||
48 | return fp; | ||
49 | } | ||
26 | 50 | ||
27 | #endif /* BB_VER */ | 51 | #endif /* BB_VER */ |
28 | 52 | ||