I have two processes that are run by the same user, but neither is related to the other (in the parent/child sense). The server creates a socket, and the client opens a connection using its port number. This works great, however it would be better if there were a way to make this port local/private. No other computer needs to connect to my server, so it would be nice to protect it from remote port scans. Also, if the port weren’t opened up to the outside world, I could potentially avoid bumping into the OS’s firewall.
It looks like PF_UNIX might let me create a filename-type socket that works in this way, but is there a way to do it with a port-type (PF_INET) interface?
Yes, by using the loopback interface (127.0.0.1, localhost etc.) – processes on your system can all see it but nothing outside can.
Edit: To be specific, the whole 127.0.0.1/8 block is reserved for loopback, so 127.0.0.[1-254] will work.