netcat: misleading error message

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

netcat: misleading error message

astian
When a client nc fails to bind a unix datagram socket to a path it
prints an error message but it mentions the remote socket path instead:

  $ rm -f /tmp/srv; nc -vUul /tmp/srv &
  Bound on /tmp/srv
  $ touch /tmp/cli
  $ nc -Uu -s /tmp/cli /tmp/srv
  nc: /tmp/srv: Address already in use

It should say "nc: /tmp/cli: Address already in use".  The message comes
from the "warn" here:

        } else if (family == AF_UNIX) {
                ret = 0;

                if ((s = unix_connect(host)) > 0) {
                        if (!zflag)
                                readwrite(s, NULL);
                        close(s);
                } else {
                        warn("%s", host);
                        ret = 1;
                }

I guess this was done like so because "unix_connect" and "unix_bind"
want to be "library-like" and not print any errors/warnings, although
"unix_bind" already does print a diagnostic if "-v" is given.

As mentioned before, you might have difficulty testing this, see the
email "netcat: veiled filesystem prevents access to remote end
socket".

Cheers.