IP and port associated with a socket fd

Zubin Mithra zubin.mithra at gmail.com
Tue Aug 5 03:54:04 UTC 2014


Hello everyone,

A few notes on the patch "Print ip and port associated with descriptor
with -yy" :-

1. A sample output of running it on the client and the server can be
found here :-
- client : https://gist.github.com/eQu1NoX/3a325de729b4705dc9c3
- server : https://gist.github.com/eQu1NoX/3713abc3bae2657d4d6e

2. Currently, the ip and port associated with a file descriptor is
obtained in a similar way as netstat does it(print_remote_ipport of
the patch corresponds to tcp_do_one in netstat; I have not added in
support for tcp6, udp, udp6). This is how it prints out the ip and
port associated with a file descriptor :-
    - If -yy is used and if readlink(fd) results in something starting
with "socket:[", extract the inode number from the path returned from
getfdpath.
    - Read lines /proc/net/tcp and parse the ipv4 remote address and
port associated with the inode number and print it out.
    - In cases where the remote address and port cannot be found
out(eg:- a connect call, where the inode number does not yet
correspond to an ip and port; or a close of a file descriptor that has
not been "connect"ed yet), it simply prints out the path returned by
getfdpath.


If this implementation sounds good, I can add in support to read from
/proc/net/tcp6, /proc/net/udp and /proc/net/udp6.


Thanks,
-- zm




More information about the Strace-devel mailing list