Nyx Node
Loading...
Searching...
No Matches
addr.c
1/* NyxNode
2 * Author: Jérôme ODIER <jerome.odier@lpsc.in2p3.fr>
3 * SPDX-License-Identifier: GPL-2.0-only (Mongoose backend) or GPL-3.0+
4 */
5
6/*--------------------------------------------------------------------------------------------------------------------*/
7
8#include <string.h>
9
10#include "../nyx_node_internal.h"
11
12/*--------------------------------------------------------------------------------------------------------------------*/
13
14void nyx_generate_mac_addr(uint8_t result_mac[6], uint8_t mac0, uint8_t mac1, STR_t node_id)
15{
16 size_t size = node_id != NULL ? strlen(node_id)
17 : 0x0000000000000
18 ;
19
20 uint32_t hash = nyx_hash(size, node_id, 0xAABBCCDD);
21
22 result_mac[0] = mac0;
23 result_mac[1] = mac1;
24 result_mac[2] = (uint8_t) ((hash >> 24) & 0xFF);
25 result_mac[3] = (uint8_t) ((hash >> 16) & 0xFF);
26 result_mac[4] = (uint8_t) ((hash >> 8) & 0xFF);
27 result_mac[5] = (uint8_t) ((hash >> 0) & 0xFF);
28}
29
30/*--------------------------------------------------------------------------------------------------------------------*/
#define STR_t
Alias for const char *.
Definition nyx_node.h:71
uint32_t nyx_hash(__NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff, uint32_t seed)
Hashes a buffer using the MurmurHash2 algorithm.
void nyx_generate_mac_addr(uint8_t result_mac[6], uint8_t mac0, uint8_t mac1, STR_t node_id)
Generates a MAC address based on a node identifier.
Definition addr.c:14