[PATCH 1/6] socketeutils: extend receive_responses() to handle other type than SOCK_DIAG_BY_FAMILY communication
Masatake YAMATO
yamato at redhat.com
Sat Jun 10 06:32:42 UTC 2017
Now I'm working on decoding the communication on Netlink GENERIC
protocol. For the task, many lines of receive_responses can be reused
with two minor modifications. This is the first one.
receive_responses was written for decoding the response from kernel of
SOCK_DIAG_BY_FAMILY communication; other communications were ignored.
This change makes the type of communication a parameter. So the function
can be used for another type of communication.
* socketutils.c (receive_responses): add a new parameter
`expected_msg_type' to handle other type than SOCK_DIAG_BY_FAMILY
communication.
Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
socketutils.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/socketutils.c b/socketutils.c
index a3aedb4..3292c2e 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,
+ 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,7 @@ 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 +406,7 @@ 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,7 +438,7 @@ static const char *
netlink_get(const int fd, const unsigned long inode)
{
return netlink_send_query(fd, inode)
- && receive_responses(fd, inode, "NETLINK",
+ && receive_responses(fd, inode, SOCK_DIAG_BY_FAMILY, "NETLINK",
netlink_parse_response)
? get_sockaddr_by_inode_cached(inode) : NULL;
}
--
2.9.4
More information about the Strace-devel
mailing list