diff options
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 2ba42d295..dda678933 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -18,7 +18,7 @@ | |||
18 | * along with this program; if not, write to the Free Software | 18 | * along with this program; if not, write to the Free Software |
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <sys/time.h> | 22 | #include <sys/time.h> |
23 | #include <sys/file.h> | 23 | #include <sys/file.h> |
24 | #include <unistd.h> | 24 | #include <unistd.h> |
@@ -152,7 +152,7 @@ static void perform_release(void) | |||
152 | temp_addr.s_addr = server_addr; | 152 | temp_addr.s_addr = server_addr; |
153 | sprintf(buffer, "%s", inet_ntoa(temp_addr)); | 153 | sprintf(buffer, "%s", inet_ntoa(temp_addr)); |
154 | temp_addr.s_addr = requested_ip; | 154 | temp_addr.s_addr = requested_ip; |
155 | LOG(LOG_INFO, "Unicasting a release of %s to %s", | 155 | LOG(LOG_INFO, "Unicasting a release of %s to %s", |
156 | inet_ntoa(temp_addr), buffer); | 156 | inet_ntoa(temp_addr), buffer); |
157 | send_release(server_addr, requested_ip); /* unicast */ | 157 | send_release(server_addr, requested_ip); /* unicast */ |
158 | run_script(NULL, "deconfig"); | 158 | run_script(NULL, "deconfig"); |
@@ -213,7 +213,7 @@ int main(int argc, char *argv[]) | |||
213 | int option_index = 0; | 213 | int option_index = 0; |
214 | c = getopt_long(argc, argv, "c:fbH:h:i:np:qr:s:v", arg_options, &option_index); | 214 | c = getopt_long(argc, argv, "c:fbH:h:i:np:qr:s:v", arg_options, &option_index); |
215 | if (c == -1) break; | 215 | if (c == -1) break; |
216 | 216 | ||
217 | switch (c) { | 217 | switch (c) { |
218 | case 'c': | 218 | case 'c': |
219 | len = strlen(optarg) > 255 ? 255 : strlen(optarg); | 219 | len = strlen(optarg) > 255 ? 255 : strlen(optarg); |
@@ -269,10 +269,10 @@ int main(int argc, char *argv[]) | |||
269 | /* Start the log, sanitize fd's, and write a pid file */ | 269 | /* Start the log, sanitize fd's, and write a pid file */ |
270 | start_log_and_pid("udhcpc", client_config.pidfile); | 270 | start_log_and_pid("udhcpc", client_config.pidfile); |
271 | 271 | ||
272 | if (read_interface(client_config.interface, &client_config.ifindex, | 272 | if (read_interface(client_config.interface, &client_config.ifindex, |
273 | NULL, client_config.arp) < 0) | 273 | NULL, client_config.arp) < 0) |
274 | return 1; | 274 | return 1; |
275 | 275 | ||
276 | if (!client_config.clientid) { | 276 | if (!client_config.clientid) { |
277 | client_config.clientid = xmalloc(6 + 3); | 277 | client_config.clientid = xmalloc(6 + 3); |
278 | client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID; | 278 | client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID; |
@@ -282,8 +282,8 @@ int main(int argc, char *argv[]) | |||
282 | } | 282 | } |
283 | 283 | ||
284 | /* setup the signal pipe */ | 284 | /* setup the signal pipe */ |
285 | udhcp_sp_setup(); | 285 | udhcp_sp_setup(); |
286 | 286 | ||
287 | state = INIT_SELECTING; | 287 | state = INIT_SELECTING; |
288 | run_script(NULL, "deconfig"); | 288 | run_script(NULL, "deconfig"); |
289 | change_mode(LISTEN_RAW); | 289 | change_mode(LISTEN_RAW); |
@@ -321,7 +321,7 @@ int main(int argc, char *argv[]) | |||
321 | 321 | ||
322 | /* send discover packet */ | 322 | /* send discover packet */ |
323 | send_discover(xid, requested_ip); /* broadcast */ | 323 | send_discover(xid, requested_ip); /* broadcast */ |
324 | 324 | ||
325 | timeout = now + ((packet_num == 2) ? 4 : 2); | 325 | timeout = now + ((packet_num == 2) ? 4 : 2); |
326 | packet_num++; | 326 | packet_num++; |
327 | } else { | 327 | } else { |
@@ -345,7 +345,7 @@ int main(int argc, char *argv[]) | |||
345 | if (state == RENEW_REQUESTED) | 345 | if (state == RENEW_REQUESTED) |
346 | send_renew(xid, server_addr, requested_ip); /* unicast */ | 346 | send_renew(xid, server_addr, requested_ip); /* unicast */ |
347 | else send_selecting(xid, server_addr, requested_ip); /* broadcast */ | 347 | else send_selecting(xid, server_addr, requested_ip); /* broadcast */ |
348 | 348 | ||
349 | timeout = now + ((packet_num == 2) ? 10 : 2); | 349 | timeout = now + ((packet_num == 2) ? 10 : 2); |
350 | packet_num++; | 350 | packet_num++; |
351 | } else { | 351 | } else { |
@@ -373,7 +373,7 @@ int main(int argc, char *argv[]) | |||
373 | } else { | 373 | } else { |
374 | /* send a request packet */ | 374 | /* send a request packet */ |
375 | send_renew(xid, server_addr, requested_ip); /* unicast */ | 375 | send_renew(xid, server_addr, requested_ip); /* unicast */ |
376 | 376 | ||
377 | t1 = (t2 - t1) / 2 + t1; | 377 | t1 = (t2 - t1) / 2 + t1; |
378 | timeout = t1 + start; | 378 | timeout = t1 + start; |
379 | } | 379 | } |
@@ -403,28 +403,28 @@ int main(int argc, char *argv[]) | |||
403 | } | 403 | } |
404 | } else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(fd, &rfds)) { | 404 | } else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(fd, &rfds)) { |
405 | /* a packet is ready, read it */ | 405 | /* a packet is ready, read it */ |
406 | 406 | ||
407 | if (listen_mode == LISTEN_KERNEL) | 407 | if (listen_mode == LISTEN_KERNEL) |
408 | len = get_packet(&packet, fd); | 408 | len = get_packet(&packet, fd); |
409 | else len = get_raw_packet(&packet, fd); | 409 | else len = get_raw_packet(&packet, fd); |
410 | 410 | ||
411 | if (len == -1 && errno != EINTR) { | 411 | if (len == -1 && errno != EINTR) { |
412 | DEBUG(LOG_INFO, "error on read, %m, reopening socket"); | 412 | DEBUG(LOG_INFO, "error on read, %m, reopening socket"); |
413 | change_mode(listen_mode); /* just close and reopen */ | 413 | change_mode(listen_mode); /* just close and reopen */ |
414 | } | 414 | } |
415 | if (len < 0) continue; | 415 | if (len < 0) continue; |
416 | 416 | ||
417 | if (packet.xid != xid) { | 417 | if (packet.xid != xid) { |
418 | DEBUG(LOG_INFO, "Ignoring XID %lx (our xid is %lx)", | 418 | DEBUG(LOG_INFO, "Ignoring XID %lx (our xid is %lx)", |
419 | (unsigned long) packet.xid, xid); | 419 | (unsigned long) packet.xid, xid); |
420 | continue; | 420 | continue; |
421 | } | 421 | } |
422 | 422 | ||
423 | if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { | 423 | if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { |
424 | DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring"); | 424 | DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring"); |
425 | continue; | 425 | continue; |
426 | } | 426 | } |
427 | 427 | ||
428 | switch (state) { | 428 | switch (state) { |
429 | case INIT_SELECTING: | 429 | case INIT_SELECTING: |
430 | /* Must be a DHCPOFFER to one of our xid's */ | 430 | /* Must be a DHCPOFFER to one of our xid's */ |
@@ -433,7 +433,7 @@ int main(int argc, char *argv[]) | |||
433 | memcpy(&server_addr, temp, 4); | 433 | memcpy(&server_addr, temp, 4); |
434 | xid = packet.xid; | 434 | xid = packet.xid; |
435 | requested_ip = packet.yiaddr; | 435 | requested_ip = packet.yiaddr; |
436 | 436 | ||
437 | /* enter requesting state */ | 437 | /* enter requesting state */ |
438 | state = REQUESTING; | 438 | state = REQUESTING; |
439 | timeout = now; | 439 | timeout = now; |
@@ -455,14 +455,14 @@ int main(int argc, char *argv[]) | |||
455 | memcpy(&lease, temp, 4); | 455 | memcpy(&lease, temp, 4); |
456 | lease = ntohl(lease); | 456 | lease = ntohl(lease); |
457 | } | 457 | } |
458 | 458 | ||
459 | /* enter bound state */ | 459 | /* enter bound state */ |
460 | t1 = lease / 2; | 460 | t1 = lease / 2; |
461 | 461 | ||
462 | /* little fixed point for n * .875 */ | 462 | /* little fixed point for n * .875 */ |
463 | t2 = (lease * 0x7) >> 3; | 463 | t2 = (lease * 0x7) >> 3; |
464 | temp_addr.s_addr = packet.yiaddr; | 464 | temp_addr.s_addr = packet.yiaddr; |
465 | LOG(LOG_INFO, "Lease of %s obtained, lease time %ld", | 465 | LOG(LOG_INFO, "Lease of %s obtained, lease time %ld", |
466 | inet_ntoa(temp_addr), lease); | 466 | inet_ntoa(temp_addr), lease); |
467 | start = now; | 467 | start = now; |
468 | timeout = t1 + start; | 468 | timeout = t1 + start; |
@@ -472,7 +472,7 @@ int main(int argc, char *argv[]) | |||
472 | 472 | ||
473 | state = BOUND; | 473 | state = BOUND; |
474 | change_mode(LISTEN_NONE); | 474 | change_mode(LISTEN_NONE); |
475 | if (client_config.quit_after_lease) | 475 | if (client_config.quit_after_lease) |
476 | return 0; | 476 | return 0; |
477 | if (!client_config.foreground) | 477 | if (!client_config.foreground) |
478 | client_background(); | 478 | client_background(); |
@@ -492,10 +492,10 @@ int main(int argc, char *argv[]) | |||
492 | } | 492 | } |
493 | break; | 493 | break; |
494 | /* case BOUND, RELEASED: - ignore all packets */ | 494 | /* case BOUND, RELEASED: - ignore all packets */ |
495 | } | 495 | } |
496 | } else if (retval > 0 && (sig = udhcp_sp_read(&rfds))) { | 496 | } else if (retval > 0 && (sig = udhcp_sp_read(&rfds))) { |
497 | switch (sig) { | 497 | switch (sig) { |
498 | case SIGUSR1: | 498 | case SIGUSR1: |
499 | perform_renew(); | 499 | perform_renew(); |
500 | break; | 500 | break; |
501 | case SIGUSR2: | 501 | case SIGUSR2: |
@@ -506,12 +506,12 @@ int main(int argc, char *argv[]) | |||
506 | return 0; | 506 | return 0; |
507 | } | 507 | } |
508 | } else if (retval == -1 && errno == EINTR) { | 508 | } else if (retval == -1 && errno == EINTR) { |
509 | /* a signal was caught */ | 509 | /* a signal was caught */ |
510 | } else { | 510 | } else { |
511 | /* An error occured */ | 511 | /* An error occured */ |
512 | DEBUG(LOG_ERR, "Error on select"); | 512 | DEBUG(LOG_ERR, "Error on select"); |
513 | } | 513 | } |
514 | 514 | ||
515 | } | 515 | } |
516 | return 0; | 516 | return 0; |
517 | } | 517 | } |