4

I have an IPv4-only UDP application listening on port 624. I created an IPv6/IPv4 front-end with socat, listening on port 625. I can now use the server's IPv4 or IPv6 address to access the IPv4-only app. Cool, so far!

socat UDP6-LISTEN:625,fork,su=nobody UDP4:localhost:624 &

After sending just one UDP message, IPv4 in the example below, I see two new long-lived processes created, one for each side of the gateway..

# lsof -i:624 -i:625 -n -P -i:625
COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
myap     4296   root    4u  IPv4   7845     0t64  UDP *:624
socat   28597 nobody    3u  IPv6  67603     0t64  UDP 192.168.93.90:625->192.168.90.121:34091
socat   28597 nobody    4u  IPv4  67882     0t64  UDP 127.0.0.1:53648->127.0.0.1:624

As you can imagine, for a busy server, the number of long-lived processes grows quickly.

How can I use socat to provide the gateway feature and have it cleanup these long-lived UDP processes?

1 Answers1

3

I found what I need from the socat man page...

The answer is to set a timeout for UDP-based communication.

-T<timeout> Total inactivity timeout: when socat is already in the transfer loop and nothing has happened for <timeout> [timeval] seconds (no data arrived, no interrupt occurred...) then it terminates. Useful with protocols like UDP that cannot transfer EOF.

So the command-line ought to become (for a 5 second timeout):

socat -T5 UDP6-LISTEN:625,fork,su=nobody UDP4:localhost:624 &

Matt.