1 /* 2 * Copyright 2006-2010, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 #ifndef DHCP_CLIENT_H 9 #define DHCP_CLIENT_H 10 11 12 #include "AutoconfigClient.h" 13 14 #include <netinet/in.h> 15 16 class BMessageRunner; 17 class dhcp_message; 18 19 enum dhcp_state { 20 INIT, 21 REQUESTING, 22 BOUND, 23 RENEWAL, 24 REBINDING, 25 ACKNOWLEDGED, 26 }; 27 28 29 class DHCPClient : public AutoconfigClient { 30 public: 31 DHCPClient(BMessenger target, 32 const char* device); 33 virtual ~DHCPClient(); 34 35 virtual status_t Initialize(); 36 37 virtual void MessageReceived(BMessage* message); 38 39 private: 40 status_t _Negotiate(dhcp_state state); 41 void _ParseOptions(dhcp_message& message, 42 BMessage& address); 43 void _PrepareMessage(dhcp_message& message, 44 dhcp_state state); 45 status_t _SendMessage(int socket, dhcp_message& message, 46 sockaddr_in& address) const; 47 dhcp_state _CurrentState() const; 48 void _ResetTimeout(int socket, time_t& timeout, 49 uint32& tries); 50 bool _TimeoutShift(int socket, time_t& timeout, 51 uint32& tries); 52 void _RestartLease(bigtime_t lease); 53 BString _ToString(const uint8* data) const; 54 BString _ToString(in_addr_t address) const; 55 56 private: 57 BMessage fConfiguration; 58 BMessageRunner* fRunner; 59 uint8 fMAC[6]; 60 uint32 fTransactionID; 61 in_addr_t fAssignedAddress; 62 sockaddr_in fServer; 63 bigtime_t fStartTime; 64 bigtime_t fRenewalTime; 65 bigtime_t fRebindingTime; 66 bigtime_t fLeaseTime; 67 status_t fStatus; 68 }; 69 70 #endif // DHCP_CLIENT_H 71