I know there is a way to read bandswitch.
1 Answers
There is no documented way in the iPhone SDK to do this. I am pretty sure that they use sysctl(), which is a standard BSD call, so it must be present on iPhone OSX, too.
See this answer: How to get network adapter stats in linux/Mac OSX?
A good question is how they got through the Appstore procedure. I think sysctl() is about "halfway" from documented to undocumented API: it is not mentioned in the SDK documentation, but it is present on all BSD systems. So it is possible that Apple does not (or did not) filter for standard BSD calls, and that's why they let sysctl() through.
UPDATE: I successfully ran this netstat code on iPhone Simulator (i have no iPhone device with me at the moment). All I had to do is to comment out #include <net/route.h>
because it is not present in iPhone SDK, and copy the following definition from this header:
#define RTM_IFINFO2 0x12
So it was simpler than I thought. Because there were basically no function calls in this code that is not in the SDK headers, it is possible that Apple will approve your application if you use this code (they cannot filter for simple constants...).
-
Thanks. What is the way to recognize if the bandswitch belong to 3G or wifi? – arachide Jun 01 '10 at 15:25
-
You are iterating over the network adapters in the for() loop (on my simulator it gave 7 results, which equals the number of network adapters printed by ifconfig). According to headers the interface type is in if2m->ifm_data.ifi_type. Not sure about the specific numeric values, but you can compare the input/output bytes with another stat tool to find them out :) – gyim Jun 01 '10 at 23:23