I am looking to x11 forwarding example in libssh2 source (example/x11.c). In the function x11_send_receive I see this code:
rc = select(sock + 1, &set, NULL, NULL, &timeval_out);
if(rc > 0) {
memset((void *)buf, 0, bufsize);
/* Data in sock*/
rc = read(sock, buf, bufsize);
if(rc > 0) {
libssh2_channel_write(channel, buf, rc);
}
else {
free(buf);
return -1;
}
}
I don't understand why the socked is incremented (+ 1) in the select statement. Can someone explain this?
Probably it is related to listening sockets - I see two:
# netstat -lxn | grep /tmp/.X11-unix/X0
unix 2 [ ACC ] STREAM LISTENING 32746 /tmp/.X11-unix/X0
unix 2 [ ACC ] STREAM LISTENING 32745 @/tmp/.X11-unix/X0
sock is connecting to path /tmp/.X11-unix/X0 (without @)... So what is in the background?...