sanguino/cores/arduino/IPAddress.cpp

Thu, 07 Jul 2016 12:23:34 +0200

author
mbayer
date
Thu, 07 Jul 2016 12:23:34 +0200
changeset 2
b373b0288715
permissions
-rw-r--r--

added missing sanguino files

2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
2 #include <Arduino.h>
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
3 #include <IPAddress.h>
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
4
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
5 IPAddress::IPAddress()
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
6 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
7 memset(_address, 0, sizeof(_address));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
8 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
9
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
10 IPAddress::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
11 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
12 _address[0] = first_octet;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
13 _address[1] = second_octet;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
14 _address[2] = third_octet;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
15 _address[3] = fourth_octet;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
16 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
17
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
18 IPAddress::IPAddress(uint32_t address)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
19 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
20 memcpy(_address, &address, sizeof(_address));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
21 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
22
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
23 IPAddress::IPAddress(const uint8_t *address)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
24 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
25 memcpy(_address, address, sizeof(_address));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
26 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
27
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
28 IPAddress& IPAddress::operator=(const uint8_t *address)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
29 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
30 memcpy(_address, address, sizeof(_address));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
31 return *this;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
32 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
33
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
34 IPAddress& IPAddress::operator=(uint32_t address)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
35 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
36 memcpy(_address, (const uint8_t *)&address, sizeof(_address));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
37 return *this;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
38 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
39
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
40 bool IPAddress::operator==(const uint8_t* addr)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
41 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
42 return memcmp(addr, _address, sizeof(_address)) == 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
43 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
44
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
45 size_t IPAddress::printTo(Print& p) const
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
46 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
47 size_t n = 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
48 for (int i =0; i < 3; i++)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
49 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
50 n += p.print(_address[i], DEC);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
51 n += p.print('.');
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
52 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
53 n += p.print(_address[3], DEC);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
54 return n;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
55 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
56

mercurial