linux
系统
ioctl
使用示例
These were writed and collected by kf701,
you can use and modify them but NO W
ARRANTY
.
Contact with me : kf_701@21cn.com
程序
1
:检测接口的
inet_addr,netmask,broad_addr
程序
2
:检查接口的物理连接是否正常
程序
3
:更简单一点测试物理连接
程序
4
:调节音量
***************************
程序
1****************************************
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static void usage(){
printf("usage : ipconfig interface \n");
exit(0);
}
int main(int argc,char **argv)
{
struct sockaddr_in *addr;
struct ifreq ifr;
char *name,*address;
int sockfd;
if(argc != 2)
usage();
else
name = argv[1];
sockfd = socket(AF_INET,SOCK_DGRAM,0);
strncpy(ifr.ifr_name,name,IFNAMSIZ-1);
if(ioctl(sockfd,SIOCGIFADDR,&ifr) == -1)
perror("ioctl error"),exit(1);
addr = (struct sockaddr_in *)&(ifr.ifr_addr);
address = inet_ntoa(addr->sin_addr);
printf("inet addr: %s ",address);
if(ioctl(sockfd,SIOCGIFBRDADDR,&ifr) == -1)
perror("ioctl error"),exit(1);