This file is indexed.

/usr/include/tins/dhcp.h is in libtins-dev 1.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
/*
 * Copyright (c) 2012, Matias Fontanini
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above
 *   copyright notice, this list of conditions and the following disclaimer
 *   in the documentation and/or other materials provided with the
 *   distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#ifndef TINS_DHCP_H
#define TINS_DHCP_H


#include <list>
#include <string>
#include "bootp.h"
#include "pdu_option.h"
#include "cxxstd.h"

namespace Tins {
    /** 
     * \brief Class that represents the DHCP PDU.
     * 
     * The end option is added automatically at the end of the option list.
     */
    class DHCP : public BootP {
    public:
        /**
         * This PDU's flag.
         */
        static const PDU::PDUType pdu_flag = PDU::DHCP;
    
        /** 
         * DHCP flags.
         */
        enum Flags {
            DISCOVER = 1,
            OFFER    = 2,
            REQUEST	 = 3,
            DECLINE  = 4,
            ACK      = 5,
            NAK      = 6,
            RELEASE	 = 7,
            INFORM   = 8
        };
        
        /** 
         * \brief DHCP options enum.
         */
        enum OptionTypes {
            PAD,
            SUBNET_MASK,
            TIME_OFFSET,
            ROUTERS,
            TIME_SERVERS,
            NAME_SERVERS,
            DOMAIN_NAME_SERVERS,
            LOG_SERVERS,
            COOKIE_SERVERS,
            LPR_SERVERS,
            IMPRESS_SERVERS,
            RESOURCE_LOCATION_SERVERS,
            HOST_NAME,
            BOOT_SIZE,
            MERIT_DUMP,
            DOMAIN_NAME,
            SWAP_SERVER,
            ROOT_PATH,
            EXTENSIONS_PATH,
            IP_FORWARDING,
            NON_LOCAL_SOURCE_ROUTING,
            POLICY_FILTER,
            MAX_DGRAM_REASSEMBLY,
            DEFAULT_IP_TTL,
            PATH_MTU_AGING_TIMEOUT,
            PATH_MTU_PLATEAU_TABLE,
            INTERFACE_MTU,
            ALL_SUBNETS_LOCAL,
            BROADCAST_ADDRESS,
            PERFORM_MASK_DISCOVERY,
            MASK_SUPPLIER,
            ROUTER_DISCOVERY,
            ROUTER_SOLICITATION_ADDRESS,
            STATIC_ROUTES,
            TRAILER_ENCAPSULATION,
            ARP_CACHE_TIMEOUT,
            IEEE802_3_ENCAPSULATION,
            DEFAULT_TCP_TTL,
            TCP_KEEPALIVE_INTERVAL,
            TCP_KEEPALIVE_GARBAGE,
            NIS_DOMAIN,
            NIS_SERVERS,
            NTP_SERVERS,
            VENDOR_ENCAPSULATED_OPTIONS,
            NETBIOS_NAME_SERVERS,
            NETBIOS_DD_SERVER,
            NETBIOS_NODE_TYPE,
            NETBIOS_SCOPE,
            FONT_SERVERS,
            X_DISPLAY_MANAGER,
            DHCP_REQUESTED_ADDRESS,
            DHCP_LEASE_TIME,
            DHCP_OPTION_OVERLOAD,
            DHCP_MESSAGE_TYPE,
            DHCP_SERVER_IDENTIFIER,
            DHCP_PARAMETER_REQUEST_LIST,
            DHCP_MESSAGE,
            DHCP_MAX_MESSAGE_SIZE,
            DHCP_RENEWAL_TIME,
            DHCP_REBINDING_TIME,
            VENDOR_CLASS_IDENTIFIER,
            DHCP_CLIENT_IDENTIFIER,
            NWIP_DOMAIN_NAME,
            NWIP_SUBOPTIONS,
            USER_CLASS = 77,
            FQDN = 81,
            DHCP_AGENT_OPTIONS = 82,
            SUBNET_SELECTION = 118,
            AUTHENTICATE = 210,
            END	= 255
        };
        
        /**
         * The DHCP option type.
         */
        typedef PDUOption<uint8_t> option;
        
        /**
         * The type used to store the DHCP options.
         */
        typedef std::list<option> options_type;
        
        /** 
         * \brief Creates an instance of DHCP.
         * 
         * This sets the hwtype and hlen fields to match the ethernet
         * type and length.
         */
        DHCP();
        
        /**
         * \brief Constructs a DHCP object from a buffer.
         * 
         * If there is not enough size for a BootP header, or any of
         * the TLV options contain an invalid size field, then a
         * malformed_packet exception is thrown.
         * 
         * \param buffer The buffer from which this PDU will be constructed.
         * \param total_sz The total size of the buffer.
         * Subclasses might use 0 to provide their own interpretation of this field.
         */
        DHCP(const uint8_t *buffer, uint32_t total_sz);
        
        /** 
         * \brief Adds a new option to this DHCP PDU.
         * \param opt The option to be added.
         */
        void add_option(const option &opt);
        
        #if TINS_IS_CXX11
            /** 
             * \brief Adds a new option to this DHCP PDU.
             * 
             * The option is move-constructed.
             * 
             * \param opt The option to be added.
             */
            void add_option(option &&opt) {
                internal_add_option(opt);
                _options.push_back(std::move(opt));
            }
        #endif 
    
        /**
         * \brief Searchs for an option that matchs the given flag.
         * \param opt_flag The flag to be searched.
         * \return A pointer to the option, or 0 if it was not found.
         */
        const option *search_option(OptionTypes opt) const;
        
        /** 
         * \brief Adds a type option the the option list.
         * \param type The type of this DHCP PDU.
         */
        void type(Flags type);
        
        /** 
         * \brief Adds an end option the the option list.
         * 
         * The END option is not added automatically. You should explicitly
         * add it at the end of the DHCP options for the PDU to be
         * standard-compliant.
         */
        void end();
        
        /** 
         * \brief Adds a server identifier option.
         * \param ip The ip of the server.
         */
        void server_identifier(ipaddress_type ip);
        
        /** 
         * \brief Adds an IP address lease time option.
         * \param time The lease time.
         */
        void lease_time(uint32_t time);
        
        /** 
         * \brief Adds a lease renewal time option.
         * \param time The lease renew time.
         */
        void renewal_time(uint32_t time);
        
        /** 
         * \brief Adds a rebind time option.
         * \param time The lease rebind time.
         */
        void rebind_time(uint32_t time);
        
        /**
         * \brief Adds a subnet mask option.
         * \param mask The subnet mask.
         */
        void subnet_mask(ipaddress_type mask);
        
        /** 
         * \brief Adds a routers option.
         * \param routers A list of ip addresses.
         */
        void routers(const std::list<ipaddress_type> &routers);
        
        /** 
         * \brief Adds a domain name servers option.
         * \param dns A list of ip addresses.
         */
        void domain_name_servers(const std::list<ipaddress_type> &dns);
        
        /** 
         * \brief Adds a broadcast address option.
         * \param addr The broadcast address.
         */
        void broadcast(ipaddress_type addr);
        
        /** 
         * \brief Adds a requested address option.
         * \param addr The requested address.
         */
        void requested_ip(ipaddress_type addr);
        
        /** 
         * \brief Adds a domain name option.
         * \param name The domain name.
         */
        void domain_name(const std::string &name);
        
        // Option getters
        
        /**
         * \brief Searchs for a type option.
         * 
         * If the option is not found, a option_not_found exception
         * is thrown.
         * 
         * \return uint8_t containing the type option.
         */
        uint8_t type() const;
        
        /**
         * \brief Searchs for a server identifier option.
         * 
         * If the option is not found, a option_not_found exception
         * is thrown.
         * 
         * \return ipaddress_type Containing the server identifier.
         */
        ipaddress_type server_identifier() const;
        
        /**
         * \brief Searchs for a lease time option.
         * 
         * If the option is not found, a option_not_found exception
         * is thrown.
         * 
         * \return uint32_t Containing the lease time.
         */
        uint32_t lease_time() const;
                
        /**
         * \brief Searchs for a lease renewal time option.
         * 
         * If the option is not found, a option_not_found exception
         * is thrown.
         * 
         * \return uint32_t Containing the renewal time.
         */
        uint32_t renewal_time() const;
        
        /**
         * \brief Searchs for a rebind time option.
         * 
         * If the option is not found, a option_not_found exception
         * is thrown.
         * 
         * \return uint32_t Containing the rebind time.
         */
        uint32_t rebind_time() const;
        
        /**
         * \brief Searchs for a subnet mask option.
         * 
         * If the option is not found, a option_not_found exception
         * is thrown.
         * 
         * \return ipaddress_type Containing the subnet mask.
         */
        ipaddress_type subnet_mask() const;
        
        /**
         * \brief Searchs for a routers option.
         * 
         * If the option is not found, a option_not_found exception
         * is thrown.
         * 
         * \return std::list<ipaddress_type> Containing the routers 
         * option data.
         */
        std::list<ipaddress_type> routers() const;
        
        /**
         * \brief Searchs for a dns option.
         * 
         * If the option is not found, a option_not_found exception
         * is thrown.
         * 
         * \return std::list<ipaddress_type> Contanining the DNS servers
         * provided.
         */
        std::list<ipaddress_type> domain_name_servers() const; 
        
        /**
         * \brief Searchs for a broadcast option.
         * 
         * If the option is not found, a option_not_found exception
         * is thrown.
         * 
         * \return ipaddress_type Containing the broadcast address.
         */
        ipaddress_type broadcast() const;
        
        /**
         * \brief Searchs for a requested option.
         * 
         * If the option is not found, a option_not_found exception
         * is thrown.
         * 
         * \return ipaddress_type Containing the requested IP address.
         */
        ipaddress_type requested_ip() const;
        
        /**
         * \brief Searchs for a domain name option.
         * 
         * If the option is not found, a option_not_found exception
         * is thrown.
         * 
         * \return std::string Containing the domain name.
         */
        std::string domain_name() const;
        
        /** \brief Getter for the options list.
         * \return The option list.
         */
        const options_type options() const { return _options; }
        
        /**
         * \brief Getter for the PDU's type.
         * \sa PDU::pdu_type
         */
        PDUType pdu_type() const { return PDU::DHCP; }
        
        /** 
         * \brief Getter for the header size.
         * \return Returns the BOOTP header size.
         * \sa PDU::header_size
         */ 
        uint32_t header_size() const;
        
        /**
         * \sa PDU::clone
         */
        DHCP *clone() const {
            return new DHCP(*this);
        }
    private:
        static const uint32_t MAX_DHCP_SIZE;
        
        template<typename T>
        struct type2type {};
      
        void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
        
        template<class T> 
        T generic_search(OptionTypes opt, type2type<T>) const {
            const option *option = search_option(opt);
            if(option && option->data_size() == sizeof(T))
                return *(const T*)option->data_ptr();
            else
                throw option_not_found();
        }
        
        void internal_add_option(const option &opt);
        std::list<ipaddress_type> generic_search(OptionTypes opt, type2type<std::list<ipaddress_type> >) const;
        std::string generic_search(OptionTypes opt, type2type<std::string>) const;
        ipaddress_type generic_search(OptionTypes opt, type2type<ipaddress_type>) const;
        
        serialization_type serialize_list(const std::list<ipaddress_type> &ip_list);
        
        options_type _options;
        uint32_t _size;
    };
}

#endif // TINS_DHCP_H