Alexey Vladykin
2009-Dec-28 17:31 UTC
[dtrace-discuss] find sockaddr by file descriptor number
It''s trivial to find file path by file descriptor: fds[fd].fi_pathname. Is there a place where I can get socket address in case fd corresponds to a socket? I''d like to intercept read/write syscalls and print file names or socket addresses for each read/write. Thanks! -- This message posted from opensolaris.org
Dan McDonald
2009-Dec-28 18:01 UTC
[dtrace-discuss] find sockaddr by file descriptor number
On Mon, Dec 28, 2009 at 09:31:06AM -0800, Alexey Vladykin wrote:> Is there a place where I can get socket address in case fd corresponds to a > socket? I''d like to intercept read/write syscalls and print file names or > socket addresses for each read/write.Problem with sockets is read & write aren''t the only syscalls that let you send data. There''s also the send*() and recv*() families of calls. In the case of {send,recv}{msg,to,from}(), that sockaddr can change (imagine a DNS server, e.g.). Your best bet might have been the IP provider, but then you don''t get UNIX sockets or the generalized file-descriptor intercepts you seem to want. Dan
Alexey Vladykin
2009-Dec-28 23:06 UTC
[dtrace-discuss] find sockaddr by file descriptor number
Once I deal with read/write, it should be easy to handle send*/recv* too. I didn''t get your argument that sockaddr can change. Once connection is established, the remote address can''t change. It is IP address, so DNS is not involved. One exception is sendto() with a socket in connection-less mode, when it''s possible to specify destination address for each message. But it''s not a huge problem. OpenSolaris sources (http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/stand/lib/sock/socket.c) define struct inetboot_socket sockets[MAXSOCKET] = { 0 }; which contains all the addresses I need. Is it possible to access this array from DTrace? -- This message posted from opensolaris.org