arduino-emulator
Loading...
Searching...
No Matches
ArduinoCore-API
api
IPAddress.h
1
/*
2
IPAddress.h - Base class that provides IPAddress
3
Copyright (c) 2011 Adrian McEwen. All right reserved.
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
9
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
14
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
*/
19
20
#pragma once
21
22
#include <stdint.h>
23
#include "Printable.h"
24
#include "String.h"
25
26
#define IPADDRESS_V4_BYTES_INDEX 12
27
#define IPADDRESS_V4_DWORD_INDEX 3
28
29
// forward declarations of global name space friend classes
30
class
EthernetClass;
31
class
DhcpClass;
32
class
DNSClient;
33
34
namespace
arduino
{
35
36
// A class to make it easier to handle and pass around IP addresses
37
38
enum
IPType {
39
IPv4,
40
IPv6
41
};
42
43
class
IPAddress
:
public
Printable
{
44
private
:
45
union
{
46
uint8_t
bytes[16];
47
uint32_t
dword[4];
48
} _address;
49
IPType _type;
50
51
// Access the raw byte array containing the address. Because this returns a pointer
52
// to the internal structure rather than a copy of the address this function should only
53
// be used when you know that the usage of the returned uint8_t* will be transient and not
54
// stored.
55
uint8_t
* raw_address() {
return
_type == IPv4 ? &_address.bytes[
IPADDRESS_V4_BYTES_INDEX
] : _address.bytes; }
56
57
public
:
58
// Constructors
59
60
// Default IPv4
61
IPAddress
();
62
IPAddress
(IPType
ip_type
);
63
IPAddress
(
uint8_t
first_octet
,
uint8_t
second_octet
,
uint8_t
third_octet
,
uint8_t
fourth_octet
);
64
IPAddress
(
uint8_t
o1
,
uint8_t
o2
,
uint8_t
o3
,
uint8_t
o4
,
uint8_t
o5
,
uint8_t
o6
,
uint8_t
o7
,
uint8_t
o8
,
uint8_t
o9
,
uint8_t
o10
,
uint8_t
o11
,
uint8_t
o12
,
uint8_t
o13
,
uint8_t
o14
,
uint8_t
o15
,
uint8_t
o16
);
65
// IPv4; see implementation note
66
IPAddress
(
uint32_t
address);
67
// Default IPv4
68
IPAddress
(
const
uint8_t
*address);
69
IPAddress
(IPType
ip_type
,
const
uint8_t
*address);
70
// If IPv4 fails tries IPv6 see fromString function
71
IPAddress
(
const
char
*address);
72
73
bool
fromString(
const
char
*address);
74
bool
fromString(
const
String
&address) {
return
fromString(address.c_str()); }
75
76
// Overloaded cast operator to allow IPAddress objects to be used where a uint32_t is expected
77
// NOTE: IPv4 only; see implementation note
78
operator
uint32_t
()
const
{
return
_type == IPv4 ? _address.dword[
IPADDRESS_V4_DWORD_INDEX
] : 0; };
79
80
bool
operator==(
const
IPAddress
&
addr
)
const
;
81
bool
operator!=(
const
IPAddress
&
addr
)
const
{
return
!(*
this
==
addr
); };
82
83
// NOTE: IPv4 only; we don't know the length of the pointer
84
bool
operator==(
const
uint8_t
*
addr
)
const
;
85
86
// Overloaded index operator to allow getting and setting individual octets of the address
87
uint8_t
operator[](
int
index)
const
;
88
uint8_t
& operator[](
int
index);
89
90
// Overloaded copy operators to allow initialisation of IPAddress objects from other types
91
// NOTE: IPv4 only
92
IPAddress
& operator=(
const
uint8_t
*address);
93
// NOTE: IPv4 only; see implementation note
94
IPAddress
& operator=(
uint32_t
address);
95
// If IPv4 fails tries IPv6 see fromString function
96
IPAddress
& operator=(
const
char
*address);
97
98
virtual
size_t
printTo(
Print
&
p
)
const
;
99
String
toString()
const
;
100
101
IPType type()
const
{
return
_type; }
102
103
friend
class
UDP
;
104
friend
class
Client
;
105
friend
class
Server
;
106
107
friend ::EthernetClass;
108
friend ::DhcpClass;
109
friend ::DNSClient;
110
111
protected
:
112
bool
fromString4(
const
char
*address);
113
bool
fromString6(
const
char
*address);
114
String
toString4()
const
;
115
String
toString6()
const
;
116
};
117
118
extern
const
IPAddress
IN6ADDR_ANY;
119
extern
const
IPAddress
INADDR_NONE;
120
}
121
122
using
arduino::IPAddress
;
arduino::Client
Definition
Client.h:27
arduino::DMABuffer
Definition
DMAPool.h:103
arduino::IPAddress
Definition
IPAddress.h:43
arduino::Print
Definition
Print.h:36
arduino::Printable
Definition
Printable.h:35
arduino::Server
Definition
Server.h:26
arduino::String
Definition
String.h:53
arduino::UDP
Definition
Udp.h:42
arduino
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition
CanMsg.cpp:31
Generated by
1.9.8