0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-08 20:28:43 +00:00
bird/lib/unaligned.h
Ondrej Zajicek (work) c0fc3e6718 The MRT protocol
The new MRT protocol is responsible for periodic RIB table dumps in the
MRT format (RFC 6396). Also the existing code for BGP4MP MRT dumps is
refactored and splitted between BGP to MRT protocols, will be more
integrated into MRT in the future.

Example:

protocol mrt {
	table "*";
	filename "%N_%F_%T.mrt";
	period 60;
}

It is partially based on the old MRT code from Pavel Tvrdik.
2018-09-18 17:50:45 +02:00

78 lines
1.3 KiB
C

/*
* Unaligned Data Accesses -- Generic Version, Network Order
*
* (c) 2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_UNALIGNED_H_
#define _BIRD_UNALIGNED_H_
/*
* We don't do any clever tricks with unaligned accesses since it's
* virtually impossible to figure out what alignment does the CPU want
* (unaligned accesses can be emulated by the OS which makes them work,
* but unusably slow). We use memcpy and hope GCC will optimize it out
* if possible.
*/
#include "lib/string.h"
static inline u16
get_u16(const void *p)
{
u16 x;
memcpy(&x, p, 2);
return ntohs(x);
}
static inline u32
get_u32(const void *p)
{
u32 x;
memcpy(&x, p, 4);
return ntohl(x);
}
static inline u64
get_u64(const void *p)
{
u32 xh, xl;
memcpy(&xh, p, 4);
memcpy(&xl, p+4, 4);
return (((u64) ntohl(xh)) << 32) | ntohl(xl);
}
static inline void
put_u8(void *p, u8 x)
{
memcpy(p, &x, 1);
}
static inline void
put_u16(void *p, u16 x)
{
x = htons(x);
memcpy(p, &x, 2);
}
static inline void
put_u32(void *p, u32 x)
{
x = htonl(x);
memcpy(p, &x, 4);
}
static inline void
put_u64(void *p, u64 x)
{
u32 xh, xl;
xh = htonl(x >> 32);
xl = htonl((u32) x);
memcpy(p, &xh, 4);
memcpy(p+4, &xl, 4);
}
#endif