https://github.com/fleny113/udp-forwarder
A very use-case specific tool to forward UDP packets
https://github.com/fleny113/udp-forwarder
Last synced: 20 days ago
JSON representation
A very use-case specific tool to forward UDP packets
- Host: GitHub
- URL: https://github.com/fleny113/udp-forwarder
- Owner: Fleny113
- License: mit
- Created: 2024-08-21T13:49:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-01-25T21:08:30.000Z (about 2 months ago)
- Last Synced: 2026-01-25T22:48:03.822Z (about 2 months ago)
- Language: C
- Homepage:
- Size: 45.9 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# UDP Forwarder
UDP Forwarder is a small program to forward `UDP` packets around.
This is useful to forward `UDP` packets in `NAT`-ed environments where you can't port-forward properly or you don't have access to the router configuration.
This has been built for a very specific use-case however you might be able to use it as well.
## Compilation
There aren't pre-built binaries. You will need a C17 compiler to build it.
There is a makefile, you can `make server` and `make client` to build respectively the server and the client binaries.
### Debug mode
You can compile in debug mode by using `DEBUG=1 make server` or `DEBUG=1 make client`. This will enable additional logging to help debugging issues.
## Usage
Client usage:
```
./client
```
Server usage:
```
./server
```
### Server
The server will listen to both ports, when it receives a message on the `incoming port` it will send a packet to the `forward port` with the content of the received message, and vice-versa.
Until a [client](#client) advertizes itself with the password the server will drop all packets.
### Client
The client will connect to the server at `:` and advertize itself by sending the `` string.
Then when the client receives packets from the server with the source ip and port for the client it will open a connection to `:` and forward the packets there, and vice-versa.
This allows to have multiple clients connecting to the same server and forwarding packets to different destinations.
## Why not using `socat`
`socat` is a very powerful tool however I have found it to not being able to do what UDP Forwarder does, especially for the client binary. For this reason this tool exists.
## Example use-case (Factorio)
[Factorio](https://factorio.com) uses `UDP` for its multiplayer server, however when the server is in a `NAT`-ed environment and you want to play with friend that is an issue.
Tradizionally you would use something like a VPS and an `SSH` tunnel to expose the local port and that works great. However, `SSH` does not support `UDP`, only `TCP`
and factorio doesn't seem to enjoing having its packet being converted from `UDP` to `TCP` and then from `TCP` to `UDP` again.
To solve this you can run UDP Forwarder server on the VPS, with a cmdline such as: `./server `.
After you run the command UDP Forwarder will listen to those 2 ports as explained in the server explaination above.
Then on the same server that is running the Factorio server you can run UDP Forwarder client, with a cmdline such as: `./client 127.0.0.1 `.
After that the client will connect to the UDP Forwarder server running on the VPS and advertize itself, as described in the client explaination above.
After both server and client are running, when a Factorio client opens a connection with the VPS on the port you decided
the UDP Forwarder server on the VPS will send the packets to the UDP Forwarder client running on the server running the Factorio server and then it will send the data to Factorio to handle the connection.
Since this opens a new socket for each different ip + port combination that the server receives, you can have multiple players with a single client and server.
## License
The code is publish under the MIT licence.