[编程实例]linux 设置网卡为混杂模式
2008-12-10 20:12
417 查看
#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <string.h>
#include <linux/in.h>
#include <linux/if_ether.h>
#include <unistd.h>
#include <net/if.h>
int main(int argc, char **argv) {
int sock, n;
struct ifreq ethreq;
if ( (sock=socket(PF_PACKET, SOCK_RAW,
htons(ETH_P_ALL)))<0) {
perror("socket");
exit(1);
}
/* Set the network card in promiscuos mode */
strncpy(ethreq.ifr_name,"eth0",IFNAMSIZ);
if (ioctl(sock,SIOCGIFFLAGS,ðreq)==-1) {
perror("ioctl");
close(sock);
exit(1);
}
ethreq.ifr_flags|=IFF_PROMISC;
if (ioctl(sock,SIOCSIFFLAGS,ðreq)==-1) {
perror("ioctl");
close(sock);
exit(1);
}
printf("Success to set eth0 to promiscuos mode.../n");
return 0;
}
#include <errno.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <string.h>
#include <linux/in.h>
#include <linux/if_ether.h>
#include <unistd.h>
#include <net/if.h>
int main(int argc, char **argv) {
int sock, n;
struct ifreq ethreq;
if ( (sock=socket(PF_PACKET, SOCK_RAW,
htons(ETH_P_ALL)))<0) {
perror("socket");
exit(1);
}
/* Set the network card in promiscuos mode */
strncpy(ethreq.ifr_name,"eth0",IFNAMSIZ);
if (ioctl(sock,SIOCGIFFLAGS,ðreq)==-1) {
perror("ioctl");
close(sock);
exit(1);
}
ethreq.ifr_flags|=IFF_PROMISC;
if (ioctl(sock,SIOCSIFFLAGS,ðreq)==-1) {
perror("ioctl");
close(sock);
exit(1);
}
printf("Success to set eth0 to promiscuos mode.../n");
return 0;
}
相关文章推荐
- 网卡混杂模式Promiscuous与linux上混杂模式的设置
- 网卡混杂模式Promiscuous与linux上混杂模式的设置
- Linux下网卡混杂模式设置和取消
- [原]linux下将网卡设置为混杂模式
- Linux下网卡混杂模式设置和取消
- LINUX网卡(设置千兆网卡速度及模式)
- LINUX网卡(设置网卡速度及模式)
- Linux/Unix命令之Ethtool (设置千兆网卡速度及模式)
- 设置网卡的混杂模式
- 设置网卡混杂模式
- 在 LINUX里将网卡更改为混杂模式
- linux 下怎样查看网卡是否支持混杂(promisc)模式
- LINUX网卡(设置千兆网卡速度及模式)
- X Chen笔记---Centos网卡设置混杂模式的方法
- 设置网卡混杂模式
- LINUX网卡(设置千兆网卡速度及模式)
- LINUX网卡(设置千兆网卡速度及模式)
- Linux网卡配置的四种模式以及防火墙设置的四种方式(CentOS 7.4)未完成
- LINUX网卡(设置千兆网卡速度及模式)
- 将网卡设置为混杂模式