Since we can't send raw IP packets from iPhone, wanted to analyse the
IP packet received from the accessory, find if it is TCP/UDP and
construct the corresponding packet and send it to the destination.
Just forwarding packets won’t work here. Let’s focus on TCP for the moment. There are two problems with forwarding packets:
-
You can’t do it because there’s no way to send raw IP [1].
-
The packets you get have a source address that’s unique to your accessory, probably some link-local or private IP address. If you forward those as is, the receiver’s reply will never get to you.
So you have to do some sort of rewriting. The traditional option here is to implement NAT, however that’s not feasible on iOS. An alternative is to use your own TCP/IP stack to re-assemble the TCP flow from the packets you get from the device and then proxy that flow using an iOS TCP API like NWConnection
. That feasible, but you probably don’t want to write your own TCP/IP stack from scratch.
Is there any library on the ios side which might help us with this ?
There’s nothing in the iOS SDK. There are plenty of third-party libraries that let you slice’n’dice IP packets, including full-scale user space IP stacks, but I don’t have any direct experience so I can’t offer a specific recommendation.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Even on systems where raw IP is available, you typically can’t do this the platform’s TCP stack ‘owns’ the TCP protocol.