On Fri, 22 May 2015 07:51:20 -0700
Donald Sharp <sha...@cumulusnetworks.com> wrote:

> We sure seem to have allot of different ways to get the address size
> for whatever family we are using.  I haven't done a complete in depth
> examination of the code but it sure seems like something that we could
> standardize on.

Agreed. There's lots of cruft in this regard. E.g. I plan to make all
code use sockunion2str and prefix2str (instead of e.g. inet_ntop in
switch). I also think they should print "(unspec)" etc. This would
allow to remove lot of duplicate code in the logging functions.

Not to speak about merging all the prefix46 stuff code to be AF
independent. I have a list of clean ups I hope to do after few weeks of
time. Overall I think lot of the code can be merged.

> 
> donald
> 
> On Fri, May 22, 2015 at 3:40 AM, Timo Teräs <timo.te...@iki.fi> wrote:
> 
> > Upcoming nhrp code will use this, and it can be used to remove
> > the sockunion2ip(X) macro.
> >
> > Signed-off-by: Timo Teräs <timo.te...@iki.fi>
> > ---
> >  lib/sockunion.c | 56
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  lib/sockunion.h |  5 +++++
> >  2 files changed, 61 insertions(+)
> >
> > diff --git a/lib/sockunion.c b/lib/sockunion.c
> > index c7315f2..727730a 100644
> > --- a/lib/sockunion.c
> > +++ b/lib/sockunion.c
> > @@ -589,6 +589,62 @@ sockunion_hash (const union sockunion *su)
> >    return 0;
> >  }
> >
> > +size_t
> > +family2addrsize(int family)
> > +{
> > +  switch (family)
> > +    {
> > +    case AF_INET:
> > +      return sizeof(struct in_addr);
> > +#ifdef HAVE_IPV6
> > +    case AF_INET6:
> > +      return sizeof(struct in6_addr);
> > +#endif /* HAVE_IPV6 */
> > +    }
> > +  return 0;
> > +}
> > +
> > +size_t
> > +sockunion_get_addrlen(const union sockunion *su)
> > +{
> > +  return family2addrsize(sockunion_family(su));
> > +}
> > +
> > +const u_char *
> > +sockunion_get_addr(const union sockunion *su)
> > +{
> > +  switch (sockunion_family(su))
> > +    {
> > +    case AF_INET:
> > +      return (const u_char *) &su->sin.sin_addr.s_addr;
> > +#ifdef HAVE_IPV6
> > +    case AF_INET6:
> > +      return (const u_char *) &su->sin6.sin6_addr;
> > +#endif /* HAVE_IPV6 */
> > +    }
> > +  return NULL;
> > +}
> > +
> > +void
> > +sockunion_set(union sockunion *su, int family, const u_char *addr,
> > size_t bytes)
> > +{
> > +  if (family2addrsize(family) != bytes)
> > +    return;
> > +
> > +  sockunion_family(su) = family;
> > +  switch (family)
> > +    {
> > +    case AF_INET:
> > +      memcpy(&su->sin.sin_addr.s_addr, addr, bytes);
> > +      break;
> > +#ifdef HAVE_IPV6
> > +    case AF_INET6:
> > +      memcpy(&su->sin6.sin6_addr, addr, bytes);
> > +      break;
> > +#endif /* HAVE_IPV6 */
> > +    }
> > +}
> > +
> >  /* After TCP connection is established.  Get local address and
> > port. */ union sockunion *
> >  sockunion_getsockname (int fd)
> > diff --git a/lib/sockunion.h b/lib/sockunion.h
> > index ea3b833..a6f964f 100644
> > --- a/lib/sockunion.h
> > +++ b/lib/sockunion.h
> > @@ -89,6 +89,11 @@ extern int sockunion_cmp (const union sockunion
> > *, const union sockunion *);
> >  extern int sockunion_same (const union sockunion *, const union
> > sockunion *);
> >  extern unsigned int sockunion_hash (const union sockunion *);
> >
> > +extern size_t family2addrsize(int family);
> > +extern size_t sockunion_get_addrlen(const union sockunion *);
> > +extern const u_char *sockunion_get_addr(const union sockunion *);
> > +extern void sockunion_set(union sockunion *, int family, const
> > u_char *addr, size_t bytes);
> > +
> >  extern union sockunion *sockunion_str2su (const char *str);
> >  extern int sockunion_accept (int sock, union sockunion *);
> >  extern int sockunion_stream_socket (union sockunion *);
> > --
> > 2.4.1
> >
> >
> > _______________________________________________
> > Quagga-dev mailing list
> > Quagga-dev@lists.quagga.net
> > https://lists.quagga.net/mailman/listinfo/quagga-dev
> >


_______________________________________________
Quagga-dev mailing list
Quagga-dev@lists.quagga.net
https://lists.quagga.net/mailman/listinfo/quagga-dev

Reply via email to