sanguino/cores/arduino/IPAddress.h

Fri, 17 Nov 2017 10:13:31 +0100

author
mdd
date
Fri, 17 Nov 2017 10:13:31 +0100
changeset 3
770b218a4931
parent 2
b373b0288715
permissions
-rw-r--r--

proper configuration, homing and planner optimization

2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
1 /*
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
2 *
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
3 * MIT License:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
4 * Copyright (c) 2011 Adrian McEwen
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
6 * of this software and associated documentation files (the "Software"), to deal
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
7 * in the Software without restriction, including without limitation the rights
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
9 * copies of the Software, and to permit persons to whom the Software is
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
10 * furnished to do so, subject to the following conditions:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
11 *
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
12 * The above copyright notice and this permission notice shall be included in
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
13 * all copies or substantial portions of the Software.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
14 *
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
21 * THE SOFTWARE.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
22 *
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
23 * adrianm@mcqn.com 1/1/2011
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
24 */
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
25
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
26 #ifndef IPAddress_h
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
27 #define IPAddress_h
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
28
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
29 #include <Printable.h>
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
30
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
31 // A class to make it easier to handle and pass around IP addresses
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
32
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
33 class IPAddress : public Printable {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
34 private:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
35 uint8_t _address[4]; // IPv4 address
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
36 // Access the raw byte array containing the address. Because this returns a pointer
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
37 // to the internal structure rather than a copy of the address this function should only
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
38 // be used when you know that the usage of the returned uint8_t* will be transient and not
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
39 // stored.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
40 uint8_t* raw_address() { return _address; };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
41
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
42 public:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
43 // Constructors
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
44 IPAddress();
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
45 IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
46 IPAddress(uint32_t address);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
47 IPAddress(const uint8_t *address);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
48
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
49 // Overloaded cast operator to allow IPAddress objects to be used where a pointer
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
50 // to a four-byte uint8_t array is expected
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
51 operator uint32_t() { return *((uint32_t*)_address); };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
52 bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
53 bool operator==(const uint8_t* addr);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
54
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
55 // Overloaded index operator to allow getting and setting individual octets of the address
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
56 uint8_t operator[](int index) const { return _address[index]; };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
57 uint8_t& operator[](int index) { return _address[index]; };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
58
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
59 // Overloaded copy operators to allow initialisation of IPAddress objects from other types
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
60 IPAddress& operator=(const uint8_t *address);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
61 IPAddress& operator=(uint32_t address);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
62
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
63 virtual size_t printTo(Print& p) const;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
64
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
65 friend class EthernetClass;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
66 friend class UDP;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
67 friend class Client;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
68 friend class Server;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
69 friend class DhcpClass;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
70 friend class DNSClient;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
71 };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
72
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
73 const IPAddress INADDR_NONE(0,0,0,0);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
74
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
75
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
76 #endif

mercurial