mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-25 00:11:07 +00:00
ca971bbfd8
This patch changes the top-level directory layout as a preparatory step for improving the tools for managing 3rd-party source codes. The rationale is described in the issue referenced below. Issue #1082
57 lines
1.2 KiB
C++
57 lines
1.2 KiB
C++
/*
|
|
* \brief Xml-node routines used internally in NIC drivers
|
|
* \author Sebastian Sumpf
|
|
* \author Stefan Kalkowski
|
|
* \date 2012-10-22
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2012-2013 Genode Labs GmbH
|
|
*
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
* under the terms of the GNU General Public License version 2.
|
|
*/
|
|
|
|
#ifndef _INCLUDE__NIC__XML_NODE_H_
|
|
#define _INCLUDE__NIC__XML_NODE_H_
|
|
|
|
#include <nic_session/nic_session.h>
|
|
#include <util/string.h>
|
|
|
|
namespace Genode {
|
|
|
|
/**
|
|
* Convert ASCII string to mac address
|
|
*/
|
|
template <>
|
|
inline size_t ascii_to<Nic::Mac_address>(char const *s,
|
|
Nic::Mac_address* mac, unsigned)
|
|
{
|
|
enum {
|
|
HEX = true,
|
|
MAC_CHAR_LEN = 17, /* 12 number and 6 colons */
|
|
MAC_SIZE = 6,
|
|
};
|
|
|
|
if(strlen(s) < MAC_CHAR_LEN)
|
|
throw -1;
|
|
|
|
char mac_str[6];
|
|
for (int i = 0; i < MAC_SIZE; i++) {
|
|
int hi = i * 3;
|
|
int lo = hi + 1;
|
|
|
|
if (!is_digit(s[hi], HEX) || !is_digit(s[lo], HEX))
|
|
throw -1;
|
|
|
|
mac_str[i] = (digit(s[hi], HEX) << 4) | digit(s[lo], HEX);
|
|
}
|
|
|
|
Genode::memcpy(mac->addr, mac_str, MAC_SIZE);
|
|
|
|
return MAC_CHAR_LEN;
|
|
}
|
|
}
|
|
|
|
#endif /* _INCLUDE__NIC__XML_NODE_H_ */
|