Ticket #2531: dhcp.1.diff
File dhcp.1.diff, 4.3 KB (added by , 16 years ago) |
---|
-
src/servers/net/DHCPClient.cpp
21 21 #include <sys/time.h> 22 22 23 23 24 #define LND do { ktrace_printf("DHCP: %s: %s: %d\n", __FILE__, __func__, __LINE__); } while(0) 25 24 26 // See RFC 2131 for DHCP, see RFC 1533 for BOOTP/DHCP options 25 27 26 28 #define DHCP_CLIENT_PORT 68 … … 336 338 fRunner(NULL), 337 339 fLeaseTime(0) 338 340 { 341 LND; 339 342 fStartTime = system_time(); 340 343 fTransactionID = (uint32)fStartTime; 341 344 342 345 fStatus = get_mac_address(device, fMAC); 343 if (fStatus < B_OK) 346 if (fStatus < B_OK) { 347 LND; 344 348 return; 349 } 345 350 346 351 memset(&fServer, 0, sizeof(struct sockaddr_in)); 347 352 fServer.sin_family = AF_INET; 348 353 fServer.sin_len = sizeof(struct sockaddr_in); 349 354 fServer.sin_port = htons(DHCP_SERVER_PORT); 355 LND; 350 356 } 351 357 352 358 353 359 DHCPClient::~DHCPClient() 354 360 { 361 LND; 355 362 if (fStatus != B_OK) 356 363 return; 357 364 … … 374 381 status_t 375 382 DHCPClient::Initialize() 376 383 { 384 LND; 377 385 fStatus = _Negotiate(INIT); 378 386 printf("DHCP for %s, status: %s\n", fDevice.String(), strerror(fStatus)); 379 387 return fStatus; … … 383 391 status_t 384 392 DHCPClient::_Negotiate(dhcp_state state) 385 393 { 394 LND; 386 395 int socket = ::socket(AF_INET, SOCK_DGRAM, 0); 387 396 if (socket < 0) 388 397 return errno; … … 453 462 454 463 // receive loop until we've got an offer and acknowledged it 455 464 465 LND; 466 456 467 while (state != ACKNOWLEDGED) { 468 LND; 457 469 char buffer[2048]; 458 470 ssize_t bytesReceived = recvfrom(socket, buffer, sizeof(buffer), 459 471 0, NULL, NULL); … … 559 571 break; 560 572 } 561 573 } 574 LND; 562 575 563 576 close(socket); 564 577 … … 582 595 fRenewalTime = (fLeaseTime - now) * 2/3 + now; 583 596 fRebindingTime = (fLeaseTime - now) * 5/6 + now; 584 597 } 598 LND; 585 599 586 600 return status; 587 601 } … … 819 833 dhcp_state state = _CurrentState(); 820 834 821 835 bigtime_t next; 836 LND; 822 837 if (_Negotiate(state) == B_OK) { 823 838 switch (state) { 824 839 case RENEWAL: -
src/servers/net/NetServer.cpp
37 37 #include <string.h> 38 38 #include <unistd.h> 39 39 40 #define LND do { ktrace_printf("DHCP: %s: %s: %d\n", __FILE__, __func__, __LINE__); } while(0) 40 41 42 41 43 static const char *kSignature = "application/x-vnd.haiku-net_server"; 42 44 43 45 … … 485 487 status_t 486 488 NetServer::_ConfigureInterface(int socket, BMessage& interface, bool fromMessage) 487 489 { 490 LND; 491 488 492 const char *device; 489 493 if (interface.FindString("device", &device) != B_OK) 490 494 return B_BAD_VALUE; … … 675 679 } 676 680 } 677 681 682 LND; 678 683 if (startAutoConfig) { 679 684 // start auto configuration 685 LND; 680 686 AutoconfigLooper* looper = new AutoconfigLooper(this, device); 681 687 looper->Run(); 682 688 … … 725 731 address.AddBool("auto config", true); 726 732 interface.AddMessage("address", &address); 727 733 734 LND; 735 728 736 return _ConfigureInterface(socket, interface); 729 737 } 730 738 … … 746 754 continue; 747 755 748 756 if (S_ISBLK(stat.st_mode) || S_ISCHR(stat.st_mode)) { 757 LND; 749 758 if (suggestedInterface != NULL 750 759 && suggestedInterface->RemoveName("device") == B_OK 751 760 && suggestedInterface->AddString("device", path.Path()) == B_OK … … 782 791 } 783 792 } 784 793 794 LND; 785 795 _ConfigureInterface(socket, interface); 786 796 } 787 797 } … … 817 827 address.AddString("address", "127.0.0.1"); 818 828 interface.AddMessage("address", &address); 819 829 830 LND; 820 831 _ConfigureInterface(socket, interface); 821 832 } 822 833 -
src/servers/net/AutoconfigLooper.cpp
18 18 #include <sys/socket.h> 19 19 #include <sys/sockio.h> 20 20 21 #define LND do { ktrace_printf("DHCP: %s: %s: %d\n", __FILE__, __func__, __LINE__); } while(0) 21 22 23 22 24 static const uint32 kMsgReadyToRun = 'rdyr'; 23 25 24 26 … … 27 29 fTarget(target), 28 30 fDevice(device) 29 31 { 32 LND; 30 33 BMessage ready(kMsgReadyToRun); 31 34 PostMessage(&ready); 32 35 } … … 40 43 void 41 44 AutoconfigLooper::_ReadyToRun() 42 45 { 46 LND; 43 47 ifreq request; 44 48 if (!prepare_request(request, fDevice.String())) 45 49 return; 50 LND; 46 51 47 52 // set IFF_CONFIGURING flag on interface 48 53 … … 58 63 close(socket); 59 64 60 65 // start with DHCP 66 LND; 61 67 62 68 DHCPClient* client = new DHCPClient(fTarget, fDevice.String()); 63 69 AddHandler(client);