mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-27 17:18:53 +00:00
eaac3cc1bd
This patch curates the API documentation to become suitable for the functional specificaton, which is partially generated from the header files.
74 lines
1.4 KiB
C++
74 lines
1.4 KiB
C++
/*
|
|
* \brief Generic network address definitions
|
|
* \author Stefan Kalkowski
|
|
* \date 2010-08-20
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2010-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 _NET__NETADDRESS_H_
|
|
#define _NET__NETADDRESS_H_
|
|
|
|
/* Genode */
|
|
#include <base/stdint.h>
|
|
#include <util/string.h>
|
|
|
|
namespace Net { template <unsigned> class Network_address; }
|
|
|
|
|
|
/**
|
|
* Generic form of a network address.
|
|
*/
|
|
template <unsigned LEN>
|
|
class Net::Network_address
|
|
{
|
|
public:
|
|
|
|
Genode::uint8_t addr[LEN];
|
|
|
|
|
|
/******************
|
|
** Constructors **
|
|
******************/
|
|
|
|
Network_address(Genode::uint8_t value = 0) {
|
|
Genode::memset(&addr, value, LEN); }
|
|
|
|
Network_address(void *src) {
|
|
Genode::memcpy(&addr, src, LEN); }
|
|
|
|
|
|
/*********************
|
|
** Helper methods **
|
|
*********************/
|
|
|
|
void copy(void *dst) { Genode::memcpy(dst, addr, LEN); }
|
|
|
|
|
|
/***************
|
|
** Operators **
|
|
***************/
|
|
|
|
bool operator==(const Network_address &other) const {
|
|
|
|
/*
|
|
* We compare from lowest address segment to highest
|
|
* one, because in a local context, the higher segments
|
|
* of two addresses normally don't distinguish.
|
|
* (e.g. in an IPv4 local subnet)
|
|
*/
|
|
for (int i = LEN-1; i >= 0; --i) {
|
|
if (addr[i] != other.addr[i])
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
};
|
|
|
|
#endif /* _NET__NETADDRESS_H_ */
|