blob: 1b7ca9309e52e99c5688bc93cbea0345086e5fae [file] [log] [blame]
Brian Silverman66f079a2013-08-26 16:24:30 -07001#include "aos/common/util.h"
2
3#include <stdlib.h>
4#ifndef __VXWORKS__
5#include <string.h>
6#endif
7
8namespace aos {
9namespace util {
10
11const char *MakeIPAddress(const in_addr &base_address,
12 ::aos::NetworkAddress last_segment) {
13 in_addr address = base_address;
14 SetLastSegment(&address, last_segment);
15
16#ifdef __VXWORKS__
17 char *r = static_cast<char *>(malloc(INET_ADDR_LEN));
18 inet_ntoa_b(address, r);
19 return r;
20#else
21 return strdup(inet_ntoa(address));
22#endif
23}
24
25void SetLastSegment(in_addr *address, ::aos::NetworkAddress last_segment) {
26 address->s_addr &= ~0xFF;
27 address->s_addr |= static_cast<uint8_t>(last_segment);
28}
29
30} // namespace util
31} // namespace aos