Commit | Line | Data |
---|---|---|
931b8415 | 1 | .\" Copyright (c) 1983, 1991 The Regents of the University of California. |
da268306 | 2 | .\" All rights reserved. |
7611a06d | 3 | .\" |
af359dea C |
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. | |
da268306 | 19 | .\" |
af359dea C |
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. | |
7611a06d | 31 | .\" |
af359dea C |
32 | .\" @(#)send.2 6.9 (Berkeley) 5/1/91 |
33 | .\" | |
34 | .Dd May 1, 1991 | |
931b8415 CL |
35 | .Dt SEND 2 |
36 | .Os BSD 4.2 | |
37 | .Sh NAME | |
38 | .Nm send , | |
39 | .Nm sendto , | |
40 | .Nm sendmsg | |
41 | .Nd send a message from a socket | |
42 | .Sh SYNOPSIS | |
43 | .Fd #include <sys/types.h> | |
44 | .Fd #include <sys/socket.h> | |
45 | .Ft int | |
af359dea | 46 | .Fn send "int s" "const void *msg" "int len" "int flags" |
931b8415 | 47 | .Ft int |
af359dea | 48 | .Fn sendto "int s" "const void *msg" "int len" "int flags" "const struct sockaddr *to" "int tolen" |
931b8415 CL |
49 | .Ft int |
50 | .Fn sendmsg "int s" "const struct msghdr *msg" "int flags" | |
51 | .Sh DESCRIPTION | |
52 | .Fn Send , | |
53 | .Fn sendto , | |
7611a06d | 54 | and |
931b8415 | 55 | .Fn sendmsg |
7611a06d | 56 | are used to transmit a message to another socket. |
931b8415 | 57 | .Fn Send |
7611a06d | 58 | may be used only when the socket is in a |
931b8415 | 59 | .Em connected |
7611a06d | 60 | state, while |
931b8415 | 61 | .Fn sendto |
7611a06d | 62 | and |
931b8415 | 63 | .Fn sendmsg |
7611a06d | 64 | may be used at any time. |
931b8415 | 65 | .Pp |
7611a06d | 66 | The address of the target is given by |
931b8415 | 67 | .Fa to |
7611a06d | 68 | with |
931b8415 | 69 | .Fa tolen |
7611a06d KM |
70 | specifying its size. |
71 | The length of the message is given by | |
931b8415 | 72 | .Fa len . |
7611a06d | 73 | If the message is too long to pass atomically through the |
931b8415 CL |
74 | underlying protocol, the error |
75 | .Er EMSGSIZE | |
76 | is returned, and | |
7611a06d | 77 | the message is not transmitted. |
931b8415 | 78 | .Pp |
7611a06d | 79 | No indication of failure to deliver is implicit in a |
931b8415 CL |
80 | .Fn send . |
81 | Locally detected errors are indicated by a return value of -1. | |
82 | .Pp | |
7611a06d KM |
83 | If no messages space is available at the socket to hold |
84 | the message to be transmitted, then | |
931b8415 | 85 | .Fn send |
7611a06d | 86 | normally blocks, unless the socket has been placed in |
def9d0f9 | 87 | non-blocking I/O mode. |
7611a06d | 88 | The |
931b8415 | 89 | .Xr select 2 |
7611a06d KM |
90 | call may be used to determine when it is possible to |
91 | send more data. | |
931b8415 | 92 | .Pp |
7611a06d | 93 | The |
931b8415 | 94 | .Fa flags |
def9d0f9 | 95 | parameter may include one or more of the following: |
931b8415 | 96 | .Bd -literal |
8a9f7379 CL |
97 | #define MSG_OOB 0x1 /* process out-of-band data */ |
98 | #define MSG_DONTROUTE 0x4 /* bypass routing, use direct interface */ | |
931b8415 CL |
99 | .Ed |
100 | .Pp | |
101 | The flag | |
102 | .Dv MSG_OOB | |
103 | is used to send | |
104 | .Dq out-of-band | |
105 | data on sockets that support this notion (e.g. | |
106 | .Dv SOCK_STREAM ) ; | |
107 | the underlying protocol must also support | |
108 | .Dq out-of-band | |
109 | data. | |
110 | .Dv MSG_DONTROUTE | |
111 | is usually used only by diagnostic or routing programs. | |
112 | .Pp | |
7611a06d | 113 | See |
931b8415 | 114 | .Xr recv 2 |
7611a06d | 115 | for a description of the |
931b8415 | 116 | .Fa msghdr |
7611a06d | 117 | structure. |
931b8415 CL |
118 | .Sh RETURN VALUES |
119 | The call returns the number of characters sent, or -1 | |
7611a06d | 120 | if an error occurred. |
931b8415 CL |
121 | .Sh ERRORS |
122 | .Fn Send , | |
123 | .Fn sendto , | |
124 | and | |
125 | .Fn sendmsg | |
126 | fail if: | |
127 | .Bl -tag -width [EWOULDBLOCK] | |
128 | .It Bq Er EBADF | |
7611a06d | 129 | An invalid descriptor was specified. |
931b8415 CL |
130 | .It Bq Er ENOTSOCK |
131 | The argument | |
132 | .Fa s | |
133 | is not a socket. | |
134 | .It Bq Er EFAULT | |
7611a06d | 135 | An invalid user space address was specified for a parameter. |
931b8415 | 136 | .It Bq Er EMSGSIZE |
7611a06d KM |
137 | The socket requires that message be sent atomically, |
138 | and the size of the message to be sent made this impossible. | |
931b8415 | 139 | .It Bq Er EWOULDBLOCK |
7611a06d KM |
140 | The socket is marked non-blocking and the requested operation |
141 | would block. | |
931b8415 | 142 | .It Bq Er ENOBUFS |
def9d0f9 MK |
143 | The system was unable to allocate an internal buffer. |
144 | The operation may succeed when buffers become available. | |
931b8415 | 145 | .It Bq Er ENOBUFS |
def9d0f9 MK |
146 | The output queue for a network interface was full. |
147 | This generally indicates that the interface has stopped sending, | |
148 | but may be caused by transient congestion. | |
931b8415 CL |
149 | .El |
150 | .Sh SEE ALSO | |
151 | .Xr fcntl 2 , | |
152 | .Xr recv 2 , | |
153 | .Xr select 2 , | |
154 | .Xr getsockopt 2 , | |
155 | .Xr socket 2 , | |
156 | .Xr write 2 | |
157 | .Sh HISTORY | |
158 | The | |
159 | .Nm | |
160 | function call appeared in | |
161 | .Bx 4.2 . |