mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-28 09:38:53 +00:00
2eb8c5e21a
The combination of Net::Mac_address and Genode::ascii_to(Net::Mac_address) required shaky quirks in several places because GCC is not able to resolve the ascii_to overload if base/xml_node.h was included to early. The current solution moves the several ascii_to overloads "closer" to the Net types by putting them into the Net namespace, where GCC reliably picks them up. Hence, co-locating the ascii_to() utility with the overload type in the same scope/namespace is good practice. This patch removes the now obsolete <nic/xml_node.h> header file.
60 lines
1.2 KiB
C++
60 lines
1.2 KiB
C++
/*
|
|
* \brief Network port
|
|
* \author Martin Stein
|
|
* \date 2016-08-19
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2016-2017 Genode Labs GmbH
|
|
*
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
* under the terms of the GNU Affero General Public License version 3.
|
|
*/
|
|
|
|
#ifndef _NET__PORT_H_
|
|
#define _NET__PORT_H_
|
|
|
|
/* Genode includes */
|
|
#include <base/stdint.h>
|
|
#include <base/output.h>
|
|
#include <util/string.h>
|
|
|
|
namespace Net {
|
|
class Port;
|
|
|
|
static inline Genode::size_t ascii_to(const char *, Net::Port &);
|
|
}
|
|
|
|
/**
|
|
* This class makes it clear what the port integer-value means at an interface
|
|
*/
|
|
struct Net::Port
|
|
{
|
|
Genode::uint16_t value;
|
|
|
|
explicit Port(Genode::uint16_t const value) : value(value) { }
|
|
|
|
bool operator == (Port const &other) const { return value == other.value; }
|
|
|
|
void print(Genode::Output &out) const { Genode::print(out, value); }
|
|
}
|
|
__attribute__((packed));
|
|
|
|
|
|
/**
|
|
* Read port value from string
|
|
*
|
|
* \return number of consumed characters
|
|
*/
|
|
Genode::size_t Net::ascii_to(const char *s, Net::Port &result)
|
|
{
|
|
using namespace Genode;
|
|
|
|
unsigned value = 0;
|
|
size_t const consumed = ascii_to_unsigned(s, value, 0);
|
|
result = Net::Port(value);
|
|
return consumed;
|
|
}
|
|
|
|
#endif /* _NET__PORT_H_ */
|