diff options
author | Mauro Sardara <msardara@cisco.com> | 2022-12-02 15:20:18 +0100 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2022-12-02 15:46:48 +0000 |
commit | 4aeff8486824fecd830a1ecf0ef3abc6e58616a7 (patch) | |
tree | 12f5d818dcdfc8e5f9751e1788bd6d987647891d /ctrl/libhicnctrl | |
parent | 481d5124a127aec922acf6e8b8f2c76780142e2f (diff) |
feat: configure hicnlight port in libtransport and libconfig
Change-Id: Ib55747b4589150ce4a88938e28371c6cf5ab979b
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Signed-off-by: Michele Papalini <micpapal@cisco.com>
Diffstat (limited to 'ctrl/libhicnctrl')
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/ctrl/libhicnctrl/src/modules/hicn_light.c b/ctrl/libhicnctrl/src/modules/hicn_light.c index a652602c6..a2577c31b 100644 --- a/ctrl/libhicnctrl/src/modules/hicn_light.c +++ b/ctrl/libhicnctrl/src/modules/hicn_light.c @@ -118,8 +118,13 @@ static const struct in6_addr loopback_addr = IN6ADDR_LOOPBACK_INIT; * \return 0 if parsing succeeded, a negative error value otherwise. */ static int hicnlight_parse_url(const char *url, struct sockaddr *sa) { - /* FIXME URL parsing is currently not implemented */ - _ASSERT(!url); + char ip[100]; + char protocol[100]; + int port = PORT; + if (url) { + int ret = sscanf(url, "%99[^:]://%99[^:]:%99d[^/]", protocol, ip, &port); + if (ret == EOF) return -1; + } #ifdef __linux__ srand(time(NULL) ^ getpid() ^ gettid()); @@ -137,15 +142,25 @@ static int hicnlight_parse_url(const char *url, struct sockaddr *sa) { case AF_INET: { struct sockaddr_in *sai = (struct sockaddr_in *)sa; sai->sin_family = AF_INET; - sai->sin_port = htons(PORT); - sai->sin_addr.s_addr = htonl(INADDR_LOOPBACK); + sai->sin_port = htons(port); + if (url) { + int ret = inet_pton(AF_INET, ip, &(sai->sin_addr.s_addr)); + if (ret != 1) return -1; + } else { + sai->sin_addr.s_addr = htonl(INADDR_LOOPBACK); + } break; } case AF_INET6: { struct sockaddr_in6 *sai6 = (struct sockaddr_in6 *)sa; sai6->sin6_family = AF_INET6; - sai6->sin6_port = htons(PORT); - sai6->sin6_addr = loopback_addr; + sai6->sin6_port = htons(port); + if (url) { + int ret = inet_pton(AF_INET6, ip, &(sai6->sin6_addr)); + if (ret != 1) return -1; + } else { + sai6->sin6_addr = loopback_addr; + } break; } default: |