In one of my projects I needed to activate TCP keepalive for some sockets. Unfortunately those sockets were handled by a library and I didn’t want to compile everything just to get this feature.
Searching the web I found this small piece of code and here is the Debian package now. Maybe someone else might find it useful as well.