Skip to content

Commit

Permalink
sa: HAVE_INET6 should not change the API; add checks for AF_INET6
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed Jun 10, 2021
1 parent 9e909a6 commit b729821
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 0 additions & 2 deletions include/re_sa.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ bool sa_is_linklocal(const struct sa *sa);
bool sa_is_loopback(const struct sa *sa);
bool sa_is_any(const struct sa *sa);

#ifdef HAVE_INET6
void sa_set_scopeid(struct sa *sa, int scopeid);
int sa_scopeid(const struct sa *sa);
int sa_cpy_scopeid(struct sa *sa_dst, const struct sa *sa_src);
bool sa_is_ipv6ll(const struct sa *sa);
#endif

struct re_printf;
int sa_print_addr(struct re_printf *pf, const struct sa *sa);
20 changes: 18 additions & 2 deletions src/sa/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,27 +593,41 @@ bool sa_is_any(const struct sa *sa)
}


#ifdef HAVE_INET6
void sa_set_scopeid(struct sa *sa, int scopeid)
{
#ifndef HAVE_INET6
return;
#endif
if (!sa)
return;

if (sa_af(sa) != AF_INET6)
return;

sa->u.in6.sin6_scope_id = scopeid;
}


int sa_scopeid(const struct sa *sa)
{
#ifndef HAVE_INET6
return;
#endif
if (!sa)
return 0;

if (sa_af(sa) != AF_INET6)
return 0;

return sa->u.in6.sin6_scope_id;
}


int sa_cpy_scopeid(struct sa *sa_dst, const struct sa *sa_src)
{
#ifndef HAVE_INET6
return;
#endif
if (!sa_dst || !sa_src)
return EINVAL;

Expand All @@ -627,6 +641,8 @@ int sa_cpy_scopeid(struct sa *sa_dst, const struct sa *sa_src)

bool sa_is_ipv6ll(const struct sa *sa)
{
#ifndef HAVE_INET6
return;
#endif
return sa_af(sa) == AF_INET6 && sa_is_linklocal(sa);
}
#endif

0 comments on commit b729821

Please sign in to comment.