[PATCH v5] Print ip and port associated with descriptor with -yy
Dmitry V. Levin
ldv at altlinux.org
Mon Aug 25 17:14:56 UTC 2014
On Sun, Aug 24, 2014 at 04:44:23PM +0200, Zubin Mithra wrote:
> On 21-Aug-2014, at 4:27, Dmitry V. Levin <ldv at altlinux.org> wrote:
> > On Thu, Aug 21, 2014 at 02:53:46AM +0400, Dmitry V. Levin wrote:
> >> On Mon, Aug 11, 2014 at 02:21:01PM +0530, zubin.mithra at gmail.com wrote:
> > [...]
> >> if (!inet_ntop(diag_msg->idiag_family, diag_msg->id.idiag_dst,
> >> remote_addr_buf, size) || !remote_addr_buf[0])
> >> return -1;
> >
> > Also note for unconnected sockets idiag_dst/idiag_dport are zero, and
> > idiag_src/idiag_sport have to be used instead.
>
> Currently for unconnected sockets, it would print out the socket inode number(indicating that the socket is unconnected). Would printing idiag_sport instead be confusing?
There are sockets with zero dst address:port and non-zero
src address:port. For example, in your snapshot
(https://gist.github.com/eQu1NoX/5fe4d144a6d818382399):
accept(3<0.0.0.0:0>, {sa_family=AF_INET, sin_port=htons(48435), sin_addr=inet_addr("127.0.0.1")}, [16]) = 4
I think it would be less confusing to print both src and dst address:port
when dst address:port is non-zero, for example:
accept(3<0.0.0.0:7171>, {sa_family=AF_INET, sin_port=htons(48435), sin_addr=inet_addr("127.0.0.1")}, [16]) = 4<127.0.0.1:7171->127.0.0.1:48435>
static bool
parse_response(const struct inet_diag_msg *diag_msg, const unsigned long inode)
{
static const char zero_addr[sizeof(struct in6_addr)];
size_t addr_size;
socklen_t text_size;
if (diag_msg->idiag_inode != inode)
return false;
switch(diag_msg->idiag_family) {
case AF_INET:
addr_size = sizeof(struct in_addr);
text_size = INET_ADDRSTRLEN;
break;
case AF_INET6:
addr_size = sizeof(struct in6_addr);
text_size = INET6_ADDRSTRLEN;
break;
default:
return false;
}
char src_buf[text_size];
if (!inet_ntop(diag_msg->idiag_family, diag_msg->id.idiag_src,
src_buf, text_size))
return false;
if (diag_msg->id.idiag_dport ||
memcmp(zero_addr, diag_msg->id.idiag_dst, addr_size)) {
char dst_buf[text_size];
if (!inet_ntop(diag_msg->idiag_family, diag_msg->id.idiag_dst,
dst_buf, text_size))
return false;
tprintf("%s:%u->%s:%u",
src_buf, ntohs(diag_msg->id.idiag_sport),
dst_buf, ntohs(diag_msg->id.idiag_dport));
} else {
tprintf("%s:%u", src_buf, ntohs(diag_msg->id.idiag_sport));
}
return true;
}
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20140825/a377116a/attachment.bin>
More information about the Strace-devel
mailing list