From e6bb8d339fc6897c85c63a5a62d7c4402f7b1a54 Mon Sep 17 00:00:00 2001 From: Keith Young Date: Mon, 7 Mar 2011 03:18:46 +0100 Subject: [PATCH] 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 Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpc.c | 128 +++++++++++++++++++++------------------ 1 file 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 @@ /* struct client_config_t client_config is in bb_common_bufsiz1 */ +#if ENABLE_LONG_OPTS +static const char udhcpc_longopts[] ALIGN1 = + "clientid-none\0" No_argument "C" + "vendorclass\0" Required_argument "V" + "hostname\0" Required_argument "H" + "fqdn\0" Required_argument "F" + "interface\0" Required_argument "i" + "now\0" No_argument "n" + "pidfile\0" Required_argument "p" + "quit\0" No_argument "q" + "release\0" No_argument "R" + "request\0" Required_argument "r" + "script\0" Required_argument "s" + "timeout\0" Required_argument "T" + "version\0" No_argument "v" + "retries\0" Required_argument "t" + "tryagain\0" Required_argument "A" + "syslog\0" No_argument "S" + "request-option\0" Required_argument "O" + "no-default-options\0" No_argument "o" + "foreground\0" No_argument "f" + "background\0" No_argument "b" + "broadcast\0" No_argument "B" + IF_FEATURE_UDHCPC_ARPING("arping\0" No_argument "a") + IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P") + ; +#endif +/* Must match getopt32 option string order */ +enum { + OPT_C = 1 << 0, + OPT_V = 1 << 1, + OPT_H = 1 << 2, + OPT_h = 1 << 3, + OPT_F = 1 << 4, + OPT_i = 1 << 5, + OPT_n = 1 << 6, + OPT_p = 1 << 7, + OPT_q = 1 << 8, + OPT_R = 1 << 9, + OPT_r = 1 << 10, + OPT_s = 1 << 11, + OPT_T = 1 << 12, + OPT_t = 1 << 13, + OPT_S = 1 << 14, + OPT_A = 1 << 15, + OPT_O = 1 << 16, + OPT_o = 1 << 17, + OPT_x = 1 << 18, + OPT_f = 1 << 19, + OPT_B = 1 << 20, +/* The rest has variable bit positions, need to be clever */ + OPTBIT_B = 20, + USE_FOR_MMU( OPTBIT_b,) + IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) + IF_FEATURE_UDHCP_PORT( OPTBIT_P,) + USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,) + IF_FEATURE_UDHCPC_ARPING(OPT_a = 1 << OPTBIT_a,) + IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,) +}; + + /*** Script execution code ***/ /* 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) if (client_config.fqdn) udhcp_add_binary_option(packet, client_config.fqdn); + /* Request broadcast replies if we have no IP addr */ + if ((option_mask32 & OPT_B) && packet->ciaddr == 0) + packet->flags |= htons(BROADCAST_FLAG); + /* Add -x options if any */ { struct option_set *curr = client_config.options; @@ -853,13 +918,14 @@ static void client_background(void) //usage:# define IF_UDHCP_VERBOSE(...) //usage:#endif //usage:#define udhcpc_trivial_usage -//usage: "[-fbnq"IF_UDHCP_VERBOSE("v")"oCR] [-i IFACE] [-r IP] [-s PROG] [-p PIDFILE]\n" +//usage: "[-fbnq"IF_UDHCP_VERBOSE("v")"oCRB] [-i IFACE] [-r IP] [-s PROG] [-p PIDFILE]\n" //usage: " [-H HOSTNAME] [-V VENDOR] [-x OPT:VAL]... [-O OPT]..." IF_FEATURE_UDHCP_PORT(" [-P N]") //usage:#define udhcpc_full_usage "\n" //usage: IF_LONG_OPTS( //usage: "\n -i,--interface IFACE Interface to use (default eth0)" //usage: "\n -p,--pidfile FILE Create pidfile" //usage: "\n -s,--script PROG Run PROG at DHCP events (default "CONFIG_UDHCPC_DEFAULT_SCRIPT")" +//usage: "\n -B,--broadcast Request broadcast replies" //usage: "\n -t,--retries N Send up to N discover packets" //usage: "\n -T,--timeout N Pause between packets (default 3 seconds)" //usage: "\n -A,--tryagain N Wait N seconds after failure (default 20)" @@ -897,6 +963,7 @@ static void client_background(void) //usage: "\n -i IFACE Interface to use (default eth0)" //usage: "\n -p FILE Create pidfile" //usage: "\n -s PROG Run PROG at DHCP events (default "CONFIG_UDHCPC_DEFAULT_SCRIPT")" +//usage: "\n -B Request broadcast replies" //usage: "\n -t N Send up to N discover packets" //usage: "\n -T N Pause between packets (default 3 seconds)" //usage: "\n -A N Wait N seconds (default 20) after failure" @@ -961,63 +1028,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) struct dhcp_packet packet; fd_set rfds; -#if ENABLE_LONG_OPTS - static const char udhcpc_longopts[] ALIGN1 = - "clientid-none\0" No_argument "C" - "vendorclass\0" Required_argument "V" - "hostname\0" Required_argument "H" - "fqdn\0" Required_argument "F" - "interface\0" Required_argument "i" - "now\0" No_argument "n" - "pidfile\0" Required_argument "p" - "quit\0" No_argument "q" - "release\0" No_argument "R" - "request\0" Required_argument "r" - "script\0" Required_argument "s" - "timeout\0" Required_argument "T" - "version\0" No_argument "v" - "retries\0" Required_argument "t" - "tryagain\0" Required_argument "A" - "syslog\0" No_argument "S" - "request-option\0" Required_argument "O" - "no-default-options\0" No_argument "o" - "foreground\0" No_argument "f" - "background\0" No_argument "b" - IF_FEATURE_UDHCPC_ARPING("arping\0" No_argument "a") - IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P") - ; -#endif - enum { - OPT_C = 1 << 0, - OPT_V = 1 << 1, - OPT_H = 1 << 2, - OPT_h = 1 << 3, - OPT_F = 1 << 4, - OPT_i = 1 << 5, - OPT_n = 1 << 6, - OPT_p = 1 << 7, - OPT_q = 1 << 8, - OPT_R = 1 << 9, - OPT_r = 1 << 10, - OPT_s = 1 << 11, - OPT_T = 1 << 12, - OPT_t = 1 << 13, - OPT_S = 1 << 14, - OPT_A = 1 << 15, - OPT_O = 1 << 16, - OPT_o = 1 << 17, - OPT_x = 1 << 18, - OPT_f = 1 << 19, -/* The rest has variable bit positions, need to be clever */ - OPTBIT_f = 19, - USE_FOR_MMU( OPTBIT_b,) - IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) - IF_FEATURE_UDHCP_PORT( OPTBIT_P,) - USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,) - IF_FEATURE_UDHCPC_ARPING(OPT_a = 1 << OPTBIT_a,) - IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,) - }; - /* Default options */ IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) @@ -1033,7 +1043,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) #endif ; IF_LONG_OPTS(applet_long_options = udhcpc_longopts;) - opt = getopt32(argv, "CV:H:h:F:i:np:qRr:s:T:t:SA:O:ox:f" + opt = getopt32(argv, "CV:H:h:F:i:np:qRr:s:T:t:SA:O:ox:fB" USE_FOR_MMU("b") IF_FEATURE_UDHCPC_ARPING("a") IF_FEATURE_UDHCP_PORT("P:") -- 2.25.1