]> mj.ucw.cz Git - sock.git/blob - sock.1
Use socklen_t for accept()
[sock.git] / sock.1
1 .TH sock 1 "12 June 2001" "sock-1.1" "UCW Utilities"
2 .IX sock
3 .SH NAME
4 sock \- simple socket interface for shell scripts
5 .SH SYNOPSIS
6 .B sock
7 [-dentuvx] ([-b <local>] <remote> | -l <local>) [<command>]
8 .SH DESCRIPTION
9 .B sock
10 is a simple program serving as an interface between its standard input/output
11 streams and sockets, primarily intended to be used in shell scripts, but often
12 useful interactively from the command line as well.
13
14 .B sock
15 supports two modes: listening mode and originating mode. In the listening mode
16 (requested by the
17 .B -l
18 option),
19 .B sock
20 acts as an server and accepts incoming connections for the network address
21 specified as
22 .B <local>
23 (see below for how to write addresses). In the originating mode, you specify
24 an address
25 .RB ( <remote> )
26 to connect to and maybe also the local address
27 (\fB-b <local>\fR)
28 to bind the local end to.
29
30 By default,
31 .B sock
32 just copies its standard input to the socket and all data received from the socket
33 to its standard output. If you want, you can specify a
34 .B <command>
35 to be spawned and the socket redirected to its standard input/output instead
36 (in the listening mode, you can use
37 .B -d
38 to wait for multiple connections and spawn the command for each of them
39 instead of exiting after serving a single incoming connection).
40
41 .SH ADDRESSES
42 .B sock
43 currently supports two address families: IP and UNIX.
44
45 For
46 .B UNIX
47 domain sockets, just use a socket file name as an address.
48
49 For
50 .B IP (TCP/UDP)
51 sockets, addresses look like [\fB<host>\fR][\fB:<port>\fR], where
52 \fB<host>\fR is a host name and \fB<port>\fR is a port number or
53 a service name. In case you don't specify whether you want to use TCP
54 or UDP, sock uses the protocol associated with the specified service
55 or falls back to TCP if both are possible. If the host name is omitted,
56 "any" (for binding or listening) or "localhost" (for connecting)
57 is assumed.
58
59 .SH OPTIONS
60 .TP
61 .B -d
62 Run as a daemon and run the
63 .B <command>
64 for each incoming connection instead of exiting after having served
65 a single connection.
66 .TP
67 .B -e
68 Terminate after receiving first EOF in any direction. Default behaviour
69 is to wait for EOF in both directions. Please note that this has changed
70 since version 1.0.
71 .TP
72 .B -n
73 Avoid reverse DNS lookups in verbose mode.
74 .TP
75 .B -t
76 Open a TCP socket.
77 .TP
78 .B -u
79 Open a UDP socket.
80 .TP
81 .B -v
82 Be verbose. The more -v's you give, the more verbose sock is.
83 .TP
84 .B -x
85 Open a UNIX socket.
86
87 .SH EXAMPLES
88 Use `sock :smtp' to talk with local mailer.
89
90 Use `echo -e "HELO `hostname -f`\\nETRN `hostname -f`" | sock mail.server.name:smtp' to tell
91 your mail-exchanger it should start sending all messages queued for you.
92
93 Use `sock -dl :7777 fortune' to establish a simple fortune cookie server.
94
95 Use `sock -e :7777' as a client for the above server.
96
97 .SH AUTHOR
98 .B sock
99 has been written and is (at least sometimes) maintained by Martin Mares <mj@ucw.cz>.