从套接字fd获取IP地址,端口和连接类型

编程入门 行业动态 更新时间:2024-10-24 08:24:21
本文介绍了从套接字fd获取IP地址,端口和连接类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个跟踪网络应用程序的跟踪程序.

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

给出一个属于该被跟踪对象的套接字文件描述符,该跟踪器是否有可能找到它所对应的IP(在服务器的情况下,它所绑定的接口的IP,在客户端的情况下,用于建立连接的接口的地址),端口号和连接类型?是否有可用于完成此工作的libc API? /proc中可以使用的任何信息吗?

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?

推荐答案

对于那些使用ifreq结构的标志,您可以对其使用ioctl()系统调用.

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

更多推荐

从套接字fd获取IP地址,端口和连接类型

本文发布于:2023-08-07 13:46:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319384.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   类型   地址   fd   IP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!