人生如逆旅,我亦是行人!江湖人称wsjjeremy.blog.chinaunix.net
ubuntuer
全部博文(930)
intern(3)
string(19)
正则表达式(5)
2011年(60)
2010年(220)
2009年(371)
2008年(279)
baocheng
nba76ers
renjian2
qq576709
mcn304
zibuyule
西农魔峰
曾德标
zhuqing_
shanck
tendy
moshangx
wb123456
smile124
hjshajsh
chenhong
bzhao
python16
分类: LINUX
2009-05-07 15:44:25
[root@mip-123456 ioctl]# cat promisc.c #include <sys/types.h> #include <stdio.h> #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <errno.h> #include <linux/if_ether.h> #include <net/if.h> #include <sys/ioctl.h> #include <string.h> int do_promisc() { int f, s; struct ifreq ifr; if ((f = socket(AF_INET, SOCK_PACKET, htons(ETH_P_IP))) < 0) return -1; strcpy(ifr.ifr_name, "eth0"); if ((s = ioctl(f, SIOCGIFFLAGS, &ifr)) < 0) { close(f); return-1; } ifr.ifr_flags |= IFF_PROMISC; if ((s = ioctl(f, SIOCSIFFLAGS, &ifr)) < 0) { return -1; } printf("Setting interface ::: %s ::: to promisc\n\n", ifr.ifr_name); return 0; } int main() { do_promisc(); return 0; } [root@mip-123456 ioctl]# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:22:68:3C:9C:F0 inet addr:172.24.149.212 Bcast:172.24.149.255 Mask:255.255.255.0 inet6 addr: fe80::222:68ff:fe3c:9cf0/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:3643 errors:0 dropped:0 overruns:0 frame:0 TX packets:6629 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:6253468 (5.9 MiB) TX bytes:2379136 (2.2 MiB) Interrupt:233 Base address:0xa000 [root@mip-123456 ioctl]# ./promisc Setting interface ::: eth0 ::: to promisc [root@mip-123456 ioctl]# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:22:68:3C:9C:F0 inet addr:172.24.149.212 Bcast:172.24.149.255 Mask:255.255.255.0 inet6 addr: fe80::222:68ff:fe3c:9cf0/64 Scope:Link UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1 RX packets:3653 errors:0 dropped:0 overruns:0 frame:0 TX packets:6630 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:6255432 (5.9 MiB) TX bytes:2379200 (2.2 MiB) Interrupt:233 Base address:0xa000
其实可以直接ifconfig eth0 promisc 设置混杂
ifconfig eth0 -promisc 取消混杂
ifconfig eth0 -promisc
取消混杂
上一篇:gcc编译器介绍
下一篇:没事看看的cu好帖(不断更新)
登录 注册