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 #include <NetworkAddress.h> 17 18 19 class BMessageRunner; 20 class dhcp_message; 21 22 23 enum dhcp_state { 24 INIT, 25 SELECTING, 26 INIT_REBOOT, 27 REBOOTING, 28 REQUESTING, 29 BOUND, 30 RENEWING, 31 REBINDING, 32 }; 33 34 35 class DHCPClient : public AutoconfigClient { 36 public: 37 DHCPClient(BMessenger target, 38 const char* device); 39 virtual ~DHCPClient(); 40 41 virtual status_t Initialize(); 42 43 virtual void MessageReceived(BMessage* message); 44 45 private: 46 status_t _Negotiate(dhcp_state state); 47 void _ParseOptions(dhcp_message& message, 48 BMessage& address, 49 BMessage& resolverConfiguration); 50 void _PrepareMessage(dhcp_message& message, 51 dhcp_state state); 52 status_t _SendMessage(int socket, dhcp_message& message, 53 const BNetworkAddress& address) const; 54 dhcp_state _CurrentState() const; 55 void _ResetTimeout(int socket, time_t& timeout, 56 uint32& tries); 57 bool _TimeoutShift(int socket, time_t& timeout, 58 uint32& tries); 59 void _RestartLease(bigtime_t lease); 60 61 static BString _AddressToString(const uint8* data); 62 static BString _AddressToString(in_addr_t address); 63 64 private: 65 BMessage fConfiguration; 66 BMessage fResolverConfiguration; 67 BMessageRunner* fRunner; 68 uint8 fMAC[6]; 69 uint32 fTransactionID; 70 in_addr_t fAssignedAddress; 71 BNetworkAddress fServer; 72 bigtime_t fStartTime; 73 bigtime_t fRenewalTime; 74 bigtime_t fRebindingTime; 75 bigtime_t fLeaseTime; 76 status_t fStatus; 77 }; 78 79 #endif // DHCP_CLIENT_H 80