sctp: Avoid using file descriptor 0 to get ENOTSOCK

On some systems, errno will not be ENOTSOCK when operating on file descriptor
0 in an ssh session:

test_1_to_1_accept_close.c    2  TBROK  :  accept with invalid socketerror:-1, errno:22
test_1_to_1_addrs.c    2  TBROK  :  sctp_getladdrs with invalid socket error:-1, errno:95
test_1_to_1_connect.c    2  TBROK  :  connect with invalid socket error:-1, errno:22
test_1_to_1_recvfrom.c    2  TBROK  :  recvfrom with invalid socket count:0, errno:9
test_1_to_1_recvmsg.c    2  TBROK  :  recvmsg with invalid socket count:0, errno:9
test_1_to_1_send.c    2  TBROK  :  send with invalid socket count:15, errno:9
test_1_to_1_sendmsg.c    2  TBROK  :  sendmsg with invalid socket count:-1, errno:106
test_1_to_1_shutdown.c    2  TBROK  :  shutdown with an invalid socket error:0, errno:9
test_1_to_1_socket_bind_listen.c    6  TBROK  :  bind() with invalid socket descriptor error:-1, errno:22
test_1_to_1_sockopt.c    2  TBROK  :  setsockopt with an invalid socket error:-1, errno:95
test_getname.c    9  TBROK  :  getsockname on an invalid socket error:0 errno:9

This patch gets a non-socket file descriptor by creating a temporary file
to replace file descriptor 0.

https://github.com/borkmann/lksctp-tools/commit/c43ead6daa0b9ae5763d6cf3d21357a789651417

Signed-off-by: Simon Xu <xu.simon@oracle.com>
Acked-by: Cyril Hrubis <chrubis@suse.cz>
Acked-by: Jan Stancek <jstancek@redhat.com>
11 files changed