.\" -*- nroff -*- .ig This file is part of Socket-1.5. Copyright (c) 1992 - 2018 Juergen Nickelsen and Boris Nikolaus. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $Id$ .. .TH SOCKET 1 "Apr 08. 2007" .SH NAME socket \- create tcp socket and connect to stdin/out .SH SYNOPSIS .B socket [ .B \-bcefhHnqQrvvw46 ] [ .B \-a .I bind-address ] [ .B \-p .I command ] [ .B \-T .I timeout ] .I host port .br .B socket [ .B \-46bcefhHlnqQrRvvw ] [ .B \-a .I bind-address ] [ .B \-p .I command ] [ .B \-T .I timeout ] .B \-s [ .B \-l ] .I port .SH DESCRIPTION .B Socket creates an Internet domain TCP socket and connects it to stdin and stdout. The .I host argument can be an Internet number in dot-notation (like ``130.149.28.10'') or a domain name. In this case it must be possible to resolve the name to a valid Internet address with .IR gethostbyname (3). The .I port argument can be a port number or a service name which can be mapped to a port number by .IR getservbyname (3). .SH OPTIONS .TP .BI "\-a " bind-address Bind the socket to the specified .I bind-address instead of the default address (in client mode) or all addresses of the host (in server mode). This may lead to a connection failure in client mode if there is no route from the .I bind-address to the destination address. .TP .BR "\-4 " (IPv4) Only use IP protocol version 4. (Default: Support both IPv4 and IPv6 if IPv6 support has been compiled in). .TP .BR "\-6 " (IPv6) Only use IP protocol version 6 (if support has been compiled in). (Default: Support both IPv4 and IPv6 if IPv6 support has been compiled in). .TP .BR "\-b " (background) The program forks itself into the background, detaches from its controlling tty, closes the file descriptors associated with the tty, and changes its current directory to the root directory. .TP .BR "\-c " (crlf) Linefeed characters (LF) are converted to a Carriage Return Linefeed sequence (CRLF) when written to the socket. CRLF sequences read from the socket are converted to a single LF. .TP .BR "\-e " "(no stderr capture)" With -p: stderr from the called program is not redirected to the socket, but sent to the Socket program's original stderr. .TP .BR "\-f " (fork) When a server connection has been accepted, a separate process is forked to handle the connection in background. .TP .BR "\-h " (help) Display the usage of the program. .TP .BR "\-H " (half-close) Enable half-close support. This allows to close both directions of the connection separately by sending an end-of-file indicator for each direction. The connection is assumed alive until both directions have been closed. .TP .BR "\-l " (loop) (only valid with .BR \-s ) After a connection has been closed, another connection is accepted. .TP .BR "\-n " "(no reverse lookup)" Don't do reverse lookup of peer addresses. .TP .BR "\-p " (program) The specified .I command is executed for each connection. Its standard input, standard output, and standard error channels are connected to the socket. The environment variables SOCKET_LOCAL_ADDRESS and SOCKET_LOCAL_PORT are set to the socket's local IP address and port number; the environment variables SOCKET_PEER_ADDRESS and SOCKET_PEER_PORT are correspondingly set to IP address and port number of the socket on the peer's side. .I Command can be any shell command since it is passed to \fC/bin/sh\fP for execution. .TP .BR "\-q " (quit) The connection is closed when an end-of-file condition occurs on standard input. .TP .BR "\-Q " "(reset on ungraceful quit)" When the program is terminated by SIGINT or SIGTERM or if reading from stdin or writing to stdout fails, the connection is closed ungracefully by sending a TCP RESET instead of TCP FIN. This allows to detect the abortion at the remote side where .IR read (2) returns a "Connection reset by peer" error. .TP .BR "\-r " "(read only)" No data is read from standard input and written to the socket. .TP .BR "\-R " "(no REUSEADDR)" Don't set the socket option SO_REUSEADDR. .TP .BR "\-s " (server) A server socket is created. A .I hostname argument is not required. .TP .BR "\-T " (timeout) The specified .I timeout (in seconds) is applied to the .IR connect (2) and .IR select (2) system calls, such that the program is terminated when that timeout expires on connection setup or when reading from the socket or standard input. .TP .BR "\-v " (verbose) Each ``v'' in the options increases the verbosity level by one. Currently supported are .BR 1 : print information about connections, and .BR 2 : additionally print information about name resolution and connection attempts. .TP .BR "\-w " "(write only)" No data is read from the socket and written to the standard output. .TP .B \-version .B Socket prints its version ID and terminates. This must be the first argument to have an effect. .SH EXAMPLES The command .IP \fCsocket -v coma.cs.tu-berlin.de nntp\fP .LP connects to the nntp port (port 119) of coma.cs.tu-berlin.de (130.149.28.10). .br The command .IP \fCsocket \-sl 3425\fP .LP creates a server socket on port 3425 on the local host and waits for a connection. After a connection has been closed, a new connection is accepted. .br The command .IP \fCsocket \-wslqvp "echo Socket! " 1938\fP .LP creates a server socket on port 1938 on the local host and waits for a connection. When a connection is accepted, the string "Socket!" is written to the socket. No data is read from the socket and written to the \fCfinger\fP program. The connection is closed when an end-of-file condition at the standard output of the program occurs. Then a new connection is accepted. .SH DIAGNOSTICS Lots of diagnostics for failed system calls. .TP .BI "unknown host " host .IR host 's address could not be resolved. .B socket terminates due to an error condition. .SH SEE ALSO .BR accept (2), .BR bind (2), .BR connect (2), .BR listen (2), .BR socket (2), .BR getaddrinfo (3), .BR gethostbyname (3), .BR getservbyname (3) .SH BUGS The version 2 release is overdue. .LP \fCsocket \-p\fP terminates due to a SIGPIPE signal if there is more data from the socket available than the child process wants to read. .LP Please report any other bugs to the author. .SH VERSION This manual page describes Socket\-1.5. .SH AUTHOR Juergen Nickelsen .br Boris Nikolaus made some significant changes in version 1.5, most notably for IPv6.