id.h
Go to the documentation of this file.
1 /* vim: set ts=2 expandtab: */
2 /**
3  * @file id.h
4  * @brief simple interface for managing node id
5  *
6  * @author Josh King (jheretic), jking@chambana.net
7  *
8  * @internal
9  * Created 03/07/2013
10  * Revision $Id: doxygen.commotion.templates,v 0.1 2013/01/01 09:00:00 jheretic Exp $
11  * Compiler gcc/g++
12  * Company The Open Technology Institute
13  * Copyright Copyright (c) 2013, Josh King
14  *
15  * This file is part of Commotion, Copyright (c) 2013, Josh King
16  *
17  * Commotion is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Affero General Public License as
19  * published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * Commotion is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Affero General Public License for more details.
26  *
27  * You should have received a copy of the GNU Affero General Public License
28  * along with Commotion. If not, see <http://www.gnu.org/licenses/>.
29  *
30  * =====================================================================================
31  */
32 #ifndef _ID_H
33 #define _ID_H
34 
35 #include <stdint.h>
36 
37 /**
38  * @struct nodeid_t struct containing node id and last four bytes of MAC address
39  */
40 typedef union {
41  uint32_t id;
42  uint8_t bytes[4];
43 } nodeid_t;
44 
45 /**
46  * @brief sets node id using last four bytes of device's MAC address
47  * @param mac the MAC address of the device
48  * @param mac_size the size of the MAC address
49  */
50 void co_id_set_from_mac(const unsigned char *mac, int mac_size);
51 
52 /**
53  * @brief Converts node id from host byte order to network byte order
54  * @param n the node id (4 bytes)
55  */
56 void co_id_set_from_int(const uint32_t n);
57 
58 /**
59  * @brief Returns nodeid
60  */
61 nodeid_t co_id_get(void);
62 
63 #endif
Definition: id.h:40
void co_id_set_from_mac(const unsigned char *mac, int mac_size)
sets node id using last four bytes of device's MAC address
Definition: id.c:40
void co_id_set_from_int(const uint32_t n)
Converts node id from host byte order to network byte order.
Definition: id.c:53
nodeid_t co_id_get(void)
Returns nodeid.
Definition: id.c:58