网络在将接口设置为混杂模式后中断。

huangapple go评论64阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年3月9日 21:51:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75685532.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定