.\" -*- nroff -*- .ig This file is part of Socket-1.4. Copyright (c) 1992, 1999, 2000, 2001, 2002, 2003, 2005 Juergen Nickelsen . 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: socket.1,v 1.12 2005/11/04 07:10:44 ni Exp $ .. .TH SOCKET 1 "Sep 27. 2000" .SH NAME socket \- create tcp socket and connect to stdin/out .SH SYNOPSIS .B socket [ .B \-bcefnqrvvvw ] [ .B \-a .I bind-address ] [ .B \-p .I command ] [ .B \-T .I timeout ] .I host port .br .B socket [ .B \-bcfnqrRvvvw ] [ .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 "\-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 "\-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 "\-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 "\-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 .BR "\-T " (timeout) The specified .I timeout is applied to the connect(2) and 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 .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 socket (2), .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.4. .SH AUTHOR Juergen Nickelsen