xref: /haiku/src/servers/net/DHCPClient.h (revision 220d04022750f40f8bac8f01fa551211e28d04f2)
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 			status_t			_GotMessage(dhcp_state& state,
48 									dhcp_message* message);
49 			status_t			_StateTransition(int socket, dhcp_state& state);
50 			void				_ParseOptions(dhcp_message& message,
51 									BMessage& address,
52 									BMessage& resolverConfiguration);
53 			void				_PrepareMessage(dhcp_message& message,
54 									dhcp_state state);
55 			status_t			_SendMessage(int socket, dhcp_message& message,
56 									const BNetworkAddress& address) const;
57 			dhcp_state			_CurrentState() const;
58 			void				_ResetTimeout(int socket, dhcp_state& state,
59 									time_t& timeout, uint32& tries);
60 			bool				_TimeoutShift(int socket, dhcp_state& state,
61 									time_t& timeout, uint32& tries);
62 			void				_RestartLease(bigtime_t lease);
63 
64 	static	BString				_AddressToString(const uint8* data);
65 	static 	BString				_AddressToString(in_addr_t address);
66 
67 private:
68 			BMessage			fConfiguration;
69 			BMessage			fResolverConfiguration;
70 			BMessageRunner*		fRunner;
71 			uint8				fMAC[6];
72 			BString				fHostName;
73 			uint32				fTransactionID;
74 			in_addr_t			fAssignedAddress;
75 			BNetworkAddress		fServer;
76 			bigtime_t			fStartTime;
77 			bigtime_t			fRequestTime;
78 			bigtime_t			fRenewalTime;
79 			bigtime_t			fRebindingTime;
80 			bigtime_t			fLeaseTime;
81 			status_t			fStatus;
82 };
83 
84 #endif	// DHCP_CLIENT_H
85