Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Switch - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
86
Issues
86
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
White Rabbit Switch - Software
Commits
2e959755
Commit
2e959755
authored
Oct 31, 2012
by
Benoit Rat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rtu: add function to parse MAC address from cmd line
parent
4bb1a1ba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
10 deletions
+36
-10
mac.c
userspace/wrsw_rtud/mac.c
+22
-4
mac.h
userspace/wrsw_rtud/mac.h
+14
-6
No files found.
userspace/wrsw_rtud/mac.c
View file @
2e959755
/*
* White Rabbit
RTU (Routing Table Unit)
* White Rabbit
MAC utils
* Copyright (C) 2010, CERN.
*
* Version: wrsw_rtud v1.0
...
...
@@ -8,7 +8,7 @@
*
* Description: MAC address type related operations.
*
* Fixes:
* Fixes:
Benoit Rat
*
*
* This program is free software; you can redistribute it and/or
...
...
@@ -35,8 +35,26 @@
*/
char
*
mac_to_string
(
uint8_t
mac
[
ETH_ALEN
])
{
char
str
[
40
];
static
char
str
[
40
];
snprintf
(
str
,
40
,
"%02x:%02x:%02x:%02x:%02x:%02x"
,
mac
[
0
],
mac
[
1
],
mac
[
2
],
mac
[
3
],
mac
[
4
],
mac
[
5
]);
return
str
dup
(
str
);
//FIXME: can't be static but this takes memory
return
str
;
}
/**
* \brief Write mac address into a buffer to avoid concurrent access on static variable.
*/
char
*
mac_to_buffer
(
uint8_t
mac
[
ETH_ALEN
],
char
buffer
[
ETH_ALEN_STR
])
{
if
(
mac
&&
buffer
)
snprintf
(
buffer
,
ETH_ALEN_STR
,
"%02x:%02x:%02x:%02x:%02x:%02x"
,
mac
[
0
],
mac
[
1
],
mac
[
2
],
mac
[
3
],
mac
[
4
],
mac
[
5
]);
return
buffer
;
}
/**
* \brief Function to retrieve mac address from text input (argument in terminal)
*/
int
mac_from_str
(
uint8_t
*
tomac
,
const
char
*
fromstr
)
{
if
(
tomac
==
0
||
fromstr
==
0
)
return
-
1
;
return
sscanf
(
fromstr
,
"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"
,
tomac
+
0
,
tomac
+
1
,
tomac
+
2
,
tomac
+
3
,
tomac
+
4
,
tomac
+
5
);
}
userspace/wrsw_rtud/mac.h
View file @
2e959755
...
...
@@ -6,11 +6,12 @@
*
* Authors: Juan Luis Manas (juan.manas@integrasys.es)
*
* Description: MAC address type related operations.
* Description: MAC address type related operations.
*
* Fixes:
* Fixes:
* Alessandro Rubini
*
* Benoit Rat
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
...
...
@@ -34,9 +35,10 @@
#include <string.h>
#define ETH_ALEN 6
#define ETH_ALEN_STR 18
/**
* \brief Check whether two mac addresses are equal.
/**
* \brief Check whether two mac addresses are equal.
* @return 1 if both addresses are equal. 0 otherwise.
*/
static
inline
int
mac_equal
(
uint8_t
a
[
ETH_ALEN
],
uint8_t
b
[
ETH_ALEN
])
...
...
@@ -57,12 +59,18 @@ static inline uint8_t* mac_copy(uint8_t dst[ETH_ALEN], uint8_t src[ETH_ALEN])
* \brief Set MAC address to 00:00:00:00:00:00.
* @return pointer to mac address
*/
static
inline
uint8_t
*
mac_clean
(
uint8_t
mac
[
ETH_ALEN
])
static
inline
uint8_t
*
mac_clean
(
uint8_t
mac
[
ETH_ALEN
])
{
return
memset
(
mac
,
0x00
,
ETH_ALEN
);
}
char
*
mac_to_string
(
uint8_t
mac
[
ETH_ALEN
]);
char
*
mac_to_buffer
(
uint8_t
mac
[
ETH_ALEN
],
char
buffer
[
ETH_ALEN_STR
]);
int
mac_from_str
(
uint8_t
*
tomac
,
const
char
*
fromstr
);
#endif
/* __WHITERABBIT_RTU_MAC_H */
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