xref: /netbsd-src/lib/libc/sys/send.2 (revision bada23909e740596d0a3785a73bd3583a9807fb8)
1.\"	$NetBSD: send.2,v 1.13 1999/02/10 18:20:03 kleink Exp $
2.\"
3.\" Copyright (c) 1983, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)send.2	8.2 (Berkeley) 2/21/94
35.\"
36.Dd February 21, 1994
37.Dt SEND 2
38.Os BSD 4.2
39.Sh NAME
40.Nm send ,
41.Nm sendto ,
42.Nm sendmsg
43.Nd send a message from a socket
44.Sh SYNOPSIS
45.Fd #include <sys/types.h>
46.Fd #include <sys/socket.h>
47.Ft ssize_t
48.Fn send "int s" "const void *msg" "size_t len" "int flags"
49.Ft ssize_t
50.Fn sendto "int s" "const void *msg" "size_t len" "int flags" "const struct sockaddr *to" "socklen_t tolen"
51.Ft ssize_t
52.Fn sendmsg "int s" "const struct msghdr *msg" "int flags"
53.Sh DESCRIPTION
54.Fn send ,
55.Fn sendto ,
56and
57.Fn sendmsg
58are used to transmit a message to another socket.
59.Fn send
60may be used only when the socket is in a
61.Em connected
62state, while
63.Fn sendto
64and
65.Fn sendmsg
66may be used at any time.
67.Pp
68The address of the target is given by
69.Fa to
70with
71.Fa tolen
72specifying its size.
73The length of the message is given by
74.Fa len .
75If the message is too long to pass atomically through the
76underlying protocol, the error
77.Er EMSGSIZE
78is returned, and
79the message is not transmitted.
80.Pp
81No indication of failure to deliver is implicit in a
82.Fn send .
83Locally detected errors are indicated by a return value of -1.
84.Pp
85If no messages space is available at the socket to hold
86the message to be transmitted, then
87.Fn send
88normally blocks, unless the socket has been placed in
89non-blocking I/O mode.
90The
91.Xr select 2
92or
93.Xr poll 2
94call may be used to determine when it is possible to
95send more data.
96.Pp
97The
98.Fa flags
99parameter may include one or more of the following:
100.Bd -literal
101#define	MSG_OOB        0x1  /* process out-of-band data */
102#define	MSG_DONTROUTE  0x4  /* bypass routing, use direct interface */
103.Ed
104.Pp
105The flag
106.Dv MSG_OOB
107is used to send
108.Dq out-of-band
109data on sockets that support this notion (e.g.
110.Dv SOCK_STREAM ) ;
111the underlying protocol must also support
112.Dq out-of-band
113data.
114.Dv MSG_DONTROUTE
115is usually used only by diagnostic or routing programs.
116.Pp
117See
118.Xr recv 2
119for a description of the
120.Fa msghdr
121structure.
122.Sh RETURN VALUES
123The call returns the number of characters sent, or -1
124if an error occurred.
125.Sh ERRORS
126.Fn send ,
127.Fn sendto ,
128and
129.Fn sendmsg
130fail if:
131.Bl -tag -width Er
132.It Bq Er EBADF
133An invalid descriptor was specified.
134.It Bq Er ENOTSOCK
135The argument
136.Fa s
137is not a socket.
138.It Bq Er EFAULT
139An invalid user space address was specified for a parameter.
140.It Bq Er EMSGSIZE
141The socket requires that message be sent atomically,
142and the size of the message to be sent made this impossible.
143.It Bq Er EAGAIN
144The socket is marked non-blocking and the requested operation
145would block.
146.It Bq Er ENOBUFS
147The system was unable to allocate an internal buffer.
148The operation may succeed when buffers become available.
149.It Bq Er ENOBUFS
150The output queue for a network interface was full.
151This generally indicates that the interface has stopped sending,
152but may be caused by transient congestion.
153.It Bq Er EACCES
154The SO_BROADCAST option is not set on the socket, and a broadcast address
155was given as the destination.
156.It Bq Er EHOSTUNREACH
157The destination for the message is unreachable.
158.It Bq Er EINVAL
159The total length of the I/O is more than can be expressed by the ssize_t
160return value.
161.It Bq Er EAFNOSUPPORT
162Addresses in the specified address family cannot be used with this socket.
163.El
164.Pp
165.Fn sendmsg
166will also fail if:
167.Bl -tag -width Er
168.It Bq Er EMSGSIZE
169The
170.Fa msg_iovlen
171member of the
172.Fa msg
173structure is less than or equal to 0
174or is greater than
175.Dv {IOV_MAX} .
176.El
177.Sh SEE ALSO
178.Xr fcntl 2 ,
179.Xr recv 2 ,
180.Xr select 2 ,
181.Xr getsockopt 2 ,
182.Xr socket 2 ,
183.Xr write 2
184.Sh HISTORY
185The
186.Fn send
187function call appeared in
188.Bx 4.2 .
189