This file is indexed.

/usr/include/ola/network/IPV4Address.h is in libola-dev 0.9.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
/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * IPV4Address.h
 * Represents a IPv4 Address
 * Copyright (C) 2011 Simon Newton
 */

/**
 * @defgroup network Network
 * @brief Network related code.
 */

/**
 * @addtogroup network
 * @{
 * @file IPV4Address.h
 * @brief Represents an IPv4 Address.
 * @}
 */

#ifndef INCLUDE_OLA_NETWORK_IPV4ADDRESS_H_
#define INCLUDE_OLA_NETWORK_IPV4ADDRESS_H_

#include <stdint.h>
#include <string.h>
#include <sstream>
#include <string>

namespace ola {
namespace network {

/**
 * @addtogroup network
 * @{
 */

/**
 * @brief Represents a IPv4 Address.
 *
 * All methods use network byte order unless otherwise mentioned.
 */
class IPV4Address {
 public:
    /**
     * @brief The length in bytes of an IPv4 address.
     */
    enum { LENGTH = 4 };

    /**
     * @brief Create a new IPv4 Address set to INADDR_ANY (0.0.0.0).
     */
    IPV4Address() {
      m_address = 0;
    }

    /**
     * @brief Create a new IPv4 Address from an uint32.
     * @param address the ip address, in network byte order.
     */
    explicit IPV4Address(uint32_t address) {
      m_address = address;
    }

    /**
     * @brief Copy constructor.
     * @param other the IPV4Address to copy.
     */
    IPV4Address(const IPV4Address &other)
        : m_address(other.m_address) {
    }

    /**
     * @brief Assignment operator.
     * @param other the IPV4Address to assign to this object.
     */
    IPV4Address& operator=(const IPV4Address &other) {
      if (this != &other) {
        m_address = other.m_address;
      }
      return *this;
    }

    /**
     * @brief Equals operator.
     * @param other the IPV4Address to compare.
     * @returns true if both IPV4Addresses are equal.
     */
    bool operator==(const IPV4Address &other) const {
      return m_address == other.m_address;
    }

    /**
     * @brief Not equals operator.
     * @param other the IPV4Address to compare.
     * @returns false if both IPV4Addresses are equal.
     */
    bool operator!=(const IPV4Address &other) const {
      return !(*this == other);
    }

    /**
     * @brief Less than operator for partial ordering.
     * @note This sorts in network-byte order, so the ordering won't match
     * human's expectations.
     */
    bool operator<(const IPV4Address &other) const {
      return m_address < other.m_address;
    }

    /**
     * @brief Greater than operator.
     * @note This sorts in network-byte order, so the ordering won't match
     * human's expectations.
     */
    bool operator>(const IPV4Address &other) const {
      return m_address > other.m_address;
    }

    /**
     * @brief Return the IPV4Address as an int in network-byte order.
     * @returns An uint32 representing the IP address.
     */
    uint32_t AsInt() const { return m_address; }

    /**
     * @brief Checks if this address is the wildcard address (0.0.0.0).
     * @returns true if this address is the wildcard address.
     */
    bool IsWildcard() const;

    /**
     * @brief Copy the IPV4Address to a memory location.
     * @param ptr the memory location to copy the address to. The location
     * should be at least LENGTH bytes.
     * @note The address is copied in network byte order.
     */
    void Get(uint8_t ptr[LENGTH]) {
      memcpy(ptr, reinterpret_cast<uint8_t*>(&m_address), LENGTH);
    }

    /**
     * @brief Convert the IPV4Address to a string.
     * @returns the string representation of this IPV4Address.
     */
    std::string ToString() const;

    /**
     * @brief Write the string representation of this IPV4Address to an
     * ostream.
     * @param out the ostream to write to.
     * @param address to address to write.
     */
    friend std::ostream& operator<<(std::ostream &out,
                                    const IPV4Address &address) {
      return out << address.ToString();
    }

    /**
     * @brief Convert a string to an IPV4Address.
     * @param address the IP address string to convert.
     * @returns a new IPV4Address or NULL if the string was invalid. The caller
     * is responsible for deleting the IPV4Address object.
     */
    static IPV4Address* FromString(const std::string &address);

    /**
     * @brief Convert a string to an IPV4Address.
     * @param address the IP address string to convert.
     * @param[out] target the converted IPV4Address.
     * @returns true if the string was a valid IPv4 address, false otherwise.
     */
    static bool FromString(const std::string &address, IPV4Address *target);

    /**
     * @brief Convert a string to an IPV4Address or abort.
     * @note This should only be used within tests.
     * @param address the IP address to convert.
     * @return an IPV4Address matching the string.
     */
    static IPV4Address FromStringOrDie(const std::string &address);

    /**
     * @brief Convert a subnet mask to its CIDR format value
     * @param address the subnet mask as an IPV4Address object
     * @param mask the mask variable to populate
     * @return true if we managed to convert the address to a CIDR value, false
         otherwise
     */
    static bool ToCIDRMask(IPV4Address address, uint8_t *mask);

    /**
     * @brief Returns the wildcard address INADDR_ANY (0.0.0.0).
     * @return an IPV4Address representing the wildcard address.
     */
    static IPV4Address WildCard();

    /**
     * @brief Returns the broadcast address INADDR_NONE (255.255.255.255).
     * @return an IPV4Address representing the broadcast address.
     */
    static IPV4Address Broadcast();

    /**
     * @brief Returns the loopback address (127.0.0.1).
     * @return an IPV4Address representing the loopback address.
     */
    static IPV4Address Loopback();

 private:
    uint32_t m_address;
};
/**
 * @}
 */
}  // namespace network
}  // namespace ola
#endif  // INCLUDE_OLA_NETWORK_IPV4ADDRESS_H_