28

ios-网络流量统计功能的实现

上传者:499752884

发布时间:2012-11-26 14:22:53

大小:180 K

简介:1.3G/GPRS流量统计 int getGprs3GFlowIOBytes() {   struct ifaddrs *ifa_list = 0, *ifa;   if (getifaddrs(&ifa_list) == -1)   {     return 0;   }   uint32_t iBytes = 0;   uint32_t oBytes = 0;   for (ifa = ifa_list; ifa; ifa = ifa->ifa_next)   {     if (AF_LINK != ifa->ifa_addr->sa_family)         continue;     if (!(ifa->ifa_flags & IFF_UP) && !(ifa->ifa_flags & IFF_RUNNING))         continue;     if (ifa->ifa_data == 0)         continue;     if (!strcmp(ifa->ifa_name, "pdp_ip0"))     {         struct if_data *if_data = (struct if_data *)ifa->ifa_data;         iBytes += if_data->ifi_ibytes;         oBytes += if_data->ifi_obytes;               NSLog(@"%s :iBytes is %d, oBytes is %d",                     ifa->ifa_name, iBytes, oBytes);     }   }   freeifaddrs(ifa_list);     return iBytes + oBytes; } 返回的结果为byte

ios开发 网络流量统计
下 载 40人已下载
分享