Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
32
Issues
32
List
Board
Labels
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
ffe1546b
Commit
ffe1546b
authored
Feb 22, 2021
by
Adam Wujek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/util: move format_mac, decode_mac and decode_port from cmd_mac to lib/util
Signed-off-by:
Adam Wujek
<
adam.wujek@creotech.pl
>
parent
3a2fff4c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
28 deletions
+34
-28
util.h
include/util.h
+5
-0
util.c
lib/util.c
+29
-0
cmd_mac.c
shell/cmd_mac.c
+0
-28
No files found.
include/util.h
View file @
ffe1546b
...
...
@@ -57,6 +57,11 @@ const char *fromhex(const char *hex, int *v);
const
char
*
fromhex64
(
const
char
*
hex
,
int64_t
*
v
);
const
char
*
fromdec
(
const
char
*
dec
,
int
*
v
);
char
*
format_mac
(
char
*
s
,
const
unsigned
char
*
mac
);
void
decode_mac
(
const
char
*
str
,
unsigned
char
*
mac
);
void
decode_port
(
const
char
*
str
,
int
*
port
);
static
inline
int
within_range
(
int
x
,
int
minval
,
int
maxval
,
int
wrap
)
{
int
rv
;
...
...
lib/util.c
View file @
ffe1546b
...
...
@@ -211,6 +211,35 @@ const char *fromdec(const char *dec, int *v)
return
dec
;
}
char
*
format_mac
(
char
*
s
,
const
unsigned
char
*
mac
)
{
pp_sprintf
(
s
,
"%02x:%02x:%02x:%02x:%02x:%02x"
,
mac
[
0
],
mac
[
1
],
mac
[
2
],
mac
[
3
],
mac
[
4
],
mac
[
5
]);
return
s
;
}
void
decode_mac
(
const
char
*
str
,
unsigned
char
*
mac
)
{
int
i
,
x
;
/* Don't try to detect bad input; need small code */
for
(
i
=
0
;
i
<
6
;
++
i
)
{
str
=
fromhex
(
str
,
&
x
);
mac
[
i
]
=
x
;
if
(
*
str
==
':'
)
++
str
;
}
}
void
decode_port
(
const
char
*
str
,
int
*
port
)
{
if
(
!
str
)
*
port
=
0
;
else
*
port
=
atoi
(
str
);
}
/*
* This is a minimal atoi, that doesn't call strtol. Since we are only
* calling atoi, it saves XXXX bytes of library code
...
...
shell/cmd_mac.c
View file @
ffe1546b
...
...
@@ -18,34 +18,6 @@
#include "dev/onewire.h"
#include "dev/endpoint.h"
void
decode_mac
(
const
char
*
str
,
unsigned
char
*
mac
)
{
int
i
,
x
;
/* Don't try to detect bad input; need small code */
for
(
i
=
0
;
i
<
6
;
++
i
)
{
str
=
fromhex
(
str
,
&
x
);
mac
[
i
]
=
x
;
if
(
*
str
==
':'
)
++
str
;
}
}
void
decode_port
(
const
char
*
str
,
int
*
port
)
{
if
(
!
str
)
*
port
=
0
;
else
*
port
=
atoi
(
str
);
}
char
*
format_mac
(
char
*
s
,
const
unsigned
char
*
mac
)
{
pp_sprintf
(
s
,
"%02x:%02x:%02x:%02x:%02x:%02x"
,
mac
[
0
],
mac
[
1
],
mac
[
2
],
mac
[
3
],
mac
[
4
],
mac
[
5
]);
return
s
;
}
static
int
cmd_mac
(
const
char
*
args
[])
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment