sanguino/cores/arduino/IPAddress.cpp

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

mercurial