On Sun, Aug 20, 2017 at 08:17:18PM +0800, JingPiao Chen wrote: > * rtnl_addr.c: Include <arpa/inet.h> and <linux/netdevice.h>. > (decode_ifa_address, decode_ifa_cacheinfo, > decode_ifa_flags): New functions. > (ifaddrmsg_nla_decoders): New array. > (decode_ifaddrmsg): Use it. > --- > rtnl_addr.c | 94 > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 93 insertions(+), 1 deletion(-) > > diff --git a/rtnl_addr.c b/rtnl_addr.c > index c7e37ea..c4bde06 100644 > --- a/rtnl_addr.c > +++ b/rtnl_addr.c > @@ -32,16 +32,106 @@ > #include "nlattr.h" > #include "print_fields.h" > > +#include <arpa/inet.h> > + > #include "netlink.h" > #include <linux/rtnetlink.h> > #ifdef HAVE_LINUX_IF_ADDR_H > # include <linux/if_addr.h> > #endif > +#include <linux/netdevice.h> > > #include "xlat/ifaddrflags.h" > #include "xlat/routing_scopes.h" > #include "xlat/rtnl_addr_attrs.h" > > +static bool > +decode_ifa_address(struct tcb *const tcp, > + const kernel_ulong_t addr, > + const unsigned int len, > + const void *const opaque_data) > +{ > + const struct ifaddrmsg *const ifaddr = opaque_data; > + const unsigned int addr_len = > + len < MAX_ADDR_LEN ? len : MAX_ADDR_LEN; > + char buf[MAX_ADDR_LEN]; > + > + if (!umoven_or_printaddr(tcp, addr, addr_len, buf)) { > + switch (ifaddr->ifa_family) { > + case AF_INET: { > + char str[INET_ADDRSTRLEN]; > + > + if (addr_len < sizeof(struct in_addr) > + || !inet_ntop(AF_INET, buf, str, sizeof(str))) > + return false;
Could we check whether len >= sizeof(struct in_addr) before umoven_or_printaddr? It's a good idea to avoid umoven if it's known in advance that it's result will be ignored. > + tprints(str); > + break; > + } > + case AF_INET6: { > + char str[INET6_ADDRSTRLEN]; > + > + if (addr_len < sizeof(struct in6_addr) > + || !inet_ntop(AF_INET6, buf, str, sizeof(str))) > + break; Likewise, with len >= sizeof(struct in6_addr). > + tprints(str); > + break; > + } > + default: > + return false; > + } > + } > + > + return true; > +} BTW, decode_ifa_address looks very similar to decode_ifla_address, and both of them share ideas with print_inet_addr. Could we reuse the code somehow? Maybe create a separate function, say decode_inet_addr, and use it both in decode_ifla_address and decode_ifa_address? -- ldv
signature.asc
Description: PGP signature
------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel