开发者

Snooping in on IGMP traffic

开发者 https://www.devze.com 2023-04-12 17:16 出处:网络
I built a library for doing IGMP stuff. Now, the silly thing is, my library also does presence monitoring to make sure others ar开发者_JS百科e still part of the group.

I built a library for doing IGMP stuff. Now, the silly thing is, my library also does presence monitoring to make sure others ar开发者_JS百科e still part of the group.

IGMP does exactly the same thing at a lower level. Parting messages, polling to the router that it's still part of the same group, the whole thing. I've just repeated all the same work, and it's likely not as robust.

I can make everything a lot cleaner (and I wouldn't be reinventing the wheel) if I could tap into those packets.

Anyone have any experience doing this? Maybe create some sort of crazy socket? I don't want to use libpcap for it. I don't think the language matters, as long as it's possible using Sockets on Windows/Linux


Alright, found a way. It's super dirty right now since I have to extract the information I need by hand, but this is in essence how you pull IGMP data on an interface (note that you need to have administrator privileges to pull raw data):

var buffer = new byte[65536];
var s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Igmp); // filter out non IGMP
byte[] one = BitConverter.GetBytes(1);
s.Bind(new IPEndPoint(IPAddress.Parse("192.168.1.148"), 0)); // Which interface to listen on
s.IOControl(IOControlCode.ReceiveAll, one, one); // enter promiscuous mode
s.Recieve(buffer); // get yourself some data (BeginRecieve didn't seem to work here)

then do something with said buffer. If you poke in wireshark you can see the packet breakdown

0

精彩评论

暂无评论...
验证码 换一张
取 消