Good evening,
we have developed an application on iphone that , during background fetch or location change,it analizes traffic data usage on the device.
We call getifaddrs() from ifaddrs.h and loop all the ifa_data ("en*" for wifi and "pdp_ip*" for wwan traffic) to calculate the amount of traffic data through the variables ifa_data->ifi_obytes and ifa_data->ifi_oibytes.
We know that during reboot the amount of these variable resets and we handle this case. The problem is when the device consume traffic data greater than 4gb, since these variables res, being of type u_int32_t.
We also tried to retrieve if_data not like struct if_data but like if_data64(beacuse in this struct the two variable are u_int64_t) but the data retrieved from it is wrong (the values not represent the real traffic data usage).
Is there some way to detect to solve this problem and retrieve the exact traffic data consumed from the device? If not, there are other solution, instead of getifaddrs, to retrieve total traffic data usage of the device? We can't intercept in any way when these variable reset for overflow and this problem makes the amount retireved unreliable.
I thank you in advance for future responses.
Good day and good work.
Daniele.
ifi_ibytes and ifi_obytes from getifaddrs reset at 4GB
With regards your specific question, see this thread.
I also recommend that you read this thread, which gives more background to this issue in general.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
Thank you very much for your response eskimo, his information are very useful to me!
One last question. The topic you have linkeed to me is my exact problem. I see that this post is 2 years ago. Can you please confirm that the if_data limitation (u_int32_t, so at 4GB reset the variables) is still present and there is no valid workaround?
From what I understand the only solution to this problem is to request an enhancement request, am I right?
I thank you again for your help.
Daniele.
I see that this post is 2 years ago.
Nothing has changed since then. If things were to change, it’s unlikely that such changes would be applied to this legacy interface.
From what I understand the only solution to this problem is to request an enhancement request, am I right?
Correct. As you draft your ER be mindful of the privacy requirements of the overall iOS platform. For example, consider my advice is this post.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
I have question related to this.
Used same method to get number of sent bytes ( Ifadata->ifiobytes ),but sometimes it returns negative value. Don't understand why so, any help would be appreciated.
Thanks,
Swapnali
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Hello, we used getifaddrs' ifi_ibytes on macOS10 to get traffic data from the utun network card,But the traffic read through ifi_ibytes on macOS11 and macOS12 is doubled. Does the system upgrade affect GetifADdrs? I look forward to your reply. Thanks. SuperJohn
Rather than reanimating all the threads that have ever mentioned getifaddrs
, please start a new thread with the details of the specific issue you’re dealing with. Feel free to include links to any existing threads if you think they’re relevant. Oh, and tag with with Network so that I see it.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"