blob: a83ecf9c0bb825cfc711433a3636472664a072eb [file] [log] [blame]
Brianc1dc7d22014-04-02 12:21:08 -07001#include "aos/common/util/inet_addr.h"
Brian Silverman66f079a2013-08-26 16:24:30 -07002
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) {
Brian Silverman274e4862013-08-29 12:48:54 -070026 address->s_addr &= ~(htonl(0xFF));
27 address->s_addr |= htonl(static_cast<uint8_t>(last_segment));
Brian Silverman66f079a2013-08-26 16:24:30 -070028}
29
30} // namespace util
31} // namespace aos