IP and port associated with a socket fd

Zubin Mithra zubin.mithra at gmail.com
Tue Aug 5 13:56:35 UTC 2014

Hello everyone,

I've just sent a V2 of the patch "Print ip and port associated with
descriptor with -yy". It adds support for IPv6 and IPv4 over UDP and

I've played around with netcat for setting up the server and client
and the output looks as follows :-

- Server over UDP(ipv6) - https://gist.github.com/eQu1NoX/0c90dbe82e97e636fab8
- Client over UDP(ipv6) - https://gist.github.com/eQu1NoX/e38100ba613066aa3b21

- Server over UDP(ipv4) - https://gist.github.com/eQu1NoX/3c96dec9e24ce0c2046d
- Client over UDP(ipv4) - https://gist.github.com/eQu1NoX/ae9aa32c75e2a11af580

- Server over TCP(ipv4) - https://gist.github.com/eQu1NoX/5fe4d144a6d818382399
- Client over TCP(ipv4) - https://gist.github.com/eQu1NoX/69724cc1041d420ac596

- Server over TCP(ipv6) - https://gist.github.com/eQu1NoX/59a162a0e250a473e63f
- Client over TCP(ipv6) - https://gist.github.com/eQu1NoX/a97d74bd059682da6fe9

-- zm

On Tue, Aug 5, 2014 at 9:24 AM, Zubin Mithra <zubin.mithra at gmail.com> wrote:
> 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