Linux下检测网卡与网线连接状态,使用ioctl向socket发送SIOCETHTOOL命令字
来源:互联网 发布:大数据技术基础 编辑:程序博客网 时间:2024/04/30 20:16
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/if.h>
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned char u8;
#include <linux/sockios.h>
#include <linux/ethtool.h>
int get_netlink_status(const char *if_name);
int main(int argc, char* argv[])
{
if(argc != 2)
{
fprintf(stderr, "usage: %s <ethname>", argv[0]);
return -1;
}
if(getuid() != 0)
{
fprintf(stderr, "Netlink Status Check Need Root Power./n");
return 1;
}
printf("Net link status: %s/n", get_netlink_status(argv[1])==1?"up":"down");
return 0;
}
// if_name like "ath0", "eth0". Notice: call this function
// need root privilege.
// return value:
// -1 -- error , details can check errno
// 1 -- interface link up
// 0 -- interface link down.
int get_netlink_status(const char *if_name)
{
int skfd;
struct ifreq ifr;
struct ethtool_value edata;
edata.cmd = ETHTOOL_GLINK;
edata.data = 0;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name) - 1);
ifr.ifr_data = (char *) &edata;
if (( skfd = socket( AF_INET, SOCK_DGRAM, 0 )) == 0)
return -1;
if(ioctl( skfd, SIOCETHTOOL, &ifr ) == -1)
{
close(skfd);
return -1;
}
close(skfd);
return edata.data;
}
- Linux下检测网卡与网线连接状态,使用ioctl向socket发送SIOCETHTOOL命令字
- Linux下检测网卡与网线连接状态,使用ioctl向socket发送SIOCETHTOOL命令字
- Linux下检测网卡与网线连接状态,使用ioctl向socket发送SIOCETHTOOL命令字
- Linux下检测网卡与网线连接状态,使用ioctl向socket发送SIOCETHTOOL命令字
- Linux下检测网卡与网线连接状态,使用ioctl向socket发送SIOCETHTOOL命令字
- Linux下检测网卡与网线连接状态,使用ioctl向socket发送SIOCETHTOOL命令字
- Linux下检测网卡与网线连接状态
- Linux下检测网卡与网线连接状态
- Linux下检测网卡与网线的连接状态
- Linux下检测网卡与网线的连接状态
- Linux下检测网卡与网线的连接状态
- Linux 检测网卡与网线连接状态
- Linux下如何用C编程实现检测网卡与网线的连接状态
- Linux下如何用C编程实现检测网卡与网线的连接状态
- linux下检测网卡与网线连通状态
- Linux下检测网卡与网线连通状态
- Linux下检测网卡与网线连通状态
- Linux下检测网卡与网线连通状态
- EditPlus 快捷键
- 《BREW进阶与精通——3G移动增值业务的运营、定制与开发》连载之32---BREW PUSH 服务
- maven创建web项目
- 一些时间日期函数,转自华软
- 【转】WINCE 6.0 调大image
- Linux下检测网卡与网线连接状态,使用ioctl向socket发送SIOCETHTOOL命令字
- 解决:MySQL命令行导入备份时会出现“MySQL server has gone away”的错误
- Cacti 'Linux - Get Memory Usage' Remote Command Execution Vulnerability
- 文件复制--FileStreamDemo.java
- OnCtlColor
- 精通 JS正则表达式
- 博客园首页优化心得(转)
- ActiveX学习笔记二 ActiveX在IE中安全级别问题-实现IObjectSafety接口
- linux系统ioctl使用示例