This file is indexed.

/usr/include/tins/arp.h is in libtins-dev 3.4-2+b1.

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
/*
 * Copyright (c) 2016, 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_ARP_H
#define TINS_ARP_H

#include "macros.h"
#include "pdu.h"
#include "endianness.h"
#include "hw_address.h"
#include "ip_address.h"

namespace Tins {

class NetworkInterface;
class EthernetII;

/**
 * \class ARP
 * \brief Represents an ARP PDU.
 *
 */
class TINS_API ARP : public PDU {
public:
    /**
     * The type of the hardware address.
     */
    typedef HWAddress<6> hwaddress_type;
    
    /**
     * The type of the IP address.
     */
    typedef IPv4Address ipaddress_type;

    /**
     * \brief This PDU's flag.
     */
    static const PDU::PDUType pdu_flag = PDU::ARP;

    /**
     * \brief Enum which indicates the type of ARP packet.
     */
    enum Flags {
        REQUEST = 0x0001,
        REPLY   = 0x0002
    };

    /**
     * \brief Extracts metadata for this protocol based on the buffer provided
     *
     * \param buffer Pointer to a buffer
     * \param total_sz Size of the buffer pointed by buffer
     */
    static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);

    /**
     * \brief Constructs an ARP object using the provided addresses.
     * 
     * ARP requests and replies can be constructed easily using
     * ARP::make_arp_request/reply static member functions.
     * 
     * \sa ARP::make_arp_request
     * \sa ARP::make_arp_reply
     * 
     * \param target_ip The target IP address.
     * \param sender_ip The sender IP address.
     * \param target_hw The target hardware address.
     * \param sender_hw The sender hardware address.
     */
    ARP(ipaddress_type target_ip = ipaddress_type(), 
        ipaddress_type sender_ip = ipaddress_type(), 
        const hwaddress_type& target_hw = hwaddress_type(), 
        const hwaddress_type& sender_hw = hwaddress_type());

    /**
     * \brief Constructs an ARP object from a buffer.
     * 
     * If there is not enough size for an ARP header in the buffer,
     * a malformed_packet exception is thrown. 
     * 
     * If the buffer is bigger than the size of the ARP header, 
     * then the extra data is stored in a RawPDU.
     * 
     * \param buffer The buffer from which this PDU will be constructed.
     * \param total_sz The total size of the buffer.
     */
    ARP(const uint8_t* buffer, uint32_t total_sz);

    /* Getters */
    /**
     * \brief Getter for the sender's hardware address.
     *
     * \return The sender hardware address.
     */
    hwaddress_type sender_hw_addr() const {
        return header_.sender_hw_address;
    }

    /**
     * \brief Getter for the sender's IP address.
     *
     * \return The sender IP address.
     */
    ipaddress_type sender_ip_addr() const {
        return ipaddress_type(header_.sender_ip_address);
    }

    /**
     * \brief Getter for the target's hardware address.
     *
     * \return The target hardware address.
     */
    hwaddress_type target_hw_addr() const {
        return header_.target_hw_address;
    }

    /**
     * \brief Getter for the target's IP address.
     *
     * \return The target IP address.
     */
    ipaddress_type target_ip_addr() const {
        return ipaddress_type(header_.target_ip_address);
    }

    /**
     * \brief Getter for the hardware address format field.
     *
     * \return The hardware address format.
     */
    uint16_t hw_addr_format() const {
        return Endian::be_to_host(header_.hw_address_format);
    }

    /**
     * \brief Getter for the protocol address format field.
     *
     * \return The protocol address format.
     */
    uint16_t prot_addr_format() const {
        return Endian::be_to_host(header_.proto_address_format);
    }

    /**
     * \brief Getter for the hardware address length field.
     *
     * \return The hardware address length.
     */
    uint8_t hw_addr_length() const {
        return header_.hw_address_length;
    }

    /**
     * \brief Getter for the protocol address length field.
     *
     * \return The protocol address length.
     */
    uint8_t prot_addr_length() const {
        return header_.proto_address_length;
    }

    /**
     * \brief Getter for the ARP opcode field.
     *
     * \return The ARP opcode.
     */
    uint16_t opcode() const {
        return Endian::be_to_host(header_.opcode);
    }

    /** 
     * \brief Getter for the header size.
     * \return Returns the ARP header size.
     * \sa PDU::header_size
     */
    uint32_t header_size() const;

    /* Setters */

    /**
     * \brief Setter for the sender's hardware address.
     *
     * \param address The new sender hardware address.
     */
    void sender_hw_addr(const hwaddress_type& address);

    /**
     * \brief Setter for the sender's IP address.
     *
     * \param address The new sender IP address.
     */
    void sender_ip_addr(ipaddress_type address);

    /**
     * \brief Setter for the target's hardware address.
     *
     * \param address The new target hardware address.
     */
    void target_hw_addr(const hwaddress_type& address);

    /**
     * \brief Setter for the target's IP address.
     *
     * \param address The new target IP address.
     */
    void target_ip_addr(ipaddress_type address);

    /**
     * \brief Setter for the hardware address format field.
     *
     * \param format The new hardware address format.
     */
    void hw_addr_format(uint16_t format);

    /**
     * \brief Setter for the protocol address format field.
     *
     * \param format The new protocol address format.
     */
    void prot_addr_format(uint16_t format);

    /**
     * \brief Setter for the hardware address length field.
     *
     * \param length The new hardware address length.
     */
    void hw_addr_length(uint8_t length);

    /**
     * \brief Setter for the protocol address length field.
     *
     * \param length The new protocol address length.
     */
    void prot_addr_length(uint8_t length);

    /**
     * \brief Setter for the ARP opcode field.
     *
     * \param code Flag enum value of the ARP opcode to set.
     */
    void opcode(Flags code);

    /**
     * \brief Getter for the PDU's type.
     * \sa PDU::pdu_type
     */
    PDUType pdu_type() const { return pdu_flag; }

    /**
     * \brief Creates an ARP Request within an EthernetII PDU.
     *
     * Creates an ARP Request PDU and embeds it inside an EthernetII
     * PDU.
     *
     * \param target The target's IP address.
     * \param sender The sender's IP address.
     * \param hw_snd The sender's hardware address.
     * \return EthernetII object containing the ARP Request.
     */
    static EthernetII make_arp_request(ipaddress_type target, 
                                       ipaddress_type sender, 
                                       const hwaddress_type& hw_snd = hwaddress_type());

    /**
     * \brief Creates an ARP Reply within an EthernetII PDU.
     *
     * Creates an ARP Reply PDU and embeds it inside an EthernetII 
     * PDU.
     *
     * \param target The target's IP address.
     * \param sender The sender's IP address.
     * \param hw_tgt The target's hardware address.
     * \param hw_snd The sender's hardware address.
     * \return EthetnetII containing the ARP Replay.
     */
    static EthernetII make_arp_reply(ipaddress_type target, 
                                     ipaddress_type sender, 
                                     const hwaddress_type& hw_tgt = hwaddress_type(), 
                                     const hwaddress_type& hw_snd = hwaddress_type());

    /** 
     * \brief Check whether ptr points to a valid response for this PDU.
     *
     * \sa PDU::matches_response
     * \param ptr The pointer to the buffer.
     * \param total_sz The size of the buffer.
     */
    bool matches_response(const uint8_t* ptr, uint32_t total_sz) const;
    
    /**
     * \sa PDU::clone
     */
    ARP* clone() const {
        return new ARP(*this);
    }
private:
    TINS_BEGIN_PACK
    struct arp_header {
        uint16_t hw_address_format;
        uint16_t proto_address_format;
        uint8_t	hw_address_length;
        uint8_t	proto_address_length;
        uint16_t opcode;
        uint8_t sender_hw_address[hwaddress_type::address_size];	
        uint32_t sender_ip_address;	
        uint8_t target_hw_address[hwaddress_type::address_size];	
        uint32_t target_ip_address;
    } TINS_END_PACK;

    void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);

    arp_header header_;
};

} // Tins

#endif // TINS_ARP_H