read raw packets over network with C#?

172 Views Asked by At

I've got a proprietary BMS language that is sending it's info over a specific UDP port on the network. The existing interface is not very well made or maintained, and functions poorly.

I have access to the stack for the code, and don't mind creating some interpretation functionality

My question is what is the best way that I should be receiving these raw packets in my program to be interpreted? I'm not finding any good documentation on how to do this, and I wanted to try and do it in a reasonably appropriate way.

Do I basically need to make my program constantly sniff a specific port? and will this be cumbersome to the network or program to be doing this?

2

There are 2 best solutions below

0
On

You tagged this BACnet. Why don't you try Wireshark, with a capture filter "udp port 47808" and see if wireshark exposes the packets in a way that makes sense to you. (or have you done this). If it is bacnet, then normal UDP sockets, bound to port 47808 is the way to go. Note, that 47808-47823 are the most common BACnet "default" ports. Use cports or something to see exactly what port(s) your application is bound to.

0
On

You could use a packet-capture library - but that has security connotations, so instead you can probably (for most part) get away with using a .NET 'UdpClient'.

But! The real challenge is the breaking-down & interpretation of the BACnet packets, which is the hard part.

There is (now!/finally) a NuGet package for BACnet - not that I've used it, but that might be one of the best choices for your case.

But I also suggest you experiment with the (advanced & free) VTS (Visual Test Tool) too.

You could also try using the BACnet stack that YABE uses too.