如何确定同一 iOS 设备上对等 TCP 连接的 PID? [英] How do you determine the PID of a peer TCP connection on the same iOS device?

查看:28
本文介绍了如何确定同一 iOS 设备上对等 TCP 连接的 PID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于我不想讨论的原因(与我无法更改的第三方库的兼容性有关),我需要使用 TCP 套接字在 iOS 的单个进程中执行 IPC.

For reasons I'd rather not go into (has to do with compatibility with a third-party library that I cannot change), I need to use a TCP socket to do IPC within a single process in iOS.

为了防止其他进程与我的 TCP IPC 套接字通信,我想与操作系统验证调用 connect()(来自另一个线程)的进程具有与以下相同的 PID我自己的.

In order to prevent other processes from talking to my TCP IPC socket, I'd like to verify with the OS that the process calling connect() (from another thread) has the same PID as my own.

在 OS XI 上注意到 netstat 没有此信息(与 Windows 和 Linux 等其他操作系统不同),我能够确定此信息的唯一方法是使用 lsof.我不确定 iOS 沙箱中可能提供什么,但到目前为止,我最好的选择(即使它看起来很昂贵)似乎是弄清楚 lsof 正在做什么并尝试复制它.

On OS X I noticed that netstat does not have this information (unlike other OSes such as Windows and Linux) and the only way I was able to determine this information was using lsof. I am not sure what might be available in the iOS sandbox, but so far it seems like my best bet (even though it seems expensive) is to figure out what lsof is doing and try to replicate that.

有谁知道我可以用来检查这个的系统调用吗?我已经通读了 getsockopt(2) 并且没有看到任何适用的内容,而且我找不到关于支持哪些 ioctl(2) 调用的文档.

Does anyone know of a system call I can use in order to check this? I've already read through getsockopt(2) and don't see anything that applies, and I can't find documentation about what ioctl(2) calls are supported.

这里有什么可能?

推荐答案

哇,对于进程内库来说,这听起来像是一个糟糕的 API.

Wow, that sounds like a terrible API for an in-process library.

getpeername 应该匹配发送端的getsockname.您可以尝试将其与本地进程中所有打开的文件进行匹配.

getpeername on the receiving end should match getsockname of the sending end. You could try to match it up with all open fds in the local process.

这篇关于如何确定同一 iOS 设备上对等 TCP 连接的 PID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆