xref: /haiku/src/servers/net/DHCPClient.h (revision 58481f0f6ef1a61ba07283f012cafbc2ed874ead)
1 /*
2  * Copyright 2006-2008, 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, const char* device);
32 		virtual ~DHCPClient();
33 
34 		virtual status_t Initialize();
35 
36 		virtual void MessageReceived(BMessage* message);
37 
38 	private:
39 		status_t _Negotiate(dhcp_state state);
40 		void _ParseOptions(dhcp_message& message, BMessage& address);
41 		void _PrepareMessage(dhcp_message& message, dhcp_state state);
42 		status_t _SendMessage(int socket, dhcp_message& message, sockaddr_in& address) const;
43 		dhcp_state _CurrentState() const;
44 		void _ResetTimeout(int socket, time_t& timeout, uint32& tries);
45 		bool _TimeoutShift(int socket, time_t& timeout, uint32& tries);
46 		void _RestartLease(bigtime_t lease);
47 		BString _ToString(const uint8* data) const;
48 		BString _ToString(in_addr_t address) const;
49 
50 		BMessage		fConfiguration;
51 		BMessageRunner*	fRunner;
52 		uint8			fMAC[6];
53 		uint32			fTransactionID;
54 		in_addr_t		fAssignedAddress;
55 		sockaddr_in		fServer;
56 		bigtime_t		fStartTime;
57 		bigtime_t		fRenewalTime;
58 		bigtime_t		fRebindingTime;
59 		bigtime_t		fLeaseTime;
60 		status_t		fStatus;
61 };
62 
63 #endif	// DHCP_CLIENT_H
64