Listening for all incoming packets to a certain network interface using Boost/ASIO - boost-asio

I was looking all over the internet to find a way to capture incoming packets from a certain network interface, then I came across PCAP, TCPDUMP, I believe the most commonly used networking library out there is Boost/Asio, so I wanted to use this library in order to capture traffic, but apparently there is no example for using Raw sockets or other classes to listen for incoming packets to a certain NI, I would appreciate any help or examples on this.

We eventually found out the best option for sniffing incoming packets was Libtins.
libtins is a high-level, multiplatform C++ network packet sniffing and crafting library.
Its main purpose is to provide the C++ developer an easy, efficient,
platform and endianness-independent way to create tools which need to
send, receive and manipulate network packets.
It uses a BSD-2 license and it's hosted at github.

Related

Using ESP-IDF to recieve UDP packets via ethernet

I want to use the ESP-IDF framework to make a program that will recieve UDP packets via ethernet. I am not using an ESP32-Ethernet-Kit, but an ESP32 alongside a PHY (DP83848) in order to gain access to ethernet.
Pretty much every example I can find about UDP and ESP32 is using Wifi instead of ethernet.
What I want to do is use the basic ethernet example available in the espressif esp-idf git repository as a starting point and then add the functionality to recieve the datagrams.
If I'm not wrong, what I should do is create a new event handler and use the esp_eth_update_input_path API present in the esp_eth_driver.h, but I am not sure about how to use it. Can anyone help me with this?
esp_err_t esp_eth_update_input_path(
esp_eth_handle_t hdl,
esp_err_t (*stack_input)(esp_eth_handle_t hdl, uint8_t *buffer, uint32_t length, void *priv),
void *priv);
I posted almost the same question in the espressif ESP-IDF forum before posting this one here and got an following answer by user ESP_ondrej.
I'm posting it here in case this can help someone.
All protocols examples located in the ESP-IDF supports both Wifi and
Ethernet. You just need to configure it via idf.py menuconfig.
Please check the README at https://github.com/espressif/esp-idf/bl ...
/README.md
If you want to start from scratch with your Ethernet UDP application,
you can do so. You don't need to call esp_eth_update_input_path.
This function is used to direct L2 Ethernet frames to specific
callback function which you don't want since you want to communicate
via IP protocol. Therefore keep it as is, i.e. Ethernet frames are to
be processed by lwIP stack and just use socket API as you might be
used to from other platforms.

How to test proprietary network protocol

I have a system I want to test, the system handles a proprietary network protocol (this need to be checked). The tested protocols are over TCP and UDP.
I'm looking for a software I could install on my OS-X/Linux/Windows computer connect it to the system I want to test and inject protocol messages and analyse feedback (software should have the ability to compare for each received message if it is the expected one etc.).
Prefer a software with a nice looking GUI and open-source so I could add features if needed (could be a paid software).
Where should I begin?
There is a probably a library/framework which implements the protocol. My approach would be to use it (or write it when it's missing) to write simply unit tests.
There are many unit testing frameworks with nice GUIs, headless modes and automated tools, so unless you can be more specific, it's hard to suggest something.
With the Argos protocol analyzer (http://xpro.co/index.php/products/argos), you can:
define your proprietary protocol in XML
monitor IP traffic, offload to TCP/UDP endpoints, load proprietary
format text/binary logfiles
visualize the analysis
send commands/messages from command forms, where you can include also
a COM/ActiveX control, which can generate and receive traffic and
implement the logic behind it
Argos runs on Windows and it is a paid software.
Using Load Multiplier (loadmultiplier.com), you can test proprietary protocols. Any text / binary call flows (with / without media) over any transport protocol like (udp / tcp / tls / dtls / sctp / websocket / secured websocket) can be simulated using multiplier.
Disclaimer: I work for load multiplier tool.

WebRTC Relay Server / Broadcast multiple clients

I've got WebRTC peer to peer working but when I want to broadcast a single camera to multiple clients obviously peer to peer isn't suitable.
I've found solutions like
http://lynckia.com
and
http://www.medooze.com/products/mcu/webrtc-support.aspx
But the first I can't get setup (and it seems to have cross browser issues)
the second just feels like we're hitting a nail with a nuclear missile.
All I need is a relay, I don't need to decode / recode streams.
I just need
The Broadcaster to connect to the server (peer to peer)
The clients to connect to the server (peer to peer)
The server to relay the stream from the broadcaster to the clients.
Is there any software out there that offers this solution that I've missed? is there an alternative working and scalable alternative?
Thanks
Jitsi Video Bridge works pretty much exactly how you describe.
On your server you can run Janus, to which your broadcaster can provide a stream via RTP.
Have a look at an example configuration file.
After writing a configuration file which defines how the server receives stream from the broadcaster, you should be able to launch janus in the background via a command line interface tool:
$ janus --daemon --config=config_file.conf
Also, see streaming test demo.
Note: I have not tested this thoroughly.
Have a look at this github-repo inspired from muaz khan's WebRTC p2p scalable broadcast. This can work great on LAN. On internet, I am not sure how well it can work as of now though we are improving it on the go.
If you just want to broadcast from a peer to a set of peers, if they don't care about the latency, the best solution is to covert WebRTC to live streaming, without transcoding just muxing:
Peer(Publisher) ---WebRTC--> Server --RTMP/HLS/DASH--> Peers/Players
If this works good for you, SRS is able to covert WebRTC to live streaming.
Because live streaming allows you to use CDN or TCP to deliver the streams, and the latency is about 3~5s, so this solution is only available when Peers/Players never need to communicate to the Peer(Publisher).
If you want all those peers to talk to each other, it's very complex and need a WebRTC SFU cluster to do this, there will be a huge number of streams. For example, if allows 100 peers to talk to each other, there will be 100x100 = 10k streams.
It's too complicated, so I don't think there is good open-source solution right now(at 2022.02).

iOS client app with Mac server

I am attempting to build a client/server game architecture and would like to begin testing the game using my local Mac as the server. I have found several articles on Bonjour, but that is for local network traffic only. My goal is to make this application work over the Internet, connecting to a hosted application on a static address to facilitate turn data. However, I'm at a loss as to which Cocoa APIs to use for this purpose. Should I use NSConnection, NSStream subclasses, or good 'ol C sockets and whatnot. The game state is already built in Objective-C and is ready to be set in motion once I have the server facilities ready. Any insight?
NSConnection, NSStrean and C sockets are build for different needs. You need to specify the needs of your game and the kind of service in order to get more help. If you want to develop a client-server application that relies on the Internet and not on the local network, Bonjour will not be able to help.
C sockets, and Cocoa APIs that wrap around them are intended to operate on an open network stream between the client and the server. The advantage of having an open stream is that you can have the server send data to the client without the client having requested for it. NSURLConnection in Cocoa works differently. With it, you can perform HTTP requests and receive formatted responses from a server.
If your application is based on HTTP requests, I recommend you take a look an NSURLConnection, or AFNetworking, as a 3rd party alternative. If your application relies on open streams, I recommend you take a look at CFNetwork from Apple (C wrapper around BSD sockets that originates from the days Macs had Carbon, with great performance, stability and versatility) and GCDAsyncSocket, a 3rd party library wrapped around BSD Sockets, supports Crand Central Dispatch, is Objective-C ready, and does the job wonderfully.
I hope I helped.
I suggest you to use sockets, since they're not hard to use and are a standard way. I've even written an asynchronous wrapper class around BSD sockets: https://github.com/H2CO3/TCPHelper
This is for simple, one-to-one TCP protocol connections, supporting both IPv4 and IPv6. You can send and receive raw NSData and possibly build a protocol around it.
Foundation classes such as NSURLConnection are not particularily for this purpose; rather than to interact with standard HTTP servers (I suppose you don't want to implement a full HTTP server for a game).
NSNetServices may suit you just like CFNetwork, but the latter is a bit harder to use. If you'd like to use Foundation classes, I'd recommend NSNetServices.
Hope it helps.
There are many different ways to accomplish this. It really depends on how you'll be passing the data and what it will be used for.
First, I would setup a hostname that you can use for development purposes with your game. You can use anything like http://dyn.com/dns/ to setup this for your Mac. Then you can enable a compiler setting to switch out the development / production URL's.
Next, I would recommend using TCP sockets for your game (using CocoaAsyncSocket - https://github.com/robbiehanson/CocoaAsyncSocket). This method should work fine your your use case. Since you are doing turn-based data (and since all of that data is vital) I would not recommend using UDP sockets (but those would work if you were solely passing position, video, or audio data where a dropped packet might not matter).

How to implement websockets on an embedded device server?

I am working with an electronics appliance manufacturer to embed LAN based control systems into the products. The idea is to serve up a system configuration/control interface through a web browser so clients never need to install software. We can communicate with the appliance by sending and receiving serial data through the embedded module. Since the appliance can also be controlled from a front panel UI, it creates a challenge to keep a remote web interface in sync with very low latency. It seems like websockets or some sort of Push is what we need for handling real time events from the server to clients.
I am using a Lantronix Mathport AR embedded device server. Out of the box the unit will serve up any custom HTML and java servlets/applets. We have the option to install a lightweight Linux distro if we need more flexibility. I am not sure how to implement any server side apps since the device is not running standard Apache. I believe it is using Boa.
Can anyone guide me in the right direction of how to do this?
Some general info...The WebSocket protocol (draft spec here) is a simple layer on top of TCP. What this means is that, if you already have a TCP server for your platform, implementing the WebSocket is just a matter of hours. The protocol specifies a handshake and two ways of sending data frames.
I strongly suggest you start by reading the 39 pages spec.
As Tihauan already mentioned, start by reading the spec, and also note that there are still some changes ongoing, although websockets is now more stable than it was 1 year ago.
Key point for me was the requirement that websocket data is entirely UTF-8 text, which lends itself nicely to JSON based message definitions.
Our system uses a form of embedded linux, so we then added and made use of the following libraries:
"libwebsockets" from:
http://git.warmcat.com/cgi-bin/cgit/libwebsockets/
"jansson" from:
http://www.digip.org/jansson/
Using the above as support libraries, we created an internal lightweight "client/server" that allowed our other software modules to register for certain, applicable, websocket messages, and respond as needed. Worked great.
Good luck and best regards,
I'm a bit late, but Mozilla posted a guide entitled "Writing WebSocket servers", which literally guides you through writing a websocket server.
You will need to already know how HTTP works and have medium programming experience. Depending on language support, knowledge of TCP sockets may be required. The scope of this guide is to present the minimum knowledge you need to write a WebSocket server.
https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers