On Wed, Jun 15, 2016 at 12:43:02PM +0000, Fabien Siron wrote: > Because netlink parsing needs a way to get the netlink protocol and the > socketutils.c file can only print the protocol, this commit adds an interface > to get some socket information without printing it. > > * defs.h > (get_sockaddr_by_inode_cached, get_sockaddr_by_inode): Add. > * socketutils.c (cache_print_inode_details): Remove function. > (cache_inode_details, get_sockaddr_by_inode_cached, get_sockaddr_by_inode, > netlink_get): New functions. > (inet_print): Call print_sockaddr_by_inode_details. > (unix_print): Likewise. > (netlink_print): Likewise. > (unix_parse_response): Call cache_inode_details. > (netlink_parse_resonse): Likewise. > (inet_parse_response): Likewise.
Please split this into 2 commits: + the first that changes cache_and_print_inode_details to cache_inode_details and adds print_sockaddr_by_inode_cached calls, + the second that introduces get_sockaddr_by_inode_cached, get_sockaddr_by_inode, and netlink_get. > --- > defs.h | 3 +++ > socketutils.c | 64 > +++++++++++++++++++++++++++++++++++++++++++++++++++-------- > 2 files changed, 59 insertions(+), 8 deletions(-) > > diff --git a/defs.h b/defs.h > index ee35dab..e9a9392 100644 > --- a/defs.h > +++ b/defs.h > @@ -523,6 +523,9 @@ extern int umoven_or_printaddr(struct tcb *, long, > unsigned int, void *); k> umoven_or_printaddr((pid), (addr), sizeof(*(objp)), (void *) (objp)) > extern int umovestr(struct tcb *, long, unsigned int, char *); > extern int upeek(int pid, long, long *); > +extern char *get_sockaddr_by_inode_cached(const unsigned long); > +extern char *get_sockaddr_by_inode(const unsigned long inode, > + const enum sock_proto); Let's move them closer to print_sockaddr_by_inode and print_sockaddr_by_inode_cached. > +static char * > +netlink_get(const int fd, const unsigned long inode) > +{ > + if (netlink_send_query(fd, inode) > + && receive_responses(fd, inode, "NETLINK", > + netlink_parse_response)) { > + cache_entry *e = &cache[inode & CACHE_MASK]; > + if (e && inode == e->inode) > + return e->details; This duplicates the code from get_sockaddr_by_inode_cached. > +char * > +get_sockaddr_by_inode(const unsigned long inode, const enum sock_proto proto) > +{ > + if ((unsigned int) proto >= ARRAY_SIZE(protocols) || > + (proto != SOCK_PROTO_UNKNOWN && !protocols[proto].print)) > + return false; > + > + const int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG); > + if (fd < 0) > + return NULL; > + char *details = NULL; > + > + if (proto != SOCK_PROTO_UNKNOWN) { > + if (proto == SOCK_PROTO_NETLINK) > + details = netlink_get(fd, inode); > + } > + > + close(fd); > + > + return details; This is too complicated for the simple task it solves. -- ldv
pgpyb1k_6YGn8.pgp
Description: PGP signature
------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports. http://sdm.link/zohomanageengine
_______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel