diff options
author | Keith Young <stripydog7@gmail.com> | 2011-03-07 03:18:46 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-03-07 03:19:42 +0100 |
commit | e6bb8d339fc6897c85c63a5a62d7c4402f7b1a54 (patch) | |
tree | 13ac9b33aff7fabcf87e167fd7cc0d0c9cc52bfc /networking/udhcp/dhcpc.c | |
parent | 82e785cf8cc6e78dd84adc1aee298dfa827a019c (diff) | |
download | busybox-w32-e6bb8d339fc6897c85c63a5a62d7c4402f7b1a54.tar.gz busybox-w32-e6bb8d339fc6897c85c63a5a62d7c4402f7b1a54.tar.bz2 busybox-w32-e6bb8d339fc6897c85c63a5a62d7c4402f7b1a54.zip |
udhcpc: add -B option
function old new delta
udhcpc_longopts - 262 +262
add_client_options 218 239 +21
packed_usage 28149 28163 +14
static.udhcpc_longopts 250 - -250
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 2/0 up/down: 297/-250) Total: 47 bytes
Signed-off-by: Keith Young <stripydog7@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 128 |
1 files changed, 69 insertions, 59 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index d97a404fa..e9a841204 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -38,6 +38,67 @@ | |||
38 | /* struct client_config_t client_config is in bb_common_bufsiz1 */ | 38 | /* struct client_config_t client_config is in bb_common_bufsiz1 */ |
39 | 39 | ||
40 | 40 | ||
41 | #if ENABLE_LONG_OPTS | ||
42 | static const char udhcpc_longopts[] ALIGN1 = | ||
43 | "clientid-none\0" No_argument "C" | ||
44 | "vendorclass\0" Required_argument "V" | ||
45 | "hostname\0" Required_argument "H" | ||
46 | "fqdn\0" Required_argument "F" | ||
47 | "interface\0" Required_argument "i" | ||
48 | "now\0" No_argument "n" | ||
49 | "pidfile\0" Required_argument "p" | ||
50 | "quit\0" No_argument "q" | ||
51 | "release\0" No_argument "R" | ||
52 | "request\0" Required_argument "r" | ||
53 | "script\0" Required_argument "s" | ||
54 | "timeout\0" Required_argument "T" | ||
55 | "version\0" No_argument "v" | ||
56 | "retries\0" Required_argument "t" | ||
57 | "tryagain\0" Required_argument "A" | ||
58 | "syslog\0" No_argument "S" | ||
59 | "request-option\0" Required_argument "O" | ||
60 | "no-default-options\0" No_argument "o" | ||
61 | "foreground\0" No_argument "f" | ||
62 | "background\0" No_argument "b" | ||
63 | "broadcast\0" No_argument "B" | ||
64 | IF_FEATURE_UDHCPC_ARPING("arping\0" No_argument "a") | ||
65 | IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P") | ||
66 | ; | ||
67 | #endif | ||
68 | /* Must match getopt32 option string order */ | ||
69 | enum { | ||
70 | OPT_C = 1 << 0, | ||
71 | OPT_V = 1 << 1, | ||
72 | OPT_H = 1 << 2, | ||
73 | OPT_h = 1 << 3, | ||
74 | OPT_F = 1 << 4, | ||
75 | OPT_i = 1 << 5, | ||
76 | OPT_n = 1 << 6, | ||
77 | OPT_p = 1 << 7, | ||
78 | OPT_q = 1 << 8, | ||
79 | OPT_R = 1 << 9, | ||
80 | OPT_r = 1 << 10, | ||
81 | OPT_s = 1 << 11, | ||
82 | OPT_T = 1 << 12, | ||
83 | OPT_t = 1 << 13, | ||
84 | OPT_S = 1 << 14, | ||
85 | OPT_A = 1 << 15, | ||
86 | OPT_O = 1 << 16, | ||
87 | OPT_o = 1 << 17, | ||
88 | OPT_x = 1 << 18, | ||
89 | OPT_f = 1 << 19, | ||
90 | OPT_B = 1 << 20, | ||
91 | /* The rest has variable bit positions, need to be clever */ | ||
92 | OPTBIT_B = 20, | ||
93 | USE_FOR_MMU( OPTBIT_b,) | ||
94 | IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) | ||
95 | IF_FEATURE_UDHCP_PORT( OPTBIT_P,) | ||
96 | USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,) | ||
97 | IF_FEATURE_UDHCPC_ARPING(OPT_a = 1 << OPTBIT_a,) | ||
98 | IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,) | ||
99 | }; | ||
100 | |||
101 | |||
41 | /*** Script execution code ***/ | 102 | /*** Script execution code ***/ |
42 | 103 | ||
43 | /* get a rough idea of how long an option will be (rounding up...) */ | 104 | /* get a rough idea of how long an option will be (rounding up...) */ |
@@ -391,6 +452,10 @@ static void add_client_options(struct dhcp_packet *packet) | |||
391 | if (client_config.fqdn) | 452 | if (client_config.fqdn) |
392 | udhcp_add_binary_option(packet, client_config.fqdn); | 453 | udhcp_add_binary_option(packet, client_config.fqdn); |
393 | 454 | ||
455 | /* Request broadcast replies if we have no IP addr */ | ||
456 | if ((option_mask32 & OPT_B) && packet->ciaddr == 0) | ||
457 | packet->flags |= htons(BROADCAST_FLAG); | ||
458 | |||
394 | /* Add -x options if any */ | 459 | /* Add -x options if any */ |
395 | { | 460 | { |
396 | struct option_set *curr = client_config.options; | 461 | struct option_set *curr = client_config.options; |
@@ -853,13 +918,14 @@ static void client_background(void) | |||
853 | //usage:# define IF_UDHCP_VERBOSE(...) | 918 | //usage:# define IF_UDHCP_VERBOSE(...) |
854 | //usage:#endif | 919 | //usage:#endif |
855 | //usage:#define udhcpc_trivial_usage | 920 | //usage:#define udhcpc_trivial_usage |
856 | //usage: "[-fbnq"IF_UDHCP_VERBOSE("v")"oCR] [-i IFACE] [-r IP] [-s PROG] [-p PIDFILE]\n" | 921 | //usage: "[-fbnq"IF_UDHCP_VERBOSE("v")"oCRB] [-i IFACE] [-r IP] [-s PROG] [-p PIDFILE]\n" |
857 | //usage: " [-H HOSTNAME] [-V VENDOR] [-x OPT:VAL]... [-O OPT]..." IF_FEATURE_UDHCP_PORT(" [-P N]") | 922 | //usage: " [-H HOSTNAME] [-V VENDOR] [-x OPT:VAL]... [-O OPT]..." IF_FEATURE_UDHCP_PORT(" [-P N]") |
858 | //usage:#define udhcpc_full_usage "\n" | 923 | //usage:#define udhcpc_full_usage "\n" |
859 | //usage: IF_LONG_OPTS( | 924 | //usage: IF_LONG_OPTS( |
860 | //usage: "\n -i,--interface IFACE Interface to use (default eth0)" | 925 | //usage: "\n -i,--interface IFACE Interface to use (default eth0)" |
861 | //usage: "\n -p,--pidfile FILE Create pidfile" | 926 | //usage: "\n -p,--pidfile FILE Create pidfile" |
862 | //usage: "\n -s,--script PROG Run PROG at DHCP events (default "CONFIG_UDHCPC_DEFAULT_SCRIPT")" | 927 | //usage: "\n -s,--script PROG Run PROG at DHCP events (default "CONFIG_UDHCPC_DEFAULT_SCRIPT")" |
928 | //usage: "\n -B,--broadcast Request broadcast replies" | ||
863 | //usage: "\n -t,--retries N Send up to N discover packets" | 929 | //usage: "\n -t,--retries N Send up to N discover packets" |
864 | //usage: "\n -T,--timeout N Pause between packets (default 3 seconds)" | 930 | //usage: "\n -T,--timeout N Pause between packets (default 3 seconds)" |
865 | //usage: "\n -A,--tryagain N Wait N seconds after failure (default 20)" | 931 | //usage: "\n -A,--tryagain N Wait N seconds after failure (default 20)" |
@@ -897,6 +963,7 @@ static void client_background(void) | |||
897 | //usage: "\n -i IFACE Interface to use (default eth0)" | 963 | //usage: "\n -i IFACE Interface to use (default eth0)" |
898 | //usage: "\n -p FILE Create pidfile" | 964 | //usage: "\n -p FILE Create pidfile" |
899 | //usage: "\n -s PROG Run PROG at DHCP events (default "CONFIG_UDHCPC_DEFAULT_SCRIPT")" | 965 | //usage: "\n -s PROG Run PROG at DHCP events (default "CONFIG_UDHCPC_DEFAULT_SCRIPT")" |
966 | //usage: "\n -B Request broadcast replies" | ||
900 | //usage: "\n -t N Send up to N discover packets" | 967 | //usage: "\n -t N Send up to N discover packets" |
901 | //usage: "\n -T N Pause between packets (default 3 seconds)" | 968 | //usage: "\n -T N Pause between packets (default 3 seconds)" |
902 | //usage: "\n -A N Wait N seconds (default 20) after failure" | 969 | //usage: "\n -A N Wait N seconds (default 20) after failure" |
@@ -961,63 +1028,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
961 | struct dhcp_packet packet; | 1028 | struct dhcp_packet packet; |
962 | fd_set rfds; | 1029 | fd_set rfds; |
963 | 1030 | ||
964 | #if ENABLE_LONG_OPTS | ||
965 | static const char udhcpc_longopts[] ALIGN1 = | ||
966 | "clientid-none\0" No_argument "C" | ||
967 | "vendorclass\0" Required_argument "V" | ||
968 | "hostname\0" Required_argument "H" | ||
969 | "fqdn\0" Required_argument "F" | ||
970 | "interface\0" Required_argument "i" | ||
971 | "now\0" No_argument "n" | ||
972 | "pidfile\0" Required_argument "p" | ||
973 | "quit\0" No_argument "q" | ||
974 | "release\0" No_argument "R" | ||
975 | "request\0" Required_argument "r" | ||
976 | "script\0" Required_argument "s" | ||
977 | "timeout\0" Required_argument "T" | ||
978 | "version\0" No_argument "v" | ||
979 | "retries\0" Required_argument "t" | ||
980 | "tryagain\0" Required_argument "A" | ||
981 | "syslog\0" No_argument "S" | ||
982 | "request-option\0" Required_argument "O" | ||
983 | "no-default-options\0" No_argument "o" | ||
984 | "foreground\0" No_argument "f" | ||
985 | "background\0" No_argument "b" | ||
986 | IF_FEATURE_UDHCPC_ARPING("arping\0" No_argument "a") | ||
987 | IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P") | ||
988 | ; | ||
989 | #endif | ||
990 | enum { | ||
991 | OPT_C = 1 << 0, | ||
992 | OPT_V = 1 << 1, | ||
993 | OPT_H = 1 << 2, | ||
994 | OPT_h = 1 << 3, | ||
995 | OPT_F = 1 << 4, | ||
996 | OPT_i = 1 << 5, | ||
997 | OPT_n = 1 << 6, | ||
998 | OPT_p = 1 << 7, | ||
999 | OPT_q = 1 << 8, | ||
1000 | OPT_R = 1 << 9, | ||
1001 | OPT_r = 1 << 10, | ||
1002 | OPT_s = 1 << 11, | ||
1003 | OPT_T = 1 << 12, | ||
1004 | OPT_t = 1 << 13, | ||
1005 | OPT_S = 1 << 14, | ||
1006 | OPT_A = 1 << 15, | ||
1007 | OPT_O = 1 << 16, | ||
1008 | OPT_o = 1 << 17, | ||
1009 | OPT_x = 1 << 18, | ||
1010 | OPT_f = 1 << 19, | ||
1011 | /* The rest has variable bit positions, need to be clever */ | ||
1012 | OPTBIT_f = 19, | ||
1013 | USE_FOR_MMU( OPTBIT_b,) | ||
1014 | IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) | ||
1015 | IF_FEATURE_UDHCP_PORT( OPTBIT_P,) | ||
1016 | USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,) | ||
1017 | IF_FEATURE_UDHCPC_ARPING(OPT_a = 1 << OPTBIT_a,) | ||
1018 | IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,) | ||
1019 | }; | ||
1020 | |||
1021 | /* Default options */ | 1031 | /* Default options */ |
1022 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) | 1032 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) |
1023 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) | 1033 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) |
@@ -1033,7 +1043,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1033 | #endif | 1043 | #endif |
1034 | ; | 1044 | ; |
1035 | IF_LONG_OPTS(applet_long_options = udhcpc_longopts;) | 1045 | IF_LONG_OPTS(applet_long_options = udhcpc_longopts;) |
1036 | opt = getopt32(argv, "CV:H:h:F:i:np:qRr:s:T:t:SA:O:ox:f" | 1046 | opt = getopt32(argv, "CV:H:h:F:i:np:qRr:s:T:t:SA:O:ox:fB" |
1037 | USE_FOR_MMU("b") | 1047 | USE_FOR_MMU("b") |
1038 | IF_FEATURE_UDHCPC_ARPING("a") | 1048 | IF_FEATURE_UDHCPC_ARPING("a") |
1039 | IF_FEATURE_UDHCP_PORT("P:") | 1049 | IF_FEATURE_UDHCP_PORT("P:") |