- 论坛徽章:
- 0
|
linux 设置 网卡混杂模式\r\n\r\nsock=socket(PF_PACKET,SOCK_RAW,htons(ETH_P_ALL));\r\n while(1)\r\n { \r\n n=recvfrom(sock,buffer,2048,0,NULL,NULL);\r\n .......\r\n }\r\n在linux 下 用C语言 实现了 截获 与本机通信的 IP包\r\n\r\n请问 大家 如何 在linux 下 用C语言 设置 网卡 为混杂 模式,谢谢,请详细点\r\n\r\n我在网上找了一些\r\n\r\n45.int Set_Promisc(char *interface, int sock ) { \r\n46. struct ifreq ifr; \r\n47. strncpy(ifr.ifr_name, interface,strnlen(interface)+1);\r\n48. if((ioctl(sock, SIOCGIFFLAGS, &ifr) == -1)) { \r\n/*Could not retrieve flags for the interface*/\r\n49. perror(\"Could not retrive flags for the interface\");\r\n50. exit(0);\r\n51. } \r\n52. printf(\"The interface is ::: %s\\n\", interface); \r\n53. perror(\"Retrieved flags from interface successfully\");\r\n54. ifr.ifr_flags |= IFF_PROMISC; \r\n55. if (ioctl (sock, SIOCSIFFLAGS, &ifr) == -1 ) { \r\n/*Could not set the flags on the interface */ \r\n56. perror(\"Could not set the PROMISC flag:\");\r\n57. exit(0); \r\n58. }\r\n59. printf(\"Setting interface ::: %s ::: to promisc\", interface);\r\n60. return(0);\r\n61. }\r\n\r\n编译的时候 提示 SIOCGIFFLAGS ifreq 没有定义,请问需要包含 哪些 .h 文件?谢谢 |
|