xref: /haiku/src/servers/net/DHCPClient.h (revision 2600324b57fa31cdea1627d584d314f2a579c4a8)
1 /*
2  * Copyright 2006, 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 <Handler.h>
13 #include <Messenger.h>
14 #include <String.h>
15 
16 #include <netinet/in.h>
17 
18 class BMessageRunner;
19 class dhcp_message;
20 
21 enum dhcp_state {
22 	INIT,
23 	REQUESTING,
24 	BOUND,
25 	RENEWAL,
26 	REBINDING,
27 	ACKNOWLEDGED,
28 };
29 
30 
31 class DHCPClient : public BHandler {
32 	public:
33 		DHCPClient(BMessenger target, const char* device);
34 		virtual ~DHCPClient();
35 
36 		status_t Initialize();
37 
38 		virtual void MessageReceived(BMessage* message);
39 
40 	private:
41 		status_t _Negotiate(dhcp_state state);
42 		void _ParseOptions(dhcp_message& message, BMessage& address);
43 		void _PrepareMessage(dhcp_message& message, dhcp_state state);
44 		status_t _SendMessage(int socket, dhcp_message& message, sockaddr_in& address) const;
45 		dhcp_state _CurrentState() const;
46 		void _ResetTimeout(int socket, time_t& timeout, uint32& tries);
47 		bool _TimeoutShift(int socket, time_t& timeout, uint32& tries);
48 		void _RestartLease(bigtime_t lease);
49 		BString _ToString(const uint8* data) const;
50 		BString _ToString(in_addr_t address) const;
51 
52 		BMessenger		fTarget;
53 		BString			fDevice;
54 		BMessage		fConfiguration;
55 		BMessageRunner*	fRunner;
56 		uint8			fMAC[6];
57 		uint32			fTransactionID;
58 		in_addr_t		fAssignedAddress;
59 		sockaddr_in		fServer;
60 		bigtime_t		fStartTime;
61 		bigtime_t		fRenewalTime;
62 		bigtime_t		fRebindingTime;
63 		bigtime_t		fLeaseTime;
64 		status_t		fStatus;
65 };
66 
67 #endif	// DHCP_CLIENT_H
68