blob: 367f991743b4cfe332e4fc7f302e88c6be88eebb [file] [log] [blame]
Brian Silverman431500a2013-10-28 19:50:15 -07001#include "aos/common/network/team_number.h"
2
3#include <netinet/in.h>
Brian Silverman8f8b06f2013-10-30 22:04:27 -07004#include <inttypes.h>
Brian Silverman431500a2013-10-28 19:50:15 -07005
6#include "aos/common/once.h"
7#include "aos/atom_code/configuration.h"
Brian Silverman8f8b06f2013-10-30 22:04:27 -07008#include "aos/common/logging/logging.h"
Brian Silverman431500a2013-10-28 19:50:15 -07009
10namespace aos {
11namespace network {
12namespace {
13
14uint16_t *DoGetTeamNumber() {
15 const in_addr &address = configuration::GetOwnIPAddress();
Brian Silverman8f8b06f2013-10-30 22:04:27 -070016 static uint16_t r =
17 (((address.s_addr & 0xFF00) >> 8) * 100) +
18 (((address.s_addr & 0xFF0000) >> 16) & 0xFF);
19 LOG(INFO, "team number is %" PRIu16 "\n", r);
Brian Silverman431500a2013-10-28 19:50:15 -070020 return &r;
21}
22
23} // namespace
24
25uint16_t GetTeamNumber() {
26 static Once<uint16_t> once(DoGetTeamNumber);
27 return *once.Get();
28}
29
30} // namespace network
31} // namespace aos