使用ioctl添加网关产生Network is unreachable的原因
来源:互联网 发布:ubuntu 中文改为英文 编辑:程序博客网 时间:2024/05/22 08:53
代码如下
- #define DBG_ERR(x...) perror(x)
- int net_add_gateway(in_addr_t addr)
- {
- struct rtentry rt;
- int skfd;
- struct sockaddr_in sa = {
- sin_family:PF_INET,
- sin_port:0
- };
- /* Clean out the RTREQ structure. */
- memset((char *) &rt, 0, sizeof(struct rtentry));
- /* Fill in the other fields. */
- rt.rt_flags = (RTF_UP | RTF_GATEWAY);
- rt.rt_dst.sa_family = PF_INET;
- rt.rt_genmask.sa_family = PF_INET;
- sa.sin_addr.s_addr = addr;
- memcpy((char *) &rt.rt_gateway, (char *) &sa, sizeof(struct sockaddr));
- /* Create a socket to the INET kernel. */
- if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- DBG_ERR("socket error");
- return -1;
- }
- /* Tell the kernel to accept this route. */
- if (ioctl(skfd, SIOCADDRT, &rt) < 0) {
- DBG_ERR("net_add_gateway: ioctl SIOCADDRT");
- close(skfd);
- return -1;
- }
- /* Close the socket. */
- close(skfd);
- return (0);
- }
在添加网关时,只要网关IP与IP地址不在同一个网段内,ioctl便会引起Network is unreachable错误.只要将ip、netmask、gateway设置对了即可.
- 使用ioctl添加网关产生Network is unreachable的原因
- 使用ioctl添加网关产生Network is unreachable的原因
- network is unreachable 网关PING不通解决办法
- linux配置网关提示route: SIOCADDRT: Network is unreachable
- Ubuntu network is unreachable
- Network is unreachable
- connect: network is unreachable
- network is unreachable
- connect: network is unreachable
- 【SuSE】network is unreachable
- ping: Network is unreachable
- ping: sendto: Network is unreachable
- ping: sendto: Network is unreachable
- ping: sendto: Network is unreachable
- ping: sendto: Network is unreachable
- ping: sendto: Network is unreachable
- network is unreachable 解决方案之一
- Ubuntu network is unreachable解决方法
- [OpenGL Insights]Ch2. Transitioning Students to Post-Deprecation OpenGL
- oracle误删数据的恢复办法
- 构造函数的初始化列表
- SSH登录linux妙用后台命令
- 什么是熵-------第四部分
- 使用ioctl添加网关产生Network is unreachable的原因
- IOS應用程序多語言本地化解决方案
- HDU 1728 逃离迷宫
- POJ 2993 Emag eht htiw Em Pleh【模拟画棋盘】
- TIPTOP ERP系统成本问题集
- restful client
- webbrowse
- python学习之路三(文件读写)
- Cstring 转 int 型问题(error C2664: “atoi”: 不能将参数 1 从“CString”转换为“const char *”))