项目需要的内容 获取ip+ 条件编译
2016-06-19 15:15
232 查看
#include <string.h> #include <stdio.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <sys/types.h> #include <netdb.h> #include <net/if.h> #include <arpa/inet.h> #include <iostream> using namespace std; #define ERRORIP 0 char *ip_search() { int sfd, intr; struct ifreq buf[16]; struct ifconf ifc; sfd = socket (AF_INET, SOCK_DGRAM, 0); if (sfd < 0) return ERRORIP; ifc.ifc_len = sizeof(buf); ifc.ifc_buf = (caddr_t)buf; if (ioctl(sfd, SIOCGIFCONF, (char *)&ifc)) return ERRORIP; intr = ifc.ifc_len / sizeof(struct ifreq); while (intr-- > 0 && ioctl(sfd, SIOCGIFADDR, (char *)&buf[intr])); close(sfd); return inet_ntoa(((struct sockaddr_in*)(&buf[intr].ifr_addr))-> sin_addr); } void cc(char*f) { cout<<f<<endl; } int main() { cc(ip_search()); return 0; } /*#if _WinNT_ #include <iostream> using namespace std; #include<windows.h> int main() { cout<<"wzzx test"<<endl; Sleep(10000); return 1; } #endif #if _Linux_ #include <iostream> using namespace std; #include<time.h> int main() { cout<<"wzzx test"<<endl; sleep(10000); return 1; } #endif */待深入学习
相关文章推荐
- 构造函数和析构函数的区别
- 进程通信之消息队列
- display:inline-block兼容ie6/7的写法
- ROS与Matlab协同进行运动控制
- 课程总结
- ACdream 1415 最短路+桥
- 98、EditText 按键盘查询 触发事件
- 数据库--索引
- 对象的三大特征
- spring如何把service注入listener或者filter?
- java利用ant压缩指定文件夹
- 《C专家编程》:全面回顾认识C++(十)
- hdu 5399 Too Simple(思路题,函数)
- [置顶] ImageNet Classification with Deep ConvolutionalNeural Networks
- HTML各种兼容性
- 函数
- LeetCode Count Numbers with Unique Digits
- ScrollView属性
- OOP-----封装,继承,多态
- 「C语言」文件的概念与简单数据流的读写函数