User | Revision | Line number | New contents of line |
gbeardall |
0:715023d993d6
|
1
|
|
gbeardall |
0:715023d993d6
|
2
|
/*
|
gbeardall |
0:715023d993d6
|
3
|
Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
|
gbeardall |
0:715023d993d6
|
4
|
|
gbeardall |
0:715023d993d6
|
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
gbeardall |
0:715023d993d6
|
6
|
of this software and associated documentation files (the "Software"), to deal
|
gbeardall |
0:715023d993d6
|
7
|
in the Software without restriction, including without limitation the rights
|
gbeardall |
0:715023d993d6
|
8
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
gbeardall |
0:715023d993d6
|
9
|
copies of the Software, and to permit persons to whom the Software is
|
gbeardall |
0:715023d993d6
|
10
|
furnished to do so, subject to the following conditions:
|
gbeardall |
0:715023d993d6
|
11
|
|
gbeardall |
0:715023d993d6
|
12
|
The above copyright notice and this permission notice shall be included in
|
gbeardall |
0:715023d993d6
|
13
|
all copies or substantial portions of the Software.
|
gbeardall |
0:715023d993d6
|
14
|
|
gbeardall |
0:715023d993d6
|
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
gbeardall |
0:715023d993d6
|
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
gbeardall |
0:715023d993d6
|
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
gbeardall |
0:715023d993d6
|
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
gbeardall |
0:715023d993d6
|
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
gbeardall |
0:715023d993d6
|
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
gbeardall |
0:715023d993d6
|
21
|
THE SOFTWARE.
|
gbeardall |
0:715023d993d6
|
22
|
*/
|
gbeardall |
0:715023d993d6
|
23
|
|
gbeardall |
0:715023d993d6
|
24
|
#ifndef IPADDR_H
|
gbeardall |
0:715023d993d6
|
25
|
#define IPADDR_H
|
gbeardall |
0:715023d993d6
|
26
|
|
gbeardall |
0:715023d993d6
|
27
|
#include "netCfg.h"
|
gbeardall |
0:715023d993d6
|
28
|
#if NET_LWIP_STACK
|
gbeardall |
0:715023d993d6
|
29
|
typedef struct ip_addr ip_addr_t;
|
gbeardall |
0:715023d993d6
|
30
|
#endif
|
gbeardall |
0:715023d993d6
|
31
|
|
gbeardall |
0:715023d993d6
|
32
|
#include "stdint.h"
|
gbeardall |
0:715023d993d6
|
33
|
|
gbeardall |
0:715023d993d6
|
34
|
///IP Address container
|
gbeardall |
0:715023d993d6
|
35
|
/**
|
gbeardall |
0:715023d993d6
|
36
|
This class is a container for an IPv4 address.
|
gbeardall |
0:715023d993d6
|
37
|
*/
|
gbeardall |
0:715023d993d6
|
38
|
class IpAddr //Basically a C++ frontend to ip_addr_t
|
gbeardall |
0:715023d993d6
|
39
|
{
|
gbeardall |
0:715023d993d6
|
40
|
public:
|
gbeardall |
0:715023d993d6
|
41
|
#if NET_LWIP_STACK
|
gbeardall |
0:715023d993d6
|
42
|
IpAddr(ip_addr_t* pIp);
|
gbeardall |
0:715023d993d6
|
43
|
#endif
|
gbeardall |
0:715023d993d6
|
44
|
|
gbeardall |
0:715023d993d6
|
45
|
///Initializes IP address with provided values
|
gbeardall |
0:715023d993d6
|
46
|
IpAddr(uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3);
|
gbeardall |
0:715023d993d6
|
47
|
|
gbeardall |
0:715023d993d6
|
48
|
///Initializes IP address with null values
|
gbeardall |
0:715023d993d6
|
49
|
IpAddr();
|
gbeardall |
0:715023d993d6
|
50
|
|
gbeardall |
0:715023d993d6
|
51
|
#if NET_LWIP_STACK
|
gbeardall |
0:715023d993d6
|
52
|
ip_addr_t getStruct() const;
|
gbeardall |
0:715023d993d6
|
53
|
#endif
|
gbeardall |
0:715023d993d6
|
54
|
|
gbeardall |
0:715023d993d6
|
55
|
///Returns IP address byte #
|
gbeardall |
0:715023d993d6
|
56
|
uint8_t operator[](unsigned int i) const;
|
gbeardall |
0:715023d993d6
|
57
|
|
gbeardall |
0:715023d993d6
|
58
|
///Compares too addresses
|
gbeardall |
0:715023d993d6
|
59
|
/**
|
gbeardall |
0:715023d993d6
|
60
|
@return true if the two addresses are equal
|
gbeardall |
0:715023d993d6
|
61
|
*/
|
gbeardall |
0:715023d993d6
|
62
|
bool isEq(const IpAddr& b) const;
|
gbeardall |
0:715023d993d6
|
63
|
|
gbeardall |
0:715023d993d6
|
64
|
///Compares too addresses
|
gbeardall |
0:715023d993d6
|
65
|
/**
|
gbeardall |
0:715023d993d6
|
66
|
@return true if the two addresses are equal
|
gbeardall |
0:715023d993d6
|
67
|
*/
|
gbeardall |
0:715023d993d6
|
68
|
bool operator==(const IpAddr& b) const;
|
gbeardall |
0:715023d993d6
|
69
|
|
gbeardall |
0:715023d993d6
|
70
|
///Compares too addresses
|
gbeardall |
0:715023d993d6
|
71
|
/**
|
gbeardall |
0:715023d993d6
|
72
|
@return true if the two addresses are different
|
gbeardall |
0:715023d993d6
|
73
|
*/
|
gbeardall |
0:715023d993d6
|
74
|
bool operator!=(const IpAddr& b) const;
|
gbeardall |
0:715023d993d6
|
75
|
|
gbeardall |
0:715023d993d6
|
76
|
///Checks whether the address is null
|
gbeardall |
0:715023d993d6
|
77
|
/**
|
gbeardall |
0:715023d993d6
|
78
|
@return true if the address is null
|
gbeardall |
0:715023d993d6
|
79
|
*/
|
gbeardall |
0:715023d993d6
|
80
|
bool isNull() const;
|
gbeardall |
0:715023d993d6
|
81
|
|
gbeardall |
0:715023d993d6
|
82
|
///Checks whether the address is a broadcast address
|
gbeardall |
0:715023d993d6
|
83
|
/**
|
gbeardall |
0:715023d993d6
|
84
|
@return true if the address is a broadcast address
|
gbeardall |
0:715023d993d6
|
85
|
*/
|
gbeardall |
0:715023d993d6
|
86
|
bool isBroadcast() const;
|
gbeardall |
0:715023d993d6
|
87
|
|
gbeardall |
0:715023d993d6
|
88
|
///Checks whether the address is a multicast address
|
gbeardall |
0:715023d993d6
|
89
|
/**
|
gbeardall |
0:715023d993d6
|
90
|
@return true if the address is a multicast address
|
gbeardall |
0:715023d993d6
|
91
|
*/
|
gbeardall |
0:715023d993d6
|
92
|
bool isMulticast() const;
|
gbeardall |
0:715023d993d6
|
93
|
|
gbeardall |
0:715023d993d6
|
94
|
private:
|
gbeardall |
0:715023d993d6
|
95
|
uint8_t m_ip[4];
|
gbeardall |
0:715023d993d6
|
96
|
};
|
gbeardall |
0:715023d993d6
|
97
|
|
gbeardall |
0:715023d993d6
|
98
|
#endif
|