Getting IP address, port and connection type from a socket fd

你说的曾经没有我的故事 提交于 2019-12-12 22:06:52

问题


I'm have a tracer process that traces a network application.

Given a socket file descriptor belonging to the tracee, would it be possible for the tracer to find the IP it corresponds to(in the case of a server the IP of the interface it binds to, in the case of a client the address of the interface used to make the connection), the port number and the type of connection? Are there libc APIs that could be used to make this work? Any information in /proc that could be used?

Also, would there be a way to distinguish a file descriptor that corresponds to a socket from one that corresponds to an open file or device?


回答1:


You can use ioctl() syscall for those by invoking respective flags use ifreq structure for it.



来源:https://stackoverflow.com/questions/24133564/getting-ip-address-port-and-connection-type-from-a-socket-fd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!