mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-22 15:02:25 +00:00
net: fix mac_from_string
The MAC tokens are given in hex so treat them as such. Fixes #2107.
This commit is contained in:
parent
0cbfef7bf1
commit
3c8d31f8fb
@ -1,3 +1,3 @@
|
|||||||
SRC_CC = ethernet.cc ipv4.cc
|
SRC_CC = ethernet.cc ipv4.cc mac_address.cc
|
||||||
|
|
||||||
vpath %.cc $(REP_DIR)/src/lib/net
|
vpath %.cc $(REP_DIR)/src/lib/net
|
@ -22,29 +22,29 @@ using namespace Genode;
|
|||||||
struct Scanner_policy_number
|
struct Scanner_policy_number
|
||||||
{
|
{
|
||||||
static bool identifier_char(char c, unsigned i ) {
|
static bool identifier_char(char c, unsigned i ) {
|
||||||
return is_digit(c) && c !=':'; }
|
return is_digit(c, true) && c !=':'; }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Token<Scanner_policy_number> Token;
|
typedef Token<Scanner_policy_number> Mac_token;
|
||||||
|
|
||||||
|
|
||||||
Mac_address Net::mac_from_string(const char * mac)
|
Mac_address Net::mac_from_string(const char * mac)
|
||||||
{
|
{
|
||||||
Mac_address mac_addr;
|
Mac_address mac_addr;
|
||||||
Token t(mac);
|
Mac_token t(mac);
|
||||||
char tmpstr[3];
|
char tmpstr[3];
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
unsigned char ipb[6] = {0};
|
unsigned char ipb[6] = {0};
|
||||||
|
|
||||||
while(t) {
|
while (t) {
|
||||||
if (t.type() == Token::WHITESPACE || t[0] == ':') {
|
if (t.type() == Mac_token::WHITESPACE || t[0] == ':') {
|
||||||
t = t.next();
|
t = t.next();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
t.string(tmpstr, sizeof(tmpstr));
|
t.string(tmpstr, sizeof(tmpstr));
|
||||||
|
|
||||||
unsigned long tmpc = 0;
|
unsigned long tmpc = 0;
|
||||||
ascii_to(tmpstr, tmpc);
|
ascii_to_unsigned(tmpstr, tmpc, 16);
|
||||||
ipb[cnt] = tmpc & 0xFF;
|
ipb[cnt] = tmpc & 0xFF;
|
||||||
t = t.next();
|
t = t.next();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user