recv(0, ...) seems to work the way you have described, although it is
- very counter-intuitive,
- does not match the goal of programs like rsh/ssh to make the intermediate socket connection transparent to both client and server program, and also
- introduces an unwanted dependency on the origin of a program's input (i.e., there must be a socket connection bound to its standard input).
Therefore I would never recommend using it. Even after adding complete socket support to xboard/WinBoard or other GUIs, an engine using recv() this way will no longer run with older GUI versions, or GUIs that do not support it. It is a basic change that can break a lot.
Indeed I meant the first argument of recv() when asking about the "socket parameter", no other parameter is a socket. The last parameter is "flags". When I looked into various versions of rshd.c I did not find any dup() or dup2() call that does what you wrote. That was one of the reasons why I did not believe it. Either I missed it, or rshd uses some internal trick instead of dup2(). I did not look into the sshd source, though.bob wrote:What "socket parameter" are you talking about? The first argument? zero (descriptor zero, which is stdin).
And I missed the non-obvious "0" as first argument to recv(), I thought it had to be a file descriptor that was the result of a socket() function call at some early time, and would therefore have a value > 2 that would be unknown in the general case.
So the essential code that would have to be present in the child process init part of the daemon would be like this:
Code: Select all
close(0);
dup2(socket, 0);
close(socket);
Sven