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