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