From 8cd3ef563542c049c8cd1282dadca9a944c156ed Mon Sep 17 00:00:00 2001 From: Vladimir Medvedkin Date: Mon, 9 Mar 2020 12:42:22 +0000 Subject: [PATCH] app/test-fib: get rid of libresolv dependency Get rid of using inet_net_pton(). Implement it internally in the app. Signed-off-by: Vladimir Medvedkin --- app/test-fib/Makefile | 2 -- app/test-fib/main.c | 61 ++++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/app/test-fib/Makefile b/app/test-fib/Makefile index 78b45fe314..9da34eb8fe 100644 --- a/app/test-fib/Makefile +++ b/app/test-fib/Makefile @@ -11,8 +11,6 @@ CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) CFLAGS += -DALLOW_EXPERIMENTAL_API -LDFLAGS += -lresolv - # all source are stored in SRCS-y SRCS-y := main.c diff --git a/app/test-fib/main.c b/app/test-fib/main.c index 7fd342092f..6e80d65f4c 100644 --- a/app/test-fib/main.c +++ b/app/test-fib/main.c @@ -2,14 +2,10 @@ * Copyright(c) 2019 Intel Corporation */ -#include #include #include -#include -#include -#include -#include #include +#include #include #include @@ -443,6 +439,32 @@ gen_rnd_lookup_tbl(int af) } } +static int +_inet_net_pton(int af, char *prefix, void *addr) +{ + const char *dlm = "/"; + char *s, *sp; + int ret, depth; + unsigned int max_depth; + + if ((prefix == NULL) || (addr == NULL)) + return -EINVAL; + + s = strtok_r(prefix, dlm, &sp); + if (s == NULL) + return -EINVAL; + + ret = inet_pton(af, s, addr); + if (ret != 1) + return -errno; + + s = strtok_r(NULL, dlm, &sp); + max_depth = (af == AF_INET) ? 32 : 128; + GET_CB_FIELD(s, depth, 0, max_depth, 0); + + return depth; +} + static int parse_rt_4(FILE *f) { @@ -463,8 +485,7 @@ parse_rt_4(FILE *f) s = NULL; } - ret = inet_net_pton(AF_INET, in[RT_PREFIX], &rt[j].addr, - sizeof(rt[j].addr)); + ret = _inet_net_pton(AF_INET, in[RT_PREFIX], &rt[j].addr); if (ret == -1) return -errno; @@ -478,30 +499,6 @@ parse_rt_4(FILE *f) return 0; } -static int -__inet_net_pton6(char *prefix, uint8_t *addr) -{ - const char *dlm = "/"; - char *s, *sp; - int ret, depth; - - if ((prefix == NULL) || (addr == NULL)) - return -EINVAL; - - s = strtok_r(prefix, dlm, &sp); - if (s == NULL) - return -EINVAL; - - ret = inet_pton(AF_INET6, s, addr); - if (ret != 1) - return -errno; - - s = strtok_r(NULL, dlm, &sp); - GET_CB_FIELD(s, depth, 0, 128, 0); - - return depth; -} - static int parse_rt_6(FILE *f) { @@ -522,7 +519,7 @@ parse_rt_6(FILE *f) s = NULL; } - ret = __inet_net_pton6(in[RT_PREFIX], rt[j].addr); + ret = _inet_net_pton(AF_INET6, in[RT_PREFIX], rt[j].addr); if (ret < 0) return ret; -- 2.20.1