mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-20 14:13:09 +00:00
eef18e1ecd
Thereby fix bug in the NIC router that previously used uint8_t values for ports in some places. Ref #2193
57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
/*
|
|
* \brief Network port
|
|
* \author Martin Stein
|
|
* \date 2016-08-19
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2016 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 _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; }
|
|
|
|
/**
|
|
* 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));
|
|
|
|
|
|
namespace Genode {
|
|
|
|
/**
|
|
* Read port value from string
|
|
*
|
|
* \return number of consumed characters
|
|
*/
|
|
inline size_t ascii_to(const char *s, Net::Port &result)
|
|
{
|
|
unsigned value = 0;
|
|
size_t const consumed = ascii_to_unsigned(s, value, 0);
|
|
result = Net::Port(value);
|
|
return consumed;
|
|
}
|
|
}
|
|
|
|
#endif /* _NET__PORT_H_ */
|