From f36881d8b020613fee3c62f5968c841b3825c4e9 Mon Sep 17 00:00:00 2001 From: Christian Spielberger Date: Fri, 11 Jun 2021 10:37:53 +0200 Subject: [PATCH] sa: add setter and getter for scope id --- include/re_sa.h | 3 +++ src/sa/sa.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/re_sa.h b/include/re_sa.h index 44929227a..1a74f68c0 100644 --- a/include/re_sa.h +++ b/include/re_sa.h @@ -59,5 +59,8 @@ bool sa_is_linklocal(const struct sa *sa); bool sa_is_loopback(const struct sa *sa); bool sa_is_any(const struct sa *sa); +void sa_set_scopeid(struct sa *sa, uint32_t scopeid); +uint32_t sa_scopeid(const struct sa *sa); + struct re_printf; int sa_print_addr(struct re_printf *pf, const struct sa *sa); diff --git a/src/sa/sa.c b/src/sa/sa.c index 1d293bd09..ab9fc8a7e 100644 --- a/src/sa/sa.c +++ b/src/sa/sa.c @@ -591,3 +591,32 @@ bool sa_is_any(const struct sa *sa) return false; } } + + +void sa_set_scopeid(struct sa *sa, uint32_t scopeid) +{ + if (!sa) + return; + +#ifdef HAVE_INET6 + if (sa_af(sa) != AF_INET6) + return; + + sa->u.in6.sin6_scope_id = scopeid; +#endif +} + + +uint32_t sa_scopeid(const struct sa *sa) +{ + if (!sa) + return 0; + +#ifdef HAVE_INET6 + if (sa_af(sa) != AF_INET6) + return 0; + + return sa->u.in6.sin6_scope_id; +#endif + return 0; +}