Commit | Line | Data |
---|---|---|
15637ed4 RG |
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 | .\" @(#)send.2 6.9 (Berkeley) 5/1/91 | |
33 | .\" | |
34 | .Dd May 1, 1991 | |
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 | |
46 | .Fn send "int s" "const void *msg" "int len" "int flags" | |
47 | .Ft int | |
48 | .Fn sendto "int s" "const void *msg" "int len" "int flags" "const struct sockaddr *to" "int tolen" | |
49 | .Ft int | |
50 | .Fn sendmsg "int s" "const struct msghdr *msg" "int flags" | |
51 | .Sh DESCRIPTION | |
52 | .Fn Send , | |
53 | .Fn sendto , | |
54 | and | |
55 | .Fn sendmsg | |
56 | are used to transmit a message to another socket. | |
57 | .Fn Send | |
58 | may be used only when the socket is in a | |
59 | .Em connected | |
60 | state, while | |
61 | .Fn sendto | |
62 | and | |
63 | .Fn sendmsg | |
64 | may be used at any time. | |
65 | .Pp | |
66 | The address of the target is given by | |
67 | .Fa to | |
68 | with | |
69 | .Fa tolen | |
70 | specifying its size. | |
71 | The length of the message is given by | |
72 | .Fa len . | |
73 | If the message is too long to pass atomically through the | |
74 | underlying protocol, the error | |
75 | .Er EMSGSIZE | |
76 | is returned, and | |
77 | the message is not transmitted. | |
78 | .Pp | |
79 | No indication of failure to deliver is implicit in a | |
80 | .Fn send . | |
81 | Locally detected errors are indicated by a return value of -1. | |
82 | .Pp | |
83 | If no messages space is available at the socket to hold | |
84 | the message to be transmitted, then | |
85 | .Fn send | |
86 | normally blocks, unless the socket has been placed in | |
87 | non-blocking I/O mode. | |
88 | The | |
89 | .Xr select 2 | |
90 | call may be used to determine when it is possible to | |
91 | send more data. | |
92 | .Pp | |
93 | The | |
94 | .Fa flags | |
95 | parameter may include one or more of the following: | |
96 | .Bd -literal | |
97 | #define MSG_OOB 0x1 /* process out-of-band data */ | |
98 | #define MSG_DONTROUTE 0x4 /* bypass routing, use direct interface */ | |
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 | |
113 | See | |
114 | .Xr recv 2 | |
115 | for a description of the | |
116 | .Fa msghdr | |
117 | structure. | |
118 | .Sh RETURN VALUES | |
119 | The call returns the number of characters sent, or -1 | |
120 | if an error occurred. | |
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 | |
129 | An invalid descriptor was specified. | |
130 | .It Bq Er ENOTSOCK | |
131 | The argument | |
132 | .Fa s | |
133 | is not a socket. | |
134 | .It Bq Er EFAULT | |
135 | An invalid user space address was specified for a parameter. | |
136 | .It Bq Er EMSGSIZE | |
137 | The socket requires that message be sent atomically, | |
138 | and the size of the message to be sent made this impossible. | |
139 | .It Bq Er EWOULDBLOCK | |
140 | The socket is marked non-blocking and the requested operation | |
141 | would block. | |
142 | .It Bq Er ENOBUFS | |
143 | The system was unable to allocate an internal buffer. | |
144 | The operation may succeed when buffers become available. | |
145 | .It Bq Er ENOBUFS | |
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. | |
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 . |