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 | |
Brian Silverman | f02c398 | 2014-04-21 22:04:41 -0700 | [diff] [blame^] | 8 | #include "aos/common/byteorder.h" |
| 9 | |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 10 | namespace aos { |
| 11 | namespace util { |
| 12 | |
| 13 | const char *MakeIPAddress(const in_addr &base_address, |
| 14 | ::aos::NetworkAddress last_segment) { |
| 15 | in_addr address = base_address; |
| 16 | SetLastSegment(&address, last_segment); |
| 17 | |
| 18 | #ifdef __VXWORKS__ |
| 19 | char *r = static_cast<char *>(malloc(INET_ADDR_LEN)); |
| 20 | inet_ntoa_b(address, r); |
| 21 | return r; |
| 22 | #else |
| 23 | return strdup(inet_ntoa(address)); |
| 24 | #endif |
| 25 | } |
| 26 | |
| 27 | void SetLastSegment(in_addr *address, ::aos::NetworkAddress last_segment) { |
Brian Silverman | f02c398 | 2014-04-21 22:04:41 -0700 | [diff] [blame^] | 28 | address->s_addr &= ~(hton<uint32_t>(0xFF)); |
| 29 | address->s_addr |= hton<uint32_t>(static_cast<uint8_t>(last_segment)); |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | } // namespace util |
| 33 | } // namespace aos |