android NDK 获取本机IP
2016-07-29 22:57
615 查看
int i=0; int sockfd; struct ifconf ifconf; unsigned char buf[512]; struct ifreq *ifreq; //初始化ifconf ifconf.ifc_len = 512; ifconf.ifc_buf = (char*)buf; if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0))<0) { return -1; } ioctl(sockfd, SIOCGIFCONF, &ifconf); //获取所有接口信息 //接下来一个一个的获取IP地址 ifreq = (struct ifreq*)buf; for (i=(ifconf.ifc_len/sizeof (struct ifreq)); i>0; i--) { // if(ifreq->ifr_flags == AF_INET){ //for ipv4 char* ip = inet_ntoa(((struct sockaddr_in*)&(ifreq->ifr_addr))->sin_addr); __android_log_print(ANDROID_LOG_INFO,"test","%s",ip); ifreq++; // } }
相关文章推荐
- Android之在ubuntu过滤日志以及ps总结
- Android开发方向
- Android图片缓存之Glide进阶(四)
- Android图片缓存之初识Glide(三)
- Android图片缓存之Lru算法(二)
- Android Permission整理
- Android ndk socket客户端
- android ndk 使用LOG
- 减少视图层级<merge />
- Android RecyclerView中ViewHolder的复用导致数据错乱解决办法
- 关于回调技术的原理和作用
- Android 之 Picasso使用
- 重用布局文件
- Android 学习之 Fragment(一)
- Android Telephony分析(三) ---- RILJ详解
- android手机(设备)横竖屏切换时activity的生命周期是如何执行的?
- android 坐标问题
- LinearLayout居中
- Android 异步任务队列实现
- android尺寸单位