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 BMessage& resolverConfiguration); 44 void _PrepareMessage(dhcp_message& message, 45 dhcp_state state); 46 status_t _SendMessage(int socket, dhcp_message& message, 47 sockaddr_in& address) const; 48 dhcp_state _CurrentState() const; 49 void _ResetTimeout(int socket, time_t& timeout, 50 uint32& tries); 51 bool _TimeoutShift(int socket, time_t& timeout, 52 uint32& tries); 53 void _RestartLease(bigtime_t lease); 54 BString _ToString(const uint8* data) const; 55 BString _ToString(in_addr_t address) const; 56 57 private: 58 BMessage fConfiguration; 59 BMessage fResolverConfiguration; 60 BMessageRunner* fRunner; 61 uint8 fMAC[6]; 62 uint32 fTransactionID; 63 in_addr_t fAssignedAddress; 64 sockaddr_in fServer; 65 bigtime_t fStartTime; 66 bigtime_t fRenewalTime; 67 bigtime_t fRebindingTime; 68 bigtime_t fLeaseTime; 69 status_t fStatus; 70 }; 71 72 #endif // DHCP_CLIENT_H 73