strace/linux/unix_diag.h
Masatake YAMATO 120e5dbcac Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.

For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.

An example of a server side communication using netcat:

	$ ./strace -yy -e network nc -l -U /tmp/example.sock
	socket(PF_LOCAL, SOCK_STREAM, 0)        = 3
	setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
	bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
	listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
	accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
	recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
	INPUT

An example of a client side communication using netcat:

	$ ./strace -yy -e network nc -U /tmp/example.sock
	socket(PF_LOCAL, SOCK_STREAM, 0)        = 3
	connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
	getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
	INPUT
	...
	sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6

* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-25 01:00:48 +00:00

25 lines
456 B
C

struct unix_diag_req {
uint8_t sdiag_family;
uint8_t sdiag_protocol;
uint16_t pad;
uint32_t udiag_states;
uint32_t udiag_ino;
uint32_t udiag_show;
uint32_t udiag_cookie[2];
};
#define UDIAG_SHOW_NAME 0x01
#define UDIAG_SHOW_PEER 0x04
struct unix_diag_msg {
uint8_t udiag_family;
uint8_t udiag_type;
uint8_t udiag_state;
uint8_t pad;
uint32_t udiag_ino;
uint32_t udiag_cookie[2];
};
#define UNIX_DIAG_NAME 0
#define UNIX_DIAG_PEER 2