Skip to content

Commit

Permalink
sa: add setter and getter for scope id
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 authored and sreimers committed Jun 11, 2021
1 parent ed09f2b commit f36881d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/re_sa.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
29 changes: 29 additions & 0 deletions src/sa/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit f36881d

Please sign in to comment.