英文:
Network is Down after setting interface to Promiscuous Mode
问题
网络在通过以下方式设置接口为混杂模式后总是断开连接:
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, if_name);
ifr.ifr_flags |= IFF_PROMISC;
ioctl(sock, SIOCSIFFLAGS, &ifr);
路由器是否可能察觉到这个尝试并阻止我的连接?
如果是这样,Wireshark等应用程序是如何保持运行的呢?有没有办法隐藏这种模式?
英文:
Network always goes down after setting interface to promiscuous mode via:
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, if_name);
ifr.ifr_flags |= IFF_PROMISC;
ioctl(sock, SIOCSIFFLAGS, &ifr);
Is it possible that the router knows about this attempt and it blocks my connection?
If so, how is it that applications like Wireshark stay on? Is there a way to hide this mode?
答案1
得分: 4
你的代码不仅设置了IFF_PROMISC标志,还清除了所有其他标志,比如IFF_UP,这会使接口变为下线状态。因此,你的代码导致接口下线。
如果你只想改变一个标志,你可以使用SIOCGIFFLAGS
(G代表获取)来获取旧的标志,然后编辑你想要的标志并设置它们。
英文:
Your code doesn't just set the IFF_PROMISC flag - it also clears all other flags, such as IFF_UP which makes the interface up. Therefore, your code makes the interface go down.
If you only want to change one flag, you can use SIOCGIFFLAGS
(G for Get) to get the old flags, then edit the one flag you want and set them.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论