id.h File Reference

simple interface for managing node id More...

#include <stdint.h>

Go to the source code of this file.

Classes

struct  nodeid_t
 

Functions

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 More...
 
void co_id_set_from_int (const uint32_t n)
 Converts node id from host byte order to network byte order. More...
 
nodeid_t co_id_get (void)
 Returns nodeid.
 

Detailed Description

simple interface for managing node id

Author
Josh King (jheretic), jking.nosp@m.@cha.nosp@m.mbana.nosp@m..net

Function Documentation

void co_id_set_from_int ( const uint32_t  n)

Converts node id from host byte order to network byte order.

Parameters
nthe node id (4 bytes)

Referenced by main().

53  {
54  nodeid.id = htonl(n);
55  return;
56 }
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

Parameters
macthe MAC address of the device
mac_sizethe size of the MAC address
40  {
41  nodeid.id = 0;
42  CHECK(mac_size == 6, "MAC size is not six.");
43  DEBUG("Received MAC Address : %02x:%02x:%02x:%02x:%02x:%02x\n",
44  mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
45  /* Load last four bytes of MAC address into nodeid struct*/
46  for(int i = 0; i < 4; i++) {
47  nodeid.bytes[i] = mac[i + 2];
48  }
49 error:
50  return;
51 }