2014-09-24 09:15:20 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
2013-11-27 17:54:30 +01:00
|
|
|
/**
|
|
|
|
* @defgroup net_help Net help
|
|
|
|
* @ingroup net
|
|
|
|
* @brief Helper functions for networking as byte order conversions and checksum calculations
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file net_help.h
|
2013-08-15 10:17:15 +02:00
|
|
|
*
|
2014-09-24 09:15:20 +02:00
|
|
|
* @author Oliver Gesch <oliver.gesch@googlemail.com>
|
2013-08-15 10:17:15 +02:00
|
|
|
*/
|
|
|
|
|
2013-11-27 17:54:30 +01:00
|
|
|
#ifndef __NET_HELP_H
|
|
|
|
#define __NET_HELP_H
|
2013-11-27 16:28:31 +01:00
|
|
|
|
2013-08-15 10:17:15 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2014-05-14 16:06:58 +02:00
|
|
|
#if defined(__MACH__)
|
|
|
|
#include "clang_compat.h"
|
|
|
|
#endif
|
|
|
|
|
2014-09-24 06:03:02 +02:00
|
|
|
#include "byteorder.h"
|
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-08-15 10:17:15 +02:00
|
|
|
#define BITSET(var,pos) ((var) & (1<<(pos)))
|
2014-09-24 06:03:02 +02:00
|
|
|
|
|
|
|
static inline uint16_t HTONS(uint16_t a)
|
|
|
|
{
|
|
|
|
return byteorder_htons(a).u16;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t HTONL(uint32_t a)
|
|
|
|
{
|
|
|
|
return byteorder_htonl(a).u32;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t HTONLL(uint64_t a)
|
|
|
|
{
|
|
|
|
return byteorder_htonll(a).u64;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint16_t NTOHS(uint16_t a)
|
|
|
|
{
|
|
|
|
return byteorder_ntohs(*(network_uint16_t *) &a);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t NTOHL(uint32_t a)
|
|
|
|
{
|
|
|
|
return byteorder_ntohl(*(network_uint32_t *) &a);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t NTOHLL(uint64_t a)
|
|
|
|
{
|
|
|
|
return byteorder_ntohll(*(network_uint64_t *) &a);
|
|
|
|
}
|
2013-08-15 10:17:15 +02:00
|
|
|
|
|
|
|
uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len);
|
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-27 17:54:30 +01:00
|
|
|
/** @} */
|
|
|
|
#endif /* __NET_HELP_H */
|