diff options
Diffstat (limited to 'hicn-light/src/hicn/core/address.c')
-rw-r--r-- | hicn-light/src/hicn/core/address.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/hicn-light/src/hicn/core/address.c b/hicn-light/src/hicn/core/address.c index 07aa4a8bd..cde89c888 100644 --- a/hicn-light/src/hicn/core/address.c +++ b/hicn-light/src/hicn/core/address.c @@ -26,10 +26,10 @@ address_from_ip_port(address_t * address, int family, ip_address_t * addr, uint1 memset(address, 0, sizeof(address_t)); switch(family) { case AF_INET: - *address = ADDRESS4(addr->v4.as_inaddr.s_addr, port); + *address = ADDRESS4(ntohl(addr->v4.as_inaddr.s_addr), ntohs(port)); break; case AF_INET6: - *address = ADDRESS6(addr->v6.as_in6addr, port); + *address = ADDRESS6(ntohl(addr->v6.as_in6addr), ntohs(port)); break; default: return -1; @@ -41,3 +41,18 @@ const char * _address_family_str[] = { [AF_INET] = "AF_INET", [AF_INET6] = "AF_INET6", }; + +int address_to_string(const address_t *address, char *buffer) { + struct sockaddr_storage addr = *address; + socklen_t addr_len = sizeof(addr); + int err=getnameinfo((struct sockaddr*) &addr, addr_len, buffer, INET6_ADDRSTRLEN, 0, 0, NI_NUMERICHOST); + + if (err != 0) { + strncpy(buffer, "N/A", INET6_ADDRSTRLEN); + } + return err; +} + +address_t _ADDRESS4_LOCALHOST(uint16_t port) { + return ADDRESS4_LOCALHOST(port); +}
\ No newline at end of file |