46ff54007d
* Now should adhere to the specs with regard to filling the DHCP_REQUEST messages in BOUND/RENEWAL/REBINDING states. * Now take over the times for renewal/rebinding state from the DHCP server, if any, or falls back to 2/3 and 5/6 of the original lease time. * The lease time was accidently shortened twice (to compute the renewal time, in case that was missing). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19489 a95241bf-73f2-0310-859d-f6bbb57e9c96
68 lines
1.5 KiB
C++
68 lines
1.5 KiB
C++
/*
|
|
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*
|
|
* Authors:
|
|
* Axel Dörfler, axeld@pinc-software.de
|
|
*/
|
|
#ifndef DHCP_CLIENT_H
|
|
#define DHCP_CLIENT_H
|
|
|
|
|
|
#include <Handler.h>
|
|
#include <Messenger.h>
|
|
#include <String.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
class BMessageRunner;
|
|
class dhcp_message;
|
|
|
|
enum dhcp_state {
|
|
INIT,
|
|
REQUESTING,
|
|
BOUND,
|
|
RENEWAL,
|
|
REBINDING,
|
|
ACKNOWLEDGED,
|
|
};
|
|
|
|
|
|
class DHCPClient : public BHandler {
|
|
public:
|
|
DHCPClient(BMessenger target, const char* device);
|
|
virtual ~DHCPClient();
|
|
|
|
status_t Initialize();
|
|
|
|
virtual void MessageReceived(BMessage* message);
|
|
|
|
private:
|
|
status_t _Negotiate(dhcp_state state);
|
|
void _ParseOptions(dhcp_message& message, BMessage& address);
|
|
void _PrepareMessage(dhcp_message& message, dhcp_state state);
|
|
status_t _SendMessage(int socket, dhcp_message& message, sockaddr_in& address) const;
|
|
dhcp_state _CurrentState() const;
|
|
void _ResetTimeout(int socket, time_t& timeout, uint32& tries);
|
|
bool _TimeoutShift(int socket, time_t& timeout, uint32& tries);
|
|
void _RestartLease(bigtime_t lease);
|
|
BString _ToString(const uint8* data) const;
|
|
BString _ToString(in_addr_t address) const;
|
|
|
|
BMessenger fTarget;
|
|
BString fDevice;
|
|
BMessage fConfiguration;
|
|
BMessageRunner* fRunner;
|
|
uint8 fMAC[6];
|
|
uint32 fTransactionID;
|
|
in_addr_t fAssignedAddress;
|
|
sockaddr_in fServer;
|
|
bigtime_t fStartTime;
|
|
bigtime_t fRenewalTime;
|
|
bigtime_t fRebindingTime;
|
|
bigtime_t fLeaseTime;
|
|
status_t fStatus;
|
|
};
|
|
|
|
#endif // DHCP_CLIENT_H
|