2011-12-22 15:19:25 +00:00
|
|
|
/*
|
|
|
|
* \brief Generic network address definitions
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2010-08-20
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 20:44:47 +00:00
|
|
|
* Copyright (C) 2010-2013 Genode Labs GmbH
|
2011-12-22 15:19:25 +00:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
namespace Net { template <unsigned> class Network_address; }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
|
|
|
* Generic form of a network address.
|
|
|
|
*/
|
|
|
|
template <unsigned LEN>
|
|
|
|
class Net::Network_address
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Genode::uint8_t addr[LEN];
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/******************
|
|
|
|
** Constructors **
|
|
|
|
******************/
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
Network_address(Genode::uint8_t value = 0) {
|
|
|
|
Genode::memset(&addr, value, LEN); }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
Network_address(void *src) {
|
|
|
|
Genode::memcpy(&addr, src, LEN); }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
|
2015-03-20 16:50:41 +00:00
|
|
|
/*********************
|
|
|
|
** Helper methods **
|
|
|
|
*********************/
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
void copy(void *dst) { Genode::memcpy(dst, addr, LEN); }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/***************
|
|
|
|
** Operators **
|
|
|
|
***************/
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
bool operator==(const Network_address &other) const {
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
2011-12-22 15:19:25 +00:00
|
|
|
}
|
2015-03-04 20:12:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
#endif /* _NET__NETADDRESS_H_ */
|