summaryrefslogtreecommitdiff
path: root/static/unix-v10/man4/tcp.4
blob: 8831e5cd7bfb18a521bede374a16f87cc8132245 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
.TH TCP 4
.CT comm_mach
.SH NAME
tcp, tcp_ld \- DARPA transmission control protocol
.SH SYNOPSIS
.B #include <sys/inio.h>
.br
.B #include <sys/inet/tcp_user.h>
.SH DESCRIPTION
The
.I tcp_ld
line discipline
and the
.F /dev/tcp*
devices together implement the DARPA TCP circuit protocol.
They are normally used through
.IR tcpmgr (8)
and the routines in
.IR ipc (3).
.PP
One instance of
.I tcp_ld
should be pushed on an IP device stream,
usually
.FR /dev/ip6 ;
see
.IR ip (4).
Thereafter,
data written on the
.I tcp
devices is turned into IP packets
written to the IP device,
and vice versa.
.PP
Different
.I tcp
devices represent different software channels.
Files with odd minor device numbers
are for placing calls;
while such a file is open,
it may not be opened again.
Files with even device numbers
receive calls.
.PP
To place a call,
open an unused odd-numbered
.I tcp
file;
write a
.B struct tcpuser
describing the address to be called;
and read a
.B struct tcpuser
for status.
The structure is defined in
.BR <sys/inet/tcp_user.h> :
.PP
.EX
struct tcpuser {
	int code;
	tcp_port lport, fport;
	in_addr laddr, faddr;
	int param;
};

#define TCPC_LISTEN	1
#define TCPC_CONNECT	2

#define TCPC_OK		3
#define TCPC_SORRY	4	/* unknown error */
#define TCPC_BADDEV	5	/* tcp device is bad */
#define TCPC_NOROUTE	6	/* no routing to dest */
#define TCPC_BADLOCAL	7	/* bad local address */
#define TCPC_BOUND	8	/* address already bound */

#define SO_KEEPALIVE	0x2	/* generate keepalives */
.EE
.PP
In the structure describing the call,
.B code
should be
.BR TCPC_CONNECT ;
.B faddr
and
.B fport
are the destination IP address and TCP port number;
.B laddr
is the IP address associated with a local IP interface,
or
.B INADDR_ANY
to let the system pick;
.B lport
is the local TCP port number,
or
0
to let the system pick;
.B param
is 0 or
.BR SO_KEEPALIVE .
.PP
In the structure returned for status,
.B code
is
.B TCPC_OK
if the call completed correctly;
henceforth data written to and read from the file
is transported on the circuit.
Other codes mean the circuit was not set up.
.PP
To listen for incoming calls,
open an odd-numbered device
and write a
.B struct tcpuser
with
.B code
set to
.BR TCPC_LISTEN ;
.B laddr
set to the local IP address for which calls should be taken,
or
.B INADDR_ANY
to catch any calls not explicitly taken by another listener;
.B lport
set to the port on which to listen,
or 0 for any port;
and
.B param
set to 0.
Thereafter,
reads return successive
.B tcpuser
structures,
each describing a new call;
.B faddr
and
.B fport
identify the caller,
.B laddr
and
.B lport
the assigned local address.
The local
.I tcp
device number,
.I n,
assigned to the call
is returned in
.BR param .
The corresponding device,
.BI /dev/tcp n,
should be opened;
data read and written there is transported by the circuit.
.PP
Several
.IR ioctl (2)
calls, defined in
.BR <sys/inio.h> ,
apply to
.I tcp
devices:
.nr Pw \w'\f5TCPIOMAXSEG 'u
.TP \n(Pwu
.B TCPIOHUP
When the remote end of the circuit is disconnected,
send signal
.B SIGHUP
to the local process group associated with the stream.
.TP
.B TCPMAXSEG
The third argument points to an integer
giving the maximum segment size for this connection:
the greatest number of bytes to be packed into one IP packet.
.TP
.B TCPGETADDR
The third argument points to a
.BR "struct tcpuser" ;
fill in
.BR laddr ,
.BR lport ,
.BR faddr ,
and
.BR fport
with the local and foreign addresses associated with the circuit.
.SH FILES
.F /dev/tcp??
.br
.F /dev/ip6
.SH SEE ALSO
.IR ip (4),
.IR internet (3),
.IR tcpmgr (8)
.br
DARPA standards RFC 793, 1122