blob: c23db478f5b8507e84246cc7666610beba54675e [file] [log] [blame]
Ningyuan Wang48f82042016-01-04 11:28:09 -08001//
2// Copyright (C) 2015 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#ifndef DHCP_CLIENT_DHCP_MESSAGE_H_
18#define DHCP_CLIENT_DHCP_MESSAGE_H_
19
20#include <string>
21
22#include <base/macros.h>
23
24namespace dhcp_client {
25
26class DHCPMessage {
27 public:
28 static const uint8_t kDHCPMessageTypeDiscover = 1;
29 static const uint8_t kDHCPMessageTypeOffer = 2;
30 static const uint8_t kDHCPMessageTypeRequest = 3;
31 static const uint8_t kDHCPMessageTypeDecline = 4;
32 static const uint8_t kDHCPMessageTypeAck = 5;
33 static const uint8_t kDHCPMessageTypeNak = 6;
34 static const uint8_t kDHCPMessageTypeRelease = 7;
35 static const uint8_t kDHCPMessageTypeInform = 8;
36
37 DHCPMessage();
38 ~DHCPMessage();
39 static bool InitFromBuffer(const unsigned char* buffer,
40 size_t length,
41 DHCPMessage* message);
42 uint32_t GetTransactionID();
43 std::string GetClientHardwareAddress();
44
45 private:
46 bool ParseDHCPOptions(const unsigned char* options,
47 size_t options_length);
48 bool IsValid();
49
50 // Message type.
51 uint8_t opcode_;
52 // Hardware address type.
53 uint8_t hardware_address_type_;
54 // Hardware address length.
55 uint8_t hardware_address_length_;
56 // Client sets to zero, optionally used by relay agents
57 // when booting via a relay agent.
58 uint8_t relay_hops_;
59 // Transaction id.
60 uint32_t transaction_id_;
61 // Elapsed time from boot in seconds.
62 uint16_t seconds_;
63 // Broadcast flag
64 uint16_t flags_;
65 // Previously allocated client IP.
66 uint32_t client_ip_address_;
67 // Client IP address.
68 uint32_t your_ip_address_;
69 // IP address of next server to use in bootstrap;
70 // returned in DHCPOFFER, DHCPACK by server.
71 // It should be zero in client's messages.
72 uint32_t next_server_ip_address_;
73 // Relay agent IP address, used in booting via a relay agent.
74 // It should be zero in client's messages.
75 uint32_t agent_ip_address_;
76 // Client's hardware address.
77 std::string client_hardware_address_;
78 // Server host name.
79 std::string servername_;
80 // Boot file name.
81 std::string bootfile_;
82 uint32_t cookie_;
83
84 DISALLOW_COPY_AND_ASSIGN(DHCPMessage);
85};
86
87} // namespace dhcp_client
88
89#endif // DHCP_CLIENT_DHCP_MESSAGE_H_