Files
MySensors/drivers/Linux/IPAddress.h
T
Olivier 8bb3cfb2e1 MySensors 2.1.1 release (#752)
* Bump version to 2.2.0-beta (#713)

* OTA: Add incoming FW block check (#718)

* Linux: Add support for SPIDEV (#734)

RPi and Linux refactor.

Add GPIO Sysfs for GPIO operations.

Update configure script.

Fix some cppcheck warnings.

Add serial emulation that prints to stdout.

Fix some file headers.

* Fix getControllerConfig() (#737)

* Rename MyHwATmega328 to MyHwAVR (#738)

* AVR: Restrict fast pin function use (#739)

* Fix signing presentation bug (#740)

* Consolidate open PRs for bugfix release (#741)

* Revert "Bump version to 2.2.0-beta" (#744)

* Merge Master into Dev (#745)

* Fix spi flash error when compiling in Arduino IDE 1.6.6

* Bump minor version

* Fixed "invalid suffix on literal" warning

* Fix addressing bug in _doSign bitfield

* Make sure nodes not supporting signing informs GW

A node that does not support signing, still needs to inform the
gateway about this to make sure the gateway carries a valid signing
requirement table when a node Id that was requiering signing stops
doing this.
This fixes #286.

* Prevent SecureActuator from accepting ACKs as commands

As ACKs are not currently signed, allowing ACKs as commands
is a considerable security hole for this sketch. This is now resolved.

* Backport of bugfix (#259) in repeaters when forwarding signed messages

* Bumped version to 1.5.2

* Corrected doSign variable name (was _doSign)

* Bumped version to 1.5.3

* Add NULL termination to payloads

Messages addressed to "this" node, will have a null char
appended to the payload after message verification is
done, because some "getters" assume the message being a
string.

* MySensors 2.1.1 release
2017-01-18 21:57:07 +01:00

166 lines
4.0 KiB
C++

/*
* IPAddress.h - Base class that provides IPAddress
* Copyright (c) 2011 Adrian McEwen. All right reserved.
*
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* Modified by Marcelo Aquino <marceloaqno@gmail.org> for MySensors use
*/
#ifndef IPAddress_h
#define IPAddress_h
#include <stdint.h>
#include <string>
/**
* @brief A class to make it easier to handle and pass around IP addresses
*/
class IPAddress
{
private:
union {
uint8_t bytes[4]; //!< IPv4 address as an array
uint32_t dword; //!< IPv4 address in 32 bits format
} _address;
/**
* @brief Access the raw byte array containing the address.
*
* Because this returns a pointer to the internal structure rather than a copy of the address
* this function should only be used when you know that the usage of the returned uint8_t* will
* be transient and not stored.
*
* @return pointer to the internal structure.
*/
uint8_t* raw_address()
{
return _address.bytes;
}
public:
/**
* @brief IPAddress constructor.
*/
IPAddress();
/**
* @brief IPAddress constructor.
*
* @param first_octet first octet of the IPv4 address.
* @param second_octet second octet of the IPv4 address.
* @param third_octet third octet of the IPv4 address.
* @param fourth_octet fourth octet of the IPv4 address.
*/
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
/**
* @brief IPAddress constructor.
*
* @param address to be set from a 32 bits integer.
*/
explicit IPAddress(uint32_t address);
/**
* @brief IPAddress constructor.
*
* @param address to be set from a byte array.
*/
explicit IPAddress(const uint8_t *address);
/**
* @brief Set the IP from a array of characters.
*
* @param address to be set.
*/
bool fromString(const char *address);
/**
* @brief Set the IP from a string class type.
*
* @param address to be set.
*/
bool fromString(const std::string &address)
{
return fromString(address.c_str());
}
/**
* @brief Overloaded cast operator
*
* Allow IPAddress objects to be used where a pointer to a four-byte uint8_t array is expected
*/
operator uint32_t() const
{
return _address.dword;
}
/**
* @brief Overloaded cast operator
*
*/
bool operator==(const IPAddress& addr) const
{
return _address.dword == addr._address.dword;
}
/**
* @brief Overloaded cast operator
*
*/
bool operator==(uint32_t addr) const
{
return _address.dword == addr;
}
/**
* @brief Overloaded cast operator
*
*/
bool operator==(const uint8_t* addr) const;
/**
* @brief Overloaded index operator.
*
* Allow getting and setting individual octets of the address.
*
*/
uint8_t operator[](int index) const
{
return _address.bytes[index];
}
/**
* @brief Overloaded index operator
*
*/
uint8_t& operator[](int index)
{
return _address.bytes[index];
}
/**
* @brief Overloaded copy operators.
*
* Allow initialisation of IPAddress objects from byte array.
*/
IPAddress& operator=(const uint8_t *address);
/**
* @brief Overloaded copy operator.
*
* Allow initialisation of IPAddress objects from a 32 bits integer.
*/
IPAddress& operator=(uint32_t address);
/**
* @brief Convert the IP address to a string.
*
* @return A stringified IP address
*/
std::string toString();
friend class Client;
};
#endif