From: Masatake YAMATO Date: Sun, 11 Jun 2017 07:42:27 +0000 (+0900) Subject: socketeutils: extend receive_responses to handle other netlink types X-Git-Tag: v4.18~98 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6c33d4628f699f9bb8fb7d3dd5d75e38e9f00aa5;p=strace socketeutils: extend receive_responses to handle other netlink types This is the first patch in series of implementing NETLINK_GENERIC protocol decoder. receive_responses was written for decoding kernel responses of type SOCK_DIAG_BY_FAMILY, other types were ignored. This change makes the type of netlink response a parameter so the function can be used for other types of communication. * socketutils.c (receive_responses): add a new parameter expected_msg_type to handle types other than SOCK_DIAG_BY_FAMILY. Signed-off-by: Masatake YAMATO Signed-off-by: Dmitry V. Levin --- diff --git a/socketutils.c b/socketutils.c index a3aedb4e..01d369e1 100644 --- a/socketutils.c +++ b/socketutils.c @@ -189,6 +189,7 @@ inet_parse_response(const char *const proto_name, const void *const data, static bool receive_responses(const int fd, const unsigned long inode, + const unsigned long expected_msg_type, const char *proto_name, int (* parser) (const char *, const void *, int, unsigned long)) @@ -226,7 +227,7 @@ receive_responses(const int fd, const unsigned long inode, if (!NLMSG_OK(h, ret)) return false; for (; NLMSG_OK(h, ret); h = NLMSG_NEXT(h, ret)) { - if (h->nlmsg_type != SOCK_DIAG_BY_FAMILY) + if (h->nlmsg_type != expected_msg_type) return false; const int rc = parser(proto_name, NLMSG_DATA(h), h->nlmsg_len, inode); @@ -396,7 +397,8 @@ static const char * unix_get(const int fd, const unsigned long inode) { return unix_send_query(fd, inode) - && receive_responses(fd, inode, "UNIX", unix_parse_response) + && receive_responses(fd, inode, SOCK_DIAG_BY_FAMILY, + "UNIX", unix_parse_response) ? get_sockaddr_by_inode_cached(inode) : NULL; } @@ -405,7 +407,8 @@ inet_get(const int fd, const int family, const int protocol, const unsigned long inode, const char *proto_name) { return inet_send_query(fd, family, protocol) - && receive_responses(fd, inode, proto_name, inet_parse_response) + && receive_responses(fd, inode, SOCK_DIAG_BY_FAMILY, + proto_name, inet_parse_response) ? get_sockaddr_by_inode_cached(inode) : NULL; } @@ -437,8 +440,8 @@ static const char * netlink_get(const int fd, const unsigned long inode) { return netlink_send_query(fd, inode) - && receive_responses(fd, inode, "NETLINK", - netlink_parse_response) + && receive_responses(fd, inode, SOCK_DIAG_BY_FAMILY, + "NETLINK", netlink_parse_response) ? get_sockaddr_by_inode_cached(inode) : NULL; }