#include <arpa/inet.h>
#include <net/if.h>
#include <ifaddrs.h>
#include <net/if_dl.h> - (NSArray *)getDataCounters
{
BOOL success;
struct ifaddrs *addrs;
const struct ifaddrs *cursor;
const struct if_data *networkStatisc; int WiFiSent = ;
int WiFiReceived = ;
int WWANSent = ;
int WWANReceived = ; NSString *name=[[NSString alloc]init]; success = getifaddrs(&addrs) == ;
if (success)
{
cursor = addrs;
while (cursor != NULL)
{
name=[NSString stringWithFormat:@"%s",cursor->ifa_name];
NSLog(@"ifa_name %s == %@\n", cursor->ifa_name,name);
// names of interfaces: en0 is WiFi ,pdp_ip0 is WWAN
if (cursor->ifa_addr->sa_family == AF_LINK)
{
if ([name hasPrefix:@"en"])
{
networkStatisc = (const struct if_data *) cursor->ifa_data;
WiFiSent+=networkStatisc->ifi_obytes;
WiFiReceived+=networkStatisc->ifi_ibytes;
NSLog(@"WiFiSent %d ==%d",WiFiSent,networkStatisc->ifi_obytes);
NSLog(@"WiFiReceived %d ==%d",WiFiReceived,networkStatisc->ifi_ibytes);
}
if ([name hasPrefix:@"pdp_ip"])
{
networkStatisc = (const struct if_data *) cursor->ifa_data;
WWANSent+=networkStatisc->ifi_obytes;
WWANReceived+=networkStatisc->ifi_ibytes;
NSLog(@"WWANSent %d ==%d",WWANSent,networkStatisc->ifi_obytes);
NSLog(@"WWANReceived %d ==%d",WWANReceived,networkStatisc->ifi_ibytes);
}
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
return [NSArray arrayWithObjects:[NSNumber numberWithInt:WiFiSent], [NSNumber numberWithInt:WiFiReceived],[NSNumber numberWithInt:WWANSent],[NSNumber numberWithInt:WWANReceived], nil];
}

最新文章

  1. JAVA 编程规范(上)
  2. JS---如何避免用户在请求时“猛击”
  3. 很简单的多线程访问python嘿嘿嘿
  4. Ajax 无刷新上传文件插件 uploadify 的使用
  5. 新公司入职第一天遇到的 关于 CSS 单行溢出文本显示省略号...的问题
  6. 烂泥:KVM、kickstart与NFS集成
  7. Chrome扩展开发(Gmail附件管理助手)系列之〇——概述
  8. 如何查看mysql索引
  9. 低功耗蓝牙4.0BLE编程-nrf51822开发(1)
  10. HDUoj-------(1128)Self Numbers
  11. JAVA线程优化
  12. LA 3708 Graveyard(推理 参考系 中位数)
  13. 修改mysql的默认字符集
  14. Sublime-text 自己定义快捷键攻略
  15. Jfinal中Db类的的使用
  16. TabBottomFragmentLayout【自定义底部选项卡区域(搭配Fragment)】
  17. Linux framebuffer测试程序
  18. mybatis_10关联查询_一对多
  19. WxWidgets笔记
  20. maven默认本地仓库目录

热门文章

  1. 使用TensorFlow低级别的API进行编程
  2. Git_时光机穿梭
  3. oracle的dump理解
  4. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls
  5. Spring Boot中使用redis的发布/订阅模式
  6. BTA 常问的 Java基础40道常见面试题及详细答案
  7. 关于deselectRowAtIndexPath
  8. 利用 FastCoding 将对象进行本地持久化
  9. With Visual Studio, Open Same File In Two Windows, Updates Reflected in Both
  10. 使用Scala