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