diff options
Diffstat (limited to 'busybox/networking/udhcp/dhcpc.c')
-rw-r--r-- | busybox/networking/udhcp/dhcpc.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/busybox/networking/udhcp/dhcpc.c b/busybox/networking/udhcp/dhcpc.c index 91af9153b..e89affe1f 100644 --- a/busybox/networking/udhcp/dhcpc.c +++ b/busybox/networking/udhcp/dhcpc.c | |||
@@ -76,7 +76,8 @@ static void __attribute__ ((noreturn)) show_usage(void) | |||
76 | { | 76 | { |
77 | printf( | 77 | printf( |
78 | "Usage: udhcpc [OPTIONS]\n\n" | 78 | "Usage: udhcpc [OPTIONS]\n\n" |
79 | " -c, --clientid=CLIENTID Client identifier\n" | 79 | " -c, --clientid=CLIENTID Set client identifier\n" |
80 | " -C, --clientid-none Suppress default client identifier\n" | ||
80 | " -H, --hostname=HOSTNAME Client hostname\n" | 81 | " -H, --hostname=HOSTNAME Client hostname\n" |
81 | " -h Alias for -H\n" | 82 | " -h Alias for -H\n" |
82 | " -f, --foreground Do not fork after getting lease\n" | 83 | " -f, --foreground Do not fork after getting lease\n" |
@@ -191,9 +192,11 @@ int main(int argc, char *argv[]) | |||
191 | long now; | 192 | long now; |
192 | int max_fd; | 193 | int max_fd; |
193 | int sig; | 194 | int sig; |
195 | int no_clientid = 0; | ||
194 | 196 | ||
195 | static const struct option arg_options[] = { | 197 | static const struct option arg_options[] = { |
196 | {"clientid", required_argument, 0, 'c'}, | 198 | {"clientid", required_argument, 0, 'c'}, |
199 | {"clientid-none", no_argument, 0, 'C'}, | ||
197 | {"foreground", no_argument, 0, 'f'}, | 200 | {"foreground", no_argument, 0, 'f'}, |
198 | {"background", no_argument, 0, 'b'}, | 201 | {"background", no_argument, 0, 'b'}, |
199 | {"hostname", required_argument, 0, 'H'}, | 202 | {"hostname", required_argument, 0, 'H'}, |
@@ -211,11 +214,12 @@ int main(int argc, char *argv[]) | |||
211 | /* get options */ | 214 | /* get options */ |
212 | while (1) { | 215 | while (1) { |
213 | int option_index = 0; | 216 | int option_index = 0; |
214 | c = getopt_long(argc, argv, "c:fbH:h:i:np:qr:s:v", arg_options, &option_index); | 217 | c = getopt_long(argc, argv, "c:CfbH:h:i:np:qr:s:v", arg_options, &option_index); |
215 | if (c == -1) break; | 218 | if (c == -1) break; |
216 | 219 | ||
217 | switch (c) { | 220 | switch (c) { |
218 | case 'c': | 221 | case 'c': |
222 | if (no_clientid) show_usage(); | ||
219 | len = strlen(optarg) > 255 ? 255 : strlen(optarg); | 223 | len = strlen(optarg) > 255 ? 255 : strlen(optarg); |
220 | if (client_config.clientid) free(client_config.clientid); | 224 | if (client_config.clientid) free(client_config.clientid); |
221 | client_config.clientid = xmalloc(len + 2); | 225 | client_config.clientid = xmalloc(len + 2); |
@@ -224,6 +228,10 @@ int main(int argc, char *argv[]) | |||
224 | client_config.clientid[OPT_DATA] = '\0'; | 228 | client_config.clientid[OPT_DATA] = '\0'; |
225 | strncpy(client_config.clientid + OPT_DATA, optarg, len); | 229 | strncpy(client_config.clientid + OPT_DATA, optarg, len); |
226 | break; | 230 | break; |
231 | case 'C': | ||
232 | if (client_config.clientid) show_usage(); | ||
233 | no_clientid = 1; | ||
234 | break; | ||
227 | case 'f': | 235 | case 'f': |
228 | client_config.foreground = 1; | 236 | client_config.foreground = 1; |
229 | break; | 237 | break; |
@@ -273,7 +281,8 @@ int main(int argc, char *argv[]) | |||
273 | NULL, client_config.arp) < 0) | 281 | NULL, client_config.arp) < 0) |
274 | return 1; | 282 | return 1; |
275 | 283 | ||
276 | if (!client_config.clientid) { | 284 | /* if not set, and not suppressed, setup the default client ID */ |
285 | if (!client_config.clientid && !no_clientid) { | ||
277 | client_config.clientid = xmalloc(6 + 3); | 286 | client_config.clientid = xmalloc(6 + 3); |
278 | client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID; | 287 | client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID; |
279 | client_config.clientid[OPT_LEN] = 7; | 288 | client_config.clientid[OPT_LEN] = 7; |
@@ -420,8 +429,10 @@ int main(int argc, char *argv[]) | |||
420 | continue; | 429 | continue; |
421 | } | 430 | } |
422 | /* Ignore packets that aren't for us */ | 431 | /* Ignore packets that aren't for us */ |
423 | if (memcmp(client_config.arp,packet.chaddr,6)) | 432 | if (memcmp(packet.chaddr, client_config.arp, 6)) { |
433 | DEBUG(LOG_INFO, "packet does not have our chaddr -- ignoring"); | ||
424 | continue; | 434 | continue; |
435 | } | ||
425 | 436 | ||
426 | if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { | 437 | if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { |
427 | DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring"); | 438 | DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring"); |