diff options
Diffstat (limited to 'hicn-light/src/utils')
-rw-r--r-- | hicn-light/src/utils/address.c | 30 | ||||
-rw-r--r-- | hicn-light/src/utils/address.h | 24 | ||||
-rw-r--r-- | hicn-light/src/utils/utils.c | 24 | ||||
-rw-r--r-- | hicn-light/src/utils/utils.h | 12 |
4 files changed, 54 insertions, 36 deletions
diff --git a/hicn-light/src/utils/address.c b/hicn-light/src/utils/address.c index ee1167de0..a59c6a59d 100644 --- a/hicn-light/src/utils/address.c +++ b/hicn-light/src/utils/address.c @@ -119,6 +119,36 @@ Address *addressCreateFromInet6(struct sockaddr_in6 *addr_in6) { return result; } +Address *addressFromInaddr4Port(in_addr_t *addr4, in_port_t *port) { + struct sockaddr_in addr; + memset(&addr, 0, sizeof(addr)); + + // We assume address and port are already written in memory in network byte + // order + addr.sin_family = AF_INET; + addr.sin_port = *port; + addr.sin_addr.s_addr = *addr4; + + Address *result = addressCreateFromInet(&addr); + return result; +} + +Address *addressFromInaddr6Port(struct in6_addr *addr6, in_port_t *port) { + struct sockaddr_in6 addr; + memset(&addr, 0, sizeof(addr)); + addr.sin6_family = AF_INET6; + + // We assume address and port are already written in memory in network byte + // order + addr.sin6_port = *port; + addr.sin6_addr = *addr6; + addr.sin6_scope_id = 0; + // Other 2 fields: scope_id and flowinfo, do not know what to put inside. + + Address *result = addressCreateFromInet6(&addr); + return result; +} + Address *addressCreateFromLink(const uint8_t *linkaddr, size_t length) { parcAssertNotNull(linkaddr, "Parameter must be non-null"); diff --git a/hicn-light/src/utils/address.h b/hicn-light/src/utils/address.h index d8b0efcab..ca3141ede 100644 --- a/hicn-light/src/utils/address.h +++ b/hicn-light/src/utils/address.h @@ -144,6 +144,30 @@ Address *addressCreateFromInet(struct sockaddr_in *addr_in); Address *addressCreateFromInet6(struct sockaddr_in6 *addr_in6); /** + * Convert an internet address family (IPv4) to the address format used by the + * Fwd. + * + * @param [in] addr4 IPV4 address in *Network byte order* + * @param [in] port Port number in *Network byte order* + * + * @return A new instance of `Address` that must eventually be destroyed by + * calling {@link addressDestroy}() + */ +Address *addressFromInaddr4Port(in_addr_t *addr4, in_port_t *port); + +/** + * Convert an internet address family (IPv6) to the address format used by the + * Fwd + * + * @param [in] addr6 IPV4 address in *Network byte order* + * @param [in] port Port number in *Network byte order* + * + * @return A new instance of `Address` that must eventually be destroyed by + * calling {@link addressDestroy}() + */ +Address *addressFromInaddr6Port(struct in6_addr *addr6, in_port_t *port); + +/** * Create a new `Address` instance, initialized from a Link address. * * User must know the link address format (i.e. token ring vs ethernet) and have diff --git a/hicn-light/src/utils/utils.c b/hicn-light/src/utils/utils.c index 3ab837eeb..e40b219fb 100644 --- a/hicn-light/src/utils/utils.c +++ b/hicn-light/src/utils/utils.c @@ -69,30 +69,6 @@ bool utils_ValidateSymbolicName(const char *symbolic) { return success; } -Address *utils_AddressFromInet(in_addr_t *addr4, in_port_t *port) { - struct sockaddr_in addr; - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = *port; - addr.sin_addr.s_addr = *addr4; - - Address *result = addressCreateFromInet(&addr); - return result; -} - -Address *utils_AddressFromInet6(struct in6_addr *addr6, in_port_t *port) { - struct sockaddr_in6 addr; - memset(&addr, 0, sizeof(addr)); - addr.sin6_family = AF_INET6; - addr.sin6_port = *port; - addr.sin6_addr = *addr6; - addr.sin6_scope_id = 0; - // Other 2 fields: scope_id and flowinfo, do not know what to put inside. - - Address *result = addressCreateFromInet6(&addr); - return result; -} - struct iovec *utils_CreateAck(header_control_message *header, void *payload, size_t payloadLen) { struct iovec *response = diff --git a/hicn-light/src/utils/utils.h b/hicn-light/src/utils/utils.h index 1d2616941..2c4efa965 100644 --- a/hicn-light/src/utils/utils.h +++ b/hicn-light/src/utils/utils.h @@ -32,18 +32,6 @@ bool utils_IsNumber(const char *string); bool utils_ValidateSymbolicName(const char *symbolic); /** - * Convert an internet address family (IPv4) to the address format used by the - * Fwd - */ -Address *utils_AddressFromInet(in_addr_t *addr4, in_port_t *port); - -/** - * Convert an internet address family (IPv6) to the address format used by the - * Fwd - */ -Address *utils_AddressFromInet6(struct in6_addr *addr6, in_port_t *port); - -/** *Create an Ack message instance as a response of a control successfully *completed. */ |