Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Arduino Core for SAMD21 CPU
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
josc941e
Arduino Core for SAMD21 CPU
Commits
6f2482c4
Commit
6f2482c4
authored
9 years ago
by
Cristian Maglie
Browse files
Options
Downloads
Patches
Plain Diff
Updated IPAddress to the latest version
parent
9656a761
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cores/arduino/IPAddress.cpp
+42
-0
42 additions, 0 deletions
cores/arduino/IPAddress.cpp
cores/arduino/IPAddress.h
+5
-2
5 additions, 2 deletions
cores/arduino/IPAddress.h
with
47 additions
and
2 deletions
cores/arduino/IPAddress.cpp
+
42
−
0
View file @
6f2482c4
...
...
@@ -43,6 +43,48 @@ IPAddress::IPAddress(const uint8_t *address)
memcpy
(
_address
.
bytes
,
address
,
sizeof
(
_address
.
bytes
));
}
bool
IPAddress
::
fromString
(
const
char
*
address
)
{
// TODO: add support for "a", "a.b", "a.b.c" formats
uint16_t
acc
=
0
;
// Accumulator
uint8_t
dots
=
0
;
while
(
*
address
)
{
char
c
=
*
address
++
;
if
(
c
>=
'0'
&&
c
<=
'9'
)
{
acc
=
acc
*
10
+
(
c
-
'0'
);
if
(
acc
>
255
)
{
// Value out of [0..255] range
return
false
;
}
}
else
if
(
c
==
'.'
)
{
if
(
dots
==
3
)
{
// Too much dots (there must be 3 dots)
return
false
;
}
_address
.
bytes
[
dots
++
]
=
acc
;
acc
=
0
;
}
else
{
// Invalid char
return
false
;
}
}
if
(
dots
!=
3
)
{
// Too few dots (there must be 3 dots)
return
false
;
}
_address
.
bytes
[
3
]
=
acc
;
return
true
;
}
IPAddress
&
IPAddress
::
operator
=
(
const
uint8_t
*
address
)
{
memcpy
(
_address
.
bytes
,
address
,
sizeof
(
_address
.
bytes
));
...
...
This diff is collapsed.
Click to expand it.
cores/arduino/IPAddress.h
+
5
−
2
View file @
6f2482c4
...
...
@@ -21,7 +21,8 @@
#define IPAddress_h
#include
<stdint.h>
#include
<Printable.h>
#include
"Printable.h"
#include
"WString.h"
// A class to make it easier to handle and pass around IP addresses
...
...
@@ -45,6 +46,9 @@ public:
IPAddress
(
uint32_t
address
);
IPAddress
(
const
uint8_t
*
address
);
bool
fromString
(
const
char
*
address
);
bool
fromString
(
const
String
&
address
)
{
return
fromString
(
address
.
c_str
());
}
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
// to a four-byte uint8_t array is expected
operator
uint32_t
()
const
{
return
_address
.
dword
;
};
...
...
@@ -71,5 +75,4 @@ public:
const
IPAddress
INADDR_NONE
(
0
,
0
,
0
,
0
);
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment