xref: /illumos-gate/usr/src/man/man4p/tcp.4p (revision 6446bd46ed1b4e9f69da153665f82181ccaedad5)
1'\"
2.\" This file and its contents are supplied under the terms of the
3.\" Common Development and Distribution License ("CDDL"), version 1.0.
4.\" You may only use this file in accordance with the terms of version
5.\" 1.0 of the CDDL.
6.\"
7.\" A full copy of the text of the CDDL should have accompanied this
8.\" source.  A copy of the CDDL is also available via the Internet at
9.\" http://www.illumos.org/license/CDDL.
10.\"
11.\"
12.\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
13.\" Copyright (c) 2011 Nexenta Systems, Inc. All rights reserved.
14.\" Copyright 2019 Joyent, Inc.
15.\" Copyright 2022 Oxide Computer Company
16.\" Copyright 1989 AT&T
17.\"
18.Dd "Jan 07, 2019"
19.Dt TCP 4P
20.Os
21.Sh NAME
22.Nm tcp ,
23.Nm TCP
24.Nd Internet Transmission Control Protocol
25.Sh SYNOPSIS
26.In sys/socket.h
27.In netinet/in.h
28.In netinet/tcp.h
29.Bd -literal
30s = socket(AF_INET, SOCK_STREAM, 0);
31s = socket(AF_INET6, SOCK_STREAM, 0);
32t = t_open("/dev/tcp", O_RDWR);
33t = t_open("/dev/tcp6", O_RDWR);
34.Ed
35.Sh DESCRIPTION
36TCP is the virtual circuit protocol of the Internet protocol family.
37It provides reliable, flow-controlled, in-order, two-way transmission of data.
38It is a byte-stream protocol layered above the Internet Protocol
39.Po Sy IP Pc ,
40or the Internet Protocol Version 6
41.Po Sy IPv6 Pc ,
42the Internet protocol family's
43internetwork datagram delivery protocol.
44.Pp
45Programs can access TCP using the socket interface as a
46.Dv SOCK_STREAM
47socket type, or using the Transport Level Interface
48.Po Sy TLI Pc
49where it supports the connection-oriented
50.Po Dv BT_COTS_ORD Pc
51service type.
52.Pp
53A checksum over all data helps TCP provide reliable communication.
54Using a window-based flow control mechanism that makes use of positive
55acknowledgements, sequence numbers, and a retransmission strategy, TCP can
56usually recover when datagrams are damaged, delayed, duplicated or delivered
57out of order by the underlying medium.
58.Pp
59TCP provides several socket options, defined in
60.In netinet/tcp.h
61and described throughout this document,
62which may be set using
63.Xr setsockopt 3SOCKET
64and read using
65.Xr getsockopt 3SOCKET .
66The
67.Fa level
68argument for these calls is the protocol number for TCP, available from
69.Xr getprotobyname 3SOCKET .
70IP level options may also be used with TCP.
71See
72.Xr ip 4P
73and
74.Xr ip6 4P .
75.Ss "Listening And Connecting"
76TCP uses IP's host-level addressing and adds its own per-host
77collection of
78.Dq port addresses .
79The endpoints of a TCP connection are
80identified by the combination of an IPv4 or IPv6 address and a TCP
81port number.
82Although other protocols, such as the User Datagram Protocol
83.Po Sy UDP Pc ,
84may use the same host and port address format, the port space of these
85protocols is distinct.
86See
87.Xr inet 4P
88and
89.Xr inet6 4P
90for details on
91the common aspects of addressing in the Internet protocol family.
92.Pp
93Sockets utilizing TCP are either
94.Dq active
95or
96.Dq passive .
97Active sockets
98initiate connections to passive sockets.
99Passive sockets must have their local IPv4 or IPv6 address and TCP port number
100bound with the
101.Xr bind 3SOCKET
102system call after the socket is created.
103If an active socket has not been bound by the time
104.Xr connect 3SOCKET
105is called, then the operating system will choose a local address and port for
106the application.
107By default, TCP sockets are active.
108A passive socket is created by calling the
109.Xr listen 3SOCKET
110system call after binding, which establishes a queueing parameter for the
111passive socket.
112Connections to the passive socket can then be received using the
113.Xr accept 3SOCKET
114system call.
115Active sockets use the
116.Xr connect 3SOCKET
117call after binding to initiate connections.
118.Pp
119If incoming connection requests include an IP source route option, then the
120reverse source route will be used when responding.
121.Pp
122By using the special value
123.Dv INADDR_ANY
124with IPv4, or the unspecified
125address (all zeroes) with IPv6, the local IP address can be left
126unspecified in the
127.Fn bind
128call by either active or passive TCP
129sockets.
130This feature is usually used if the local address is either unknown or
131irrelevant.
132If left unspecified, the local IP address will be bound at connection time to
133the address of the network interface used to service the connection.
134For passive sockets, this is the destination address used by the connecting
135peer.
136For active sockets, this is usually an address on the same subnet as the
137destination or default gateway address, although the rules can be more complex.
138See
139.Sy "Source Address Selection"
140in
141.Xr inet6 4P
142for a detailed discussion of how this works in IPv6.
143.Pp
144Note that no two TCP sockets can be bound to the same port unless the bound IP
145addresses are different.
146IPv4
147.Dv INADDR_ANY
148and IPv6 unspecified addresses compare as equal to any IPv4 or IPv6 address.
149For example, if a socket is bound to
150.Dv INADDR_ANY
151or the unspecified address and port
152.Em N ,
153no other socket can bind to port
154.Em N ,
155regardless of the binding address.
156This special consideration of
157.Dv INADDR_ANY
158and the unspecified address can be changed using the socket option
159.Dv SO_REUSEADDR .
160If
161.Dv SO_REUSEADDR
162is set on a socket doing a bind, IPv4
163.Dv INADDR_ANY
164and the IPv6 unspecified address do not compare as equal to any IP address.
165This means that as long as the two sockets are not both bound to
166.Dv INADDR_ANY ,
167the unspecified address, or the same IP address, then the two sockets can be
168bound to the same port.
169.Pp
170If an application does not want to allow another socket using the
171.Dv SO_REUSEADDR
172option to bind to a port its socket is bound to, the
173application can set the socket-level
174.Po Dv SOL_SOCKET Pc
175option
176.Dv SO_EXCLBIND
177on a socket.
178The
179option values of 0 and 1 mean enabling and disabling the option respectively.
180Once this option is enabled on a socket, no other socket can be bound to the
181same port.
182.Ss "Sending And Receiving Data"
183Once a connection has been established, data can be exchanged using the
184.Xr read 2
185and
186.Xr write 2
187system calls.
188If, after sending data, the local TCP receives no acknowledgements from its
189peer for a period of time (for example, if the remote machine crashes), the
190connection is closed and an error is returned.
191.Pp
192When a peer is sending data, it will only send up to the advertised
193.Dq receive window ,
194which is determined by how much more data the recipient can fit in its buffer.
195Applications can use the socket-level option
196.Dv SO_RCVBUF
197to increase or decrease the receive buffer size.
198Similarly, the socket-level option
199.Dv SO_SNDBUF
200can be used to allow TCP to buffer more unacknowledged and unsent data locally.
201.Pp
202Under most circumstances, TCP will send data when it is written by the
203application.
204When outstanding data has not yet been acknowledged, though, TCP will gather
205small amounts of output to be sent as a single packet once an acknowledgement
206has been received.
207Usually referred to as Nagle's Algorithm (RFC 896), this behavior helps prevent
208flooding the network with many small packets.
209.Pp
210However, for some highly interactive clients (such as remote shells or
211windowing systems that send a stream of keypresses or mouse events), this
212batching may cause significant delays.
213To disable this behavior, TCP provides a boolean socket option,
214.Dv TCP_NODELAY .
215.Pp
216Conversely, for other applications, it may be desirable for TCP not to send out
217any data until a full TCP segment can be sent.
218To enable this behavior, an application can use the TCP-level socket option
219.Dv TCP_CORK .
220When set to a non-zero value, TCP will only send out a full TCP segment.
221When
222.Dv TCP_CORK
223is set to zero after it has been enabled, all currently buffered data is sent
224out (as permitted by the peer's receive window and the current congestion
225window).
226.Pp
227Still other latency-sensitive applications rely on receiving a quick
228notification that their packets have been successfully received.
229To satisfy the requirements of those applications, setting the
230.Dv TCP_QUICKACK
231option to a non-zero value will instruct the TCP stack to send an acknowlegment
232immediately upon receipt of a packet, rather than waiting to acknowledge
233multiple packets at once.
234.Pp
235TCP provides an urgent data mechanism, which may be invoked using the
236out-of-band provisions of
237.Xr send 3SOCKET .
238The caller may mark one byte as
239.Dq urgent
240with the
241.Dv MSG_OOB
242flag to
243.Xr send 3SOCKET .
244This sets an
245.Dq urgent pointer
246pointing to this byte in the TCP stream.
247The receiver on the other side of the stream is notified of the urgent data by a
248.Dv SIGURG
249signal.
250The
251.Dv SIOCATMARK
252.Xr ioctl 2
253request returns a value indicating whether the stream is at the urgent mark.
254Because the system never returns data across the urgent mark in a single
255.Xr read 2
256call, it is possible to
257advance to the urgent data in a simple loop which reads data, testing the
258socket with the
259.Dv SIOCATMARK
260.Fn ioctl
261request, until it reaches the mark.
262.Ss "Congestion Control"
263TCP follows the congestion control algorithm described in RFC 2581, and
264also supports the initial congestion window (cwnd) changes in RFC 3390.
265The initial cwnd calculation can be overridden by the socket option
266.Dv TCP_INIT_CWND .
267An application can use this option to set the initial cwnd to a
268specified number of TCP segments.
269This applies to the cases when the connection
270first starts and restarts after an idle period.
271The process must have the
272.Dv PRIV_SYS_NET_CONFIG
273privilege if it wants to specify a number greater than that
274calculated by RFC 3390.
275.Pp
276The operating system also provides alternative algorithms that may be more
277appropriate for your application, including the CUBIC congestion control
278algorithm described in RFC 8312.
279These can be configured system-wide using
280.Xr ipadm 8 ,
281or on a per-connection basis with the TCP-level socket option
282.Dv TCP_CONGESTION ,
283whose argument is the name of the algorithm to use
284.Pq for example Dq cubic .
285If the requested algorithm does not exist, then
286.Fn setsockopt
287will fail, and
288.Va errno
289will be set to
290.Er ENOENT .
291.Ss "TCP Keep-Alive"
292Since TCP determines whether a remote peer is no longer reachable by timing out
293waiting for acknowledgements, a host that never sends any new data may never
294notice a peer that has gone away.
295While consumers can avoid this problem by sending their own periodic heartbeat
296messages (Transport Layer Security does this, for example),
297TCP describes an optional keep-alive mechanism in RFC 1122.
298Applications can enable it using the socket-level option
299.Dv SO_KEEPALIVE .
300When enabled, the first keep-alive probe is sent out after a TCP connection is
301idle for two hours.
302If the peer does not respond to the probe within eight minutes, the TCP
303connection is aborted.
304An application can alter the probe behavior using the following TCP-level
305socket options:
306.Bl -tag -offset indent -width 16m
307.It Dv TCP_KEEPALIVE_THRESHOLD
308Determines the interval for sending the first probe.
309The option value is specified as an unsigned integer in milliseconds.
310The system default is controlled by the TCP
311.Nm ndd
312parameter
313.Cm tcp_keepalive_interval .
314The minimum value is ten seconds.
315The maximum is ten days, while the default is two hours.
316.It Dv TCP_KEEPALIVE_ABORT_THRESHOLD
317If TCP does not receive a response to the probe, then this option determines
318how long to wait before aborting a TCP connection.
319The option value is an unsigned integer in milliseconds.
320The value zero indicates that TCP should never time
321out and abort the connection when probing.
322The system default is controlled by the TCP
323.Nm ndd
324parameter
325.Sy tcp_keepalive_abort_interval .
326The default is eight minutes.
327.It Dv TCP_KEEPIDLE
328This option, like
329.Dv TCP_KEEPALIVE_THRESHOLD ,
330determines the interval for sending the first probe, except that
331the option value is an unsigned integer in
332.Sy seconds .
333It is provided primarily for compatibility with other Unix flavors.
334.It Dv TCP_KEEPCNT
335This option specifies the number of keep-alive probes that should be sent
336without any response from the peer before aborting the connection.
337.It Dv TCP_KEEPINTVL
338This option specifies the interval in seconds between successive,
339unacknowledged keep-alive probes.
340.El
341.Ss "Additional Configuration"
342illumos supports TCP Extensions for High Performance (RFC 7323)
343which includes the window scale and timestamp options, and Protection Against
344Wrap Around Sequence Numbers
345.Po Sy PAWS Pc .
346Note that if timestamps are negotiated on
347a connection, received segments without timestamps on that connection are
348silently dropped per the suggestion in the RFC. illumos also supports Selective
349Acknowledgment
350.Po Sy SACK Pc
351capabilities (RFC 2018) and Explicit Congestion
352Notification
353.Po Sy ECN Pc
354mechanism (RFC 3168).
355.Pp
356Turn on the window scale option in one of the following ways:
357.Bl -bullet -offset indent -width 4m
358.It
359An application can set
360.Dv SO_SNDBUF
361or
362.Dv SO_RCVBUF
363size in the
364.Fn setsockopt
365option to be larger than 64K.
366This must be done
367.Em before
368the program calls
369.Fn listen
370or
371.Fn connect ,
372because the window scale
373option is negotiated when the connection is established.
374Once the connection
375has been made, it is too late to increase the send or receive window beyond the
376default TCP limit of 64K.
377.It
378For all applications, use
379.Xr ndd 8
380to modify the configuration parameter
381.Cm tcp_wscale_always .
382If
383.Cm tcp_wscale_always
384is set to
385.Sy 1 ,
386the
387window scale option will always be set when connecting to a remote system.
388If
389.Cm tcp_wscale_always
390is
391.Sy 0 ,
392the window scale option will be set only if
393the user has requested a send or receive window larger than 64K.
394The default value of
395.Cm tcp_wscale_always
396is
397.Sy 1 .
398.It
399Regardless of the value of
400.Cm tcp_wscale_always ,
401the window scale option
402will always be included in a connect acknowledgement if the connecting system
403has used the option.
404.El
405.Pp
406Turn on SACK capabilities in the following way:
407.Bl -bullet -offset indent -width 4m
408.It
409Use
410.Nm ndd
411to modify the configuration parameter
412.Cm tcp_sack_permitted .
413If
414.Cm tcp_sack_permitted
415is set to
416.Sy 0 ,
417TCP will not accept SACK or send out SACK information.
418If
419.Cm tcp_sack_permitted
420is
421set to
422.Sy 1 ,
423TCP will not initiate a connection with SACK permitted option in the
424.Sy SYN
425segment, but will respond with SACK permitted option in the
426.Sy SYN|ACK
427segment if an incoming connection request has the SACK permitted option.
428This means that TCP will only accept SACK information if the other side of the
429connection also accepts SACK information.
430If
431.Cm tcp_sack_permitted
432is set to
433.Sy 2 ,
434it will both initiate and accept connections with SACK information.
435The default for
436.Cm tcp_sack_permitted
437is
438.Sy 2
439.Pq active enabled .
440.El
441.Pp
442Turn on the TCP ECN mechanism in the following way:
443.Bl -bullet -offset indent -width 4m
444.It
445Use
446.Nm ndd
447to modify the configuration parameter
448.Cm tcp_ecn_permitted .
449If
450.Cm tcp_ecn_permitted
451is set to
452.Sy 0 ,
453then TCP will not negotiate with a peer that supports ECN mechanism.
454If
455.Cm tcp_ecn_permitted
456is set to
457.Sy 1
458when initiating a connection, TCP will not tell a peer that it supports
459.Sy ECN
460mechanism.
461However, it will tell a peer that it supports
462.Sy ECN
463mechanism when accepting a new incoming connection request if the peer
464indicates that it supports
465.Sy ECN
466mechanism in the
467.Sy SYN
468segment.
469If
470.Cm tcp_ecn_permitted
471is set to 2, in addition to negotiating with a peer on
472.Sy ECN
473mechanism when accepting connections, TCP will indicate in the outgoing
474.Sy SYN
475segment that it supports
476.Sy ECN
477mechanism when TCP makes active outgoing connections.
478The default for
479.Cm tcp_ecn_permitted
480is 1.
481.El
482.Pp
483Turn on the timestamp option in the following way:
484.Bl -bullet -offset indent -width 4m
485.It
486Use
487.Nm ndd
488to modify the configuration parameter
489.Cm tcp_tstamp_always .
490If
491.Cm tcp_tstamp_always
492is
493.Sy 1 ,
494the timestamp option will always be set
495when connecting to a remote machine.
496If
497.Cm tcp_tstamp_always
498is
499.Sy 0 ,
500the timestamp option will not be set when connecting to a remote system.
501The
502default for
503.Cm tcp_tstamp_always
504is
505.Sy 0 .
506.It
507Regardless of the value of
508.Cm tcp_tstamp_always ,
509the timestamp option will
510always be included in a connect acknowledgement (and all succeeding packets) if
511the connecting system has used the timestamp option.
512.El
513.Pp
514Use the following procedure to turn on the timestamp option only when the
515window scale option is in effect:
516.Bl -bullet -offset indent -width 4m
517.It
518Use
519.Nm ndd
520to modify the configuration parameter
521.Cm tcp_tstamp_if_wscale .
522Setting
523.Cm tcp_tstamp_if_wscale
524to
525.Sy 1
526will cause the timestamp option
527to be set when connecting to a remote system, if the window scale option has
528been set.
529If
530.Cm tcp_tstamp_if_wscale
531is
532.Sy 0 ,
533the timestamp option will
534not be set when connecting to a remote system.
535The default for
536.Cm tcp_tstamp_if_wscale
537is
538.Sy 1 .
539.El
540.Pp
541Protection Against Wrap Around Sequence Numbers
542.Po Sy PAWS Pc
543is always used when the
544timestamp option is set.
545.Pp
546The operating system also supports multiple methods of generating initial sequence numbers.
547One of these methods is the improved technique suggested in RFC 1948.
548We
549.Em HIGHLY
550recommend that you set sequence number generation parameters as
551close to boot time as possible.
552This prevents sequence number problems on
553connections that use the same connection-ID as ones that used a different
554sequence number generation.
555The
556.Sy svc:/network/initial:default
557service configures the initial sequence number generation.
558The service reads the value contained in the configuration file
559.Pa /etc/default/inetinit
560to determine which method to use.
561.Pp
562The
563.Pa /etc/default/inetinit
564file is an unstable interface, and may change in future releases.
565.Sh EXAMPLES
566.Ss Example 1: Connecting to a server
567.Bd -literal
568$ gcc -std=c99 -Wall -lsocket -o client client.c
569$ cat client.c
570#include <sys/socket.h>
571#include <netinet/in.h>
572#include <netinet/tcp.h>
573#include <netdb.h>
574#include <stdio.h>
575#include <string.h>
576#include <unistd.h>
577
578int
579main(int argc, char *argv[])
580{
581	struct addrinfo hints, *gair, *p;
582	int fd, rv, rlen;
583	char buf[1024];
584	int y = 1;
585
586	if (argc != 3) {
587		fprintf(stderr, "%s <host> <port>\\n", argv[0]);
588		return (1);
589	}
590
591	memset(&hints, 0, sizeof (hints));
592	hints.ai_family = PF_UNSPEC;
593	hints.ai_socktype = SOCK_STREAM;
594
595	if ((rv = getaddrinfo(argv[1], argv[2], &hints, &gair)) != 0) {
596		fprintf(stderr, "getaddrinfo() failed: %s\\n",
597		    gai_strerror(rv));
598		return (1);
599	}
600
601	for (p = gair; p != NULL; p = p->ai_next) {
602		if ((fd = socket(
603		    p->ai_family,
604		    p->ai_socktype,
605		    p->ai_protocol)) == -1) {
606			perror("socket() failed");
607			continue;
608		}
609
610		if (connect(fd, p->ai_addr, p->ai_addrlen) == -1) {
611			close(fd);
612			perror("connect() failed");
613			continue;
614		}
615
616		break;
617	}
618
619	if (p == NULL) {
620		fprintf(stderr, "failed to connect to server\\n");
621		return (1);
622	}
623
624	freeaddrinfo(gair);
625
626	if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &y,
627	    sizeof (y)) == -1) {
628		perror("setsockopt(SO_KEEPALIVE) failed");
629		return (1);
630	}
631
632	while ((rlen = read(fd, buf, sizeof (buf))) > 0) {
633		fwrite(buf, rlen, 1, stdout);
634	}
635
636	if (rlen == -1) {
637		perror("read() failed");
638	}
639
640	fflush(stdout);
641
642	if (close(fd) == -1) {
643		perror("close() failed");
644	}
645
646	return (0);
647}
648$ ./client 127.0.0.1 8080
649hello
650$ ./client ::1 8080
651hello
652.Ed
653.Ss Example 2: Accepting client connections
654.Bd -literal
655$ gcc -std=c99 -Wall -lsocket -o server server.c
656$ cat server.c
657#include <sys/socket.h>
658#include <netinet/in.h>
659#include <netinet/tcp.h>
660#include <netdb.h>
661#include <stdio.h>
662#include <string.h>
663#include <unistd.h>
664#include <arpa/inet.h>
665
666void
667logmsg(struct sockaddr *s, int bytes)
668{
669	char dq[INET6_ADDRSTRLEN];
670
671	switch (s->sa_family) {
672	case AF_INET: {
673		struct sockaddr_in *s4 = (struct sockaddr_in *)s;
674		inet_ntop(AF_INET, &s4->sin_addr, dq, sizeof (dq));
675		fprintf(stdout, "sent %d bytes to %s:%d\\n",
676		    bytes, dq, ntohs(s4->sin_port));
677		break;
678	}
679	case AF_INET6: {
680		struct sockaddr_in6 *s6 = (struct sockaddr_in6 *)s;
681		inet_ntop(AF_INET6, &s6->sin6_addr, dq, sizeof (dq));
682		fprintf(stdout, "sent %d bytes to [%s]:%d\\n",
683		    bytes, dq, ntohs(s6->sin6_port));
684		break;
685	}
686	default:
687		fprintf(stdout, "sent %d bytes to unknown client\\n",
688		    bytes);
689		break;
690	}
691}
692
693int
694main(int argc, char *argv[])
695{
696	struct addrinfo hints, *gair, *p;
697	int sfd, cfd;
698	int slen, wlen, rv;
699
700	if (argc != 3) {
701		fprintf(stderr, "%s <port> <message>\\n", argv[0]);
702		return (1);
703	}
704
705	slen = strlen(argv[2]);
706
707	memset(&hints, 0, sizeof (hints));
708	hints.ai_family = PF_UNSPEC;
709	hints.ai_socktype = SOCK_STREAM;
710	hints.ai_flags = AI_PASSIVE;
711
712	if ((rv = getaddrinfo(NULL, argv[1], &hints, &gair)) != 0) {
713		fprintf(stderr, "getaddrinfo() failed: %s\\n",
714		    gai_strerror(rv));
715		return (1);
716	}
717
718	for (p = gair; p != NULL; p = p->ai_next) {
719		if ((sfd = socket(
720		    p->ai_family,
721		    p->ai_socktype,
722		    p->ai_protocol)) == -1) {
723			perror("socket() failed");
724			continue;
725		}
726
727		if (bind(sfd, p->ai_addr, p->ai_addrlen) == -1) {
728			close(sfd);
729			perror("bind() failed");
730			continue;
731		}
732
733		break;
734	}
735
736	if (p == NULL) {
737		fprintf(stderr, "server failed to bind()\\n");
738		return (1);
739	}
740
741	freeaddrinfo(gair);
742
743	if (listen(sfd, 1024) != 0) {
744		perror("listen() failed");
745		return (1);
746	}
747
748	fprintf(stdout, "waiting for clients...\\n");
749
750	for (int times = 0; times < 5; times++) {
751		struct sockaddr_storage stor;
752		socklen_t alen = sizeof (stor);
753		struct sockaddr *addr = (struct sockaddr *)&stor;
754
755		if ((cfd = accept(sfd, addr, &alen)) == -1) {
756			perror("accept() failed");
757			continue;
758		}
759
760		wlen = 0;
761
762		do {
763			wlen += write(cfd, argv[2] + wlen, slen - wlen);
764		} while (wlen < slen);
765
766		logmsg(addr, wlen);
767
768		if (close(cfd) == -1) {
769			perror("close(cfd) failed");
770		}
771	}
772
773	if (close(sfd) == -1) {
774		perror("close(sfd) failed");
775	}
776
777	fprintf(stdout, "finished.\\n");
778
779	return (0);
780}
781$ ./server 8080 $'hello\\n'
782waiting for clients...
783sent 6 bytes to [::ffff:127.0.0.1]:59059
784sent 6 bytes to [::ffff:127.0.0.1]:47448
785sent 6 bytes to [::ffff:127.0.0.1]:54949
786sent 6 bytes to [::ffff:127.0.0.1]:55186
787sent 6 bytes to [::1]:62256
788finished.
789.Ed
790.Sh DIAGNOSTICS
791A socket operation may fail if:
792.Bl -tag -offset indent -width 16m
793.It Er EISCONN
794A
795.Fn connect
796operation was attempted on a socket on which a
797.Fn connect
798operation had already been performed.
799.It Er ETIMEDOUT
800A connection was dropped due to excessive retransmissions.
801.It Er ECONNRESET
802The remote peer forced the connection to be closed (usually because the remote
803machine has lost state information about the connection due to a crash).
804.It Er ECONNREFUSED
805The remote peer actively refused connection establishment (usually because no
806process is listening to the port).
807.It Er EADDRINUSE
808A
809.Fn bind
810operation was attempted on a socket with a network address/port pair that has
811already been bound to another socket.
812.It Er EADDRNOTAVAIL
813A
814.Fn bind
815operation was attempted on a socket with a network address for which no network
816interface exists.
817.It Er EACCES
818A
819.Fn bind
820operation was attempted with a
821.Dq reserved
822port number and the effective user ID of the process was not the privileged user.
823.It Er ENOBUFS
824The system ran out of memory for internal data structures.
825.El
826.Sh SEE ALSO
827.Xr svcs 1 ,
828.Xr ioctl 2 ,
829.Xr read 2 ,
830.Xr write 2 ,
831.Xr accept 3SOCKET ,
832.Xr bind 3SOCKET ,
833.Xr connect 3SOCKET ,
834.Xr getprotobyname 3SOCKET ,
835.Xr getsockopt 3SOCKET ,
836.Xr listen 3SOCKET ,
837.Xr send 3SOCKET ,
838.Xr inet 4P ,
839.Xr inet6 4P ,
840.Xr ip 4P ,
841.Xr ip6 4P ,
842.Xr smf 7 ,
843.Xr ndd 8 ,
844.Xr svcadm 8
845.Rs
846.%A "K. Ramakrishnan"
847.%A "S. Floyd"
848.%A "D. Black"
849.%T "The Addition of Explicit Congestion Notification (ECN) to IP"
850.%R "RFC 3168"
851.%D "September 2001"
852.Re
853.Rs
854.%A "M. Mathias"
855.%A "J. Mahdavi"
856.%A "S. Ford"
857.%A "A. Romanow"
858.%T "TCP Selective Acknowledgement Options"
859.%R "RFC 2018"
860.%D "October 1996"
861.Re
862.Rs
863.%A "S. Bellovin"
864.%T "Defending Against Sequence Number Attacks"
865.%R "RFC 1948"
866.%D "May 1996"
867.Re
868.Rs
869.%A "D. Borman"
870.%A "B. Braden"
871.%A "V. Jacobson"
872.%A "R. Scheffenegger, Ed."
873.%T "TCP Extensions for High Performance"
874.%R "RFC 7323"
875.%D "September 2014"
876.Re
877.Rs
878.%A "Jon Postel"
879.%T "Transmission Control Protocol - DARPA Internet Program Protocol Specification"
880.%R "RFC 793"
881.%C "Network Information Center, SRI International, Menlo Park, CA."
882.%D "September 1981"
883.Re
884.Sh NOTES
885The
886.Sy tcp
887service is managed by the service management facility,
888.Xr smf 7 ,
889under the service identifier
890.Sy svc:/network/initial:default .
891.Pp
892Administrative actions on this service, such as enabling, disabling, or
893requesting restart, can be performed using
894.Xr svcadm 8 .
895The service's
896status can be queried using the
897.Xr svcs 1
898command.
899