Brian | c1dc7d2 | 2014-04-02 12:21:08 -0700 | [diff] [blame^] | 1 | #include "aos/common/util/inet_addr.h" |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 2 | |
| 3 | #include <stdlib.h> |
| 4 | #ifndef __VXWORKS__ |
| 5 | #include <string.h> |
| 6 | #endif |
| 7 | |
| 8 | namespace aos { |
| 9 | namespace util { |
| 10 | |
| 11 | const 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 | |
| 25 | void SetLastSegment(in_addr *address, ::aos::NetworkAddress last_segment) { |
Brian Silverman | 274e486 | 2013-08-29 12:48:54 -0700 | [diff] [blame] | 26 | address->s_addr &= ~(htonl(0xFF)); |
| 27 | address->s_addr |= htonl(static_cast<uint8_t>(last_segment)); |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | } // namespace util |
| 31 | } // namespace aos |