0

My colleagues have a system by which they annotate TCP packets at a mid-point (think router) with additional TCP header fields to convey some information to a third element (again, think router) which uses that information to operate in different ways on the packet. (I don't think the actual operation is germane to the question I'm trying to get to, and they don't want me sharing anyways, so I'm leaving it somewhat abstract.)

We know how to do this at the router level - lets call this upstream for lack of a better name. Now they want to do the same thing in the downstream direction at the application level. I'm struggling to find a way of exposing these optional TCP header fields to applications. I'm working on getting my colleagues to work at the application layer (e.g., HTTP headers) which is easily exposed to apps. Let's use the Android APIs as an example, but I have the same question for other smartphone operating systems.

I don't want application developers to have to make kernel extensions to get to these headers and I don't want them having to use NDK either. Both of these smell to me like a fail.

I couldn't find any Android APIs that expose this kind of information to client apps. Is this something where I can develop an Android Service to relieve the app developers from having top figure this out, rather they just use my service for HTTP operations and I can the elevate those TCP headers into the HTTP space? Using the NDK perhaps? Other libraries I should be considering (libpcap comes to mind...)

I did see this question but it seems to be going the wrong direction - writing packets instead of reading them.

3
  • 1
    No. TCP is not a packet-oriented interface to begin with, in the sense that the client applications don't get to reliably even know where the packet boundaries fall. Looking at this from an Android perspective is just making it needlessly more complicated - you need to start by understanding the network protocols themselves, and the extremely limited influence over those which an unprivileged user on android or any other unix-like operating system has. The one thing that does come to mind as meriting research would be "out of band" data. Nov 19, 2013 at 15:17
  • Yeah yeah, stream vs datagram, blah blah blah. I already understand network protocols, I'm stuck with what my colleagues want to do and I'm looking for ways to convince them that it's a bad idea when it's going to a non-router. The Android perspective is important in convincing them that its just a bad idea since it is damn near impossible to get this up to a given app without kernel-level mods. (Sorry if this sounds snarky - I appreciate your comment as it supports my position that this is just an ugly hack that works ok in a relatively-closed environment but should be done a different way.) Nov 19, 2013 at 16:44
  • My preference would be to either send this stuff via a protocol pair (RTP/RTCP come to mind, but that's a difficult trick to pull off in TCP) or a completely separate means (hence the HTTP header notion above, accomplished relatively easily by inserting a transparent proxy). We also have to be able to do this on non-rooted Android devices which is yet another argument for an application-layer solution. Nov 19, 2013 at 16:45

2 Answers 2

1

The answer seems to be that you need to be inside the kernel to do this - the TCP headers themselves do NOT make it through the socket. Of course this makes sense, since the point of TCP is to transfer a stream of data, not a sequence of packets containing data, even though the mechanism to transfer this stream of data is a sequence of packets.

If you're inside the kernel - specifically, inside the TCP stack - you can see these headers, but I don't really want to be there and it seems impractical to require this of our library users.

0

On some platforms, there are things like RAW sockets and PCAP libraries that allow applications to gain low-level access to TCP/UDP headers.

For Android, have a look at these:

Android PCAP

android use pcap library

3
  • Do we need to root an Android device to use those libraries? Nov 20, 2013 at 17:24
  • Android PCAP does not require root access (according to its webpage). I don't know about other libraries. Nov 20, 2013 at 18:07
  • 1
    Android PCAP, as far as I can tell by reading their material, is not interesting for this problem. What it seems to do is allow a WiFi dongle to be attached to an Android device and capture packets transferred via that dongle. It expressly states that it doesn't work with the built-in network adapters (WLAN or WWAN). Nov 21, 2013 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.