简体   繁体   English

在NEPacketTunnelProvider中获取UDP数据包详细信息

[英]Getting UDP packet Details in NEPacketTunnelProvider

I want to get the details like IP address of source & destination along with the port numbers from the UDP packet we received in 我想从我们收到的UDP数据包中获取详细信息,例如源和目标的IP地址以及端口号

 self.packetFlow.readPackets { [weak self] (packets: [Data], protocols: [NSNumber]) in
        }

I am using following code to for creating session so assuming that the packet will be UDP 我正在使用以下代码来创建会话,因此假设数据包将是UDP

self.session = self.createUDPSession(to: NWHostEndpoint(hostname: serverAddress, port: serverPort), from: nil)

where self.sssion is var session: NWUDPSession? var session: NWUDPSession?在哪里var session: NWUDPSession?

Do someone has any pointers how to do this in swift ? 有人有任何指示如何迅速做到这一点吗?

I am looking for some code as I am relatively new to packet level things. 我正在寻找一些代码,因为我对数据包级别的事物还比较陌生。

I was able to read the source and destination address, along with ports of the packet using IPPacket class in NEKIT iOS Code. 我可以使用NEKIT iOS代码中的IPPacket类读取源地址和目标地址以及数据包的端口。 Hope this will help someone who face this kind of scenerio. 希望这会对遇到这种情况的人有所帮助。

I would use a solution such as BinUtils to unpack the array of Data packets received from the packetFlow.readPackets() method. 我将使用BinUtils之类的解决方案来解压缩从packetFlow.readPackets()方法接收的数据包数组。 These are IP packets received from your applications. 这些是从您的应用程序接收到的IP数据包。 You will need to define the the format for an the IP Header and UDP Header yourself. 您将需要自己定义IP头和UDP头的格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM