version 1, including all changes.
.
Rev |
Author |
# |
Line |
1 |
perry |
1 |
SEND |
|
|
2 |
!!!SEND |
|
|
3 |
NAME |
|
|
4 |
SYNOPSIS |
|
|
5 |
DESCRIPTION |
|
|
6 |
RETURN VALUE |
|
|
7 |
ERRORS |
|
|
8 |
CONFORMING TO |
|
|
9 |
NOTE |
|
|
10 |
SEE ALSO |
|
|
11 |
---- |
|
|
12 |
!!NAME |
|
|
13 |
|
|
|
14 |
|
|
|
15 |
send, sendto, sendmsg - send a message from a socket |
|
|
16 |
!!SYNOPSIS |
|
|
17 |
|
|
|
18 |
|
|
|
19 |
__#include __ |
|
|
20 |
#include __ |
|
|
21 |
|
|
|
22 |
|
|
|
23 |
__int send(int__ ''s''__, const void |
|
|
24 |
*__''msg''__, size_t__ ''len''__, int__ |
|
|
25 |
''flags''__); |
|
|
26 |
int sendto(int__ ''s''__, const void |
|
|
27 |
*__''msg''__, size_t__ ''len''__, int__ |
|
|
28 |
''flags''__, const struct sockaddr *__''to''__, |
|
|
29 |
socklen_t__ ''tolen''__); |
|
|
30 |
int sendmsg(int__ ''s''__, const struct msghdr |
|
|
31 |
*__''msg''__, int__ |
|
|
32 |
''flags''__);__ |
|
|
33 |
!!DESCRIPTION |
|
|
34 |
|
|
|
35 |
|
|
|
36 |
__Send__, __sendto__, and __sendmsg__ are used to |
|
|
37 |
transmit a message to another socket. __Send__ may be |
|
|
38 |
used only when the socket is in a ''connected'' state, |
|
|
39 |
while __sendto__ and __sendmsg__ may be used at any |
|
|
40 |
time. |
|
|
41 |
|
|
|
42 |
|
|
|
43 |
The address of the target is given by ''to'' with |
|
|
44 |
''tolen'' specifying its size. The length of the message |
|
|
45 |
is given by ''len''. If the message is too long to pass |
|
|
46 |
atomically through the underlying protocol, the error |
|
|
47 |
__EMSGSIZE__ is returned, and the message is not |
|
|
48 |
transmitted. |
|
|
49 |
|
|
|
50 |
|
|
|
51 |
No indication of failure to deliver is implicit in a |
|
|
52 |
__send__. Locally detected errors are indicated by a |
|
|
53 |
return value of -1. |
|
|
54 |
|
|
|
55 |
|
|
|
56 |
When the message does not fit into the send buffer of the |
|
|
57 |
socket, __send__ normally blocks, unless the socket has |
|
|
58 |
been placed in non-blocking I/O mode. In non-blocking mode |
|
|
59 |
it would return __EAGAIN__ in this case. The |
|
|
60 |
select(2) call may be used to determine when it is |
|
|
61 |
possible to send more data. |
|
|
62 |
|
|
|
63 |
|
|
|
64 |
The ''flags'' parameter is a flagword and can contain the |
|
|
65 |
following flags: |
|
|
66 |
|
|
|
67 |
|
|
|
68 |
__MSG_OOB__ |
|
|
69 |
|
|
|
70 |
|
|
|
71 |
Sends ''out-of-band'' data on sockets that support this |
|
|
72 |
notion (e.g. __SOCK_STREAM__); the underlying protocol |
|
|
73 |
must also support ''out-of-band'' data. |
|
|
74 |
|
|
|
75 |
|
|
|
76 |
__MSG_DONTROUTE__ |
|
|
77 |
|
|
|
78 |
|
|
|
79 |
Dont't use a gateway to send out the packet, only send to |
|
|
80 |
hosts on directly connected networks. This is usually used |
|
|
81 |
only by diagnostic or routing programs. This is only defined |
|
|
82 |
for protocol families that route; packet sockets |
|
|
83 |
don't. |
|
|
84 |
|
|
|
85 |
|
|
|
86 |
__MSG_DONTWAIT__ |
|
|
87 |
|
|
|
88 |
|
|
|
89 |
Enables non-blocking operation; if the operation would |
|
|
90 |
block, __EAGAIN__ is returned (this can also be enabled |
|
|
91 |
using the __O_NONBLOCK__ with the __F_SETFL |
|
|
92 |
fcntl(2)).__ |
|
|
93 |
|
|
|
94 |
|
|
|
95 |
__MSG_NOSIGNAL__ |
|
|
96 |
|
|
|
97 |
|
|
|
98 |
Requests not to send __SIGPIPE__ on errors on stream |
|
|
99 |
oriented sockets when the other end breaks the connection. |
|
|
100 |
The __EPIPE__ error is still returned. |
|
|
101 |
|
|
|
102 |
|
|
|
103 |
__MSG_CONFIRM__ (Linux 2.3+ only) |
|
|
104 |
|
|
|
105 |
|
|
|
106 |
Tell the link layer that forward process happened: you got a |
|
|
107 |
successful reply from the other side. If the link layer |
|
|
108 |
doesn't get this it'll regularly reprobe the neighbour (e.g. |
|
|
109 |
via a unicast ARP). Only valid on __SOCK_DGRAM__ and |
|
|
110 |
__SOCK_RAW__ sockets and currently only implemented for |
|
|
111 |
IPv4 and IPv6. See arp(7) for details. |
|
|
112 |
|
|
|
113 |
|
|
|
114 |
The definition of the ''msghdr'' structure follows. See |
|
|
115 |
recv(2) and below for an exact description of its |
|
|
116 |
fields. |
|
|
117 |
|
|
|
118 |
|
|
|
119 |
struct msghdr { |
|
|
120 |
void * msg_name; /* optional address */ |
|
|
121 |
socklen_t msg_namelen; /* size of address */ |
|
|
122 |
struct iovec * msg_iov; /* scatter/gather array */ |
|
|
123 |
size_t msg_iovlen; /* # elements in msg_iov */ |
|
|
124 |
void * msg_control; /* ancillary data, see below */ |
|
|
125 |
socklen_t msg_controllen; /* ancillary data buffer len */ |
|
|
126 |
int msg_flags; /* flags on received message */ |
|
|
127 |
}; |
|
|
128 |
|
|
|
129 |
|
|
|
130 |
You may send control information using the |
|
|
131 |
''msg_control'' and ''msg_controllen'' members. The |
|
|
132 |
maximum control buffer length the kernel can process is |
|
|
133 |
limited per socket by the __net.core.optmem_max__ sysctl; |
|
|
134 |
see socket(7). |
|
|
135 |
!!RETURN VALUE |
|
|
136 |
|
|
|
137 |
|
|
|
138 |
The calls return the number of characters sent, or -1 if an |
|
|
139 |
error occurred. |
|
|
140 |
!!ERRORS |
|
|
141 |
|
|
|
142 |
|
|
|
143 |
These are some standard errors generated by the socket |
|
|
144 |
layer. Additional errors may be generated and returned from |
|
|
145 |
the underlying protocol modules; see their respective manual |
|
|
146 |
pages. |
|
|
147 |
|
|
|
148 |
|
|
|
149 |
__EBADF__ |
|
|
150 |
|
|
|
151 |
|
|
|
152 |
An invalid descriptor was specified. |
|
|
153 |
|
|
|
154 |
|
|
|
155 |
__ENOTSOCK__ |
|
|
156 |
|
|
|
157 |
|
|
|
158 |
The argument ''s'' is not a socket. |
|
|
159 |
|
|
|
160 |
|
|
|
161 |
__EFAULT__ |
|
|
162 |
|
|
|
163 |
|
|
|
164 |
An invalid user space address was specified for a |
|
|
165 |
parameter. |
|
|
166 |
|
|
|
167 |
|
|
|
168 |
__EMSGSIZE__ |
|
|
169 |
|
|
|
170 |
|
|
|
171 |
The socket requires that message be sent atomically, and the |
|
|
172 |
size of the message to be sent made this |
|
|
173 |
impossible. |
|
|
174 |
|
|
|
175 |
|
|
|
176 |
__EAGAIN__ or __EWOULDBLOCK__ |
|
|
177 |
|
|
|
178 |
|
|
|
179 |
The socket is marked non-blocking and the requested |
|
|
180 |
operation would block. |
|
|
181 |
|
|
|
182 |
|
|
|
183 |
__ENOBUFS__ |
|
|
184 |
|
|
|
185 |
|
|
|
186 |
The output queue for a network interface was full. This |
|
|
187 |
generally indicates that the interface has stopped sending, |
|
|
188 |
but may be caused by transient congestion. (This cannot |
|
|
189 |
occur in Linux, packets are just silently dropped when a |
|
|
190 |
device queue overflows.) |
|
|
191 |
|
|
|
192 |
|
|
|
193 |
__EINTR__ |
|
|
194 |
|
|
|
195 |
|
|
|
196 |
A signal occurred. |
|
|
197 |
|
|
|
198 |
|
|
|
199 |
__ENOMEM__ |
|
|
200 |
|
|
|
201 |
|
|
|
202 |
No memory available. |
|
|
203 |
|
|
|
204 |
|
|
|
205 |
__EINVAL__ |
|
|
206 |
|
|
|
207 |
|
|
|
208 |
Invalid argument passed. |
|
|
209 |
|
|
|
210 |
|
|
|
211 |
__EPIPE__ |
|
|
212 |
|
|
|
213 |
|
|
|
214 |
The local end has been shut down on a connection oriented |
|
|
215 |
socket. In this case the process will also receive a |
|
|
216 |
__SIGPIPE__ unless __MSG_NOSIGNAL__ is |
|
|
217 |
set. |
|
|
218 |
!!CONFORMING TO |
|
|
219 |
|
|
|
220 |
|
|
|
221 |
4.4BSD, SVr4, POSIX 1003.1g draft (these function calls |
|
|
222 |
appeared in 4.2BSD). |
|
|
223 |
|
|
|
224 |
|
|
|
225 |
__MSG_CONFIRM__ is a Linux extension. |
|
|
226 |
!!NOTE |
|
|
227 |
|
|
|
228 |
|
|
|
229 |
The prototypes given above follow the Single Unix |
|
|
230 |
Specification, as glibc2 also does; the ''flags'' |
|
|
231 |
argument was `int' in BSD 4.*, but `unsigned int' in libc4 |
|
|
232 |
and libc5; the ''len'' argument was `int' in BSD 4.* and |
|
|
233 |
libc4, but `size_t' in libc5; the ''tolen'' argument was |
|
|
234 |
`int' in BSD 4.* and libc4 and libc5. See also |
|
|
235 |
accept(2). |
|
|
236 |
!!SEE ALSO |
|
|
237 |
|
|
|
238 |
|
|
|
239 |
fcntl(2), recv(2), select(2), |
|
|
240 |
getsockopt(2), sendfile(2), socket(2), |
|
|
241 |
write(2), socket(7), ip(7), |
|
|
242 |
tcp(7), udp(7) |
|
|
243 |
---- |