File: send.2

package info (click to toggle)
manpages 1.29-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,796 kB
  • ctags: 5
  • sloc: sh: 79; makefile: 61
file content (221 lines) | stat: -rw-r--r-- 6,631 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"     $Id: send.2,v 1.5 1999/06/12 10:11:39 freitag Exp $
.\"
.\" Modified Sat Jul 24 01:15:33 1993 by Rik Faith <faith@cs.unc.edu>
.\" Modified Tue Oct 22 17:55:49 1996 by Eric S. Raymond <esr@thyrsus.com>
.\" Modified Oct 1998 by Andi Kleen
.\"
.TH SEND 2 "July 1999" "Linux Man Page" "Linux Programmer's Manual"
.SH NAME
send, sendto, sendmsg \- send a message from a socket
.SH SYNOPSIS
.B #include <sys/types.h>
.br
.B #include <sys/socket.h>
.sp
.BI "int send(int " s ", const void *" msg ", size_t " len ","
.BI "int " flags );
.br
.BI "int sendto(int " s ", const void *" msg ", size_t " len ","
.BI "int " flags ", const struct sockaddr *" to ", socklen_t " tolen );
.br
.BI "int sendmsg(int " s ", const struct msghdr *" msg ","
.BI "int " flags );
.SH DESCRIPTION
.BR Send ,
.BR sendto ,
and
.B sendmsg
are used to transmit a message to another socket.
.B Send
may be used only when the socket is in a 
.I connected
state, while 
.B sendto
and
.B sendmsg
may be used at any time.
.PP
The address of the target is given by
.I to
with 
.I tolen
specifying its size.  The length of the message is given by
.IR len .
If the message is too long to pass atomically through the
underlying protocol, the error
.B EMSGSIZE
is returned, and the message is not transmitted.
.PP
No indication of failure to deliver is implicit in a
.BR send .
Locally detected errors are indicated by a return value of \-1.
.PP
When the message does not fit into the send buffer of the socket,
.B send
normally blocks, unless the socket has been placed in non-blocking I/O
mode.  In non-blocking mode it would return
.B EAGAIN
in this case.
The
.BR select (2)
call may be used to determine when it is possible to send more data.
.PP
The
.I flags
parameter is a flagword and can contain the following flags:
.\" XXX document MSG_PROXY
.TP
.B MSG_OOB
Sends
.I out-of-band
data on sockets that support this notion (e.g.
.BR SOCK_STREAM );
the underlying protocol must also support
.I out-of-band
data.
.TP
.B MSG_DONTROUTE
Dont't use a gateway to send out the packet, only send to hosts on 
directly connected networks. This is usually used only 
by diagnostic or routing programs. This is only defined for protocol
families that route; packet sockets don't.
.TP
.B MSG_DONTWAIT
Enables non-blocking operation; if the operation would block,
.B EAGAIN 
is returned (this can also be enabled using the
.B O_NONBLOCK
with the
.B F_SETFL
.BR fcntl(2)).
.TP
.B MSG_NOSIGNAL
Requests not to send 
.B SIGPIPE 
on errors on stream oriented sockets when the other end breaks the
connection. The 
.B EPIPE
error is still returned.
.PP
See 
.BR recv (2)
for a description of the
.I msghdr
structure. You may send control information using the 
.I msg_control 
and 
.I msg_controllen 
members. The maximum control buffer length the kernel can process is limited
per socket by the
.B net.core.optmem_max 
sysctl; see
.BR socket (7).
.SH "RETURN VALUES"
The calls return the number of characters sent, or \-1
if an error occurred.
.SH ERRORS
These are some standard errors generated by the socket layer. Additional errors
may be generated and returned from the underlying protocol modules; see their
respective manual pages.
.TP
.B EBADF
An invalid descriptor was specified.
.TP
.B ENOTSOCK
The argument
.I s
is not a socket.
.TP
.B EFAULT
An invalid user space address was specified for a parameter.
.TP
.B EMSGSIZE
The socket requires that message be sent atomically, and the size
of the message to be sent made this impossible.
.TP
.BR EAGAIN " or " EWOULDBLOCK
The socket is marked non-blocking and the requested operation
would block.
.TP
.B ENOBUFS
The output queue for a network interface was full.
This generally indicates that the interface has stopped sending,
but may be caused by transient congestion.
(This cannot occur in Linux, packets are just silently dropped
when a device queue overflows.)
.TP
.B EINTR
A signal occurred.
.TP
.B ENOMEM
No memory available.
.TP
.B EINVAL
Invalid argument passed. 
.TP
.B EPIPE
The local end has been shut down on a connection oriented socket.
In this case the process
will also receive a 
.B SIGPIPE 
unless 
.B MSG_NOSIGNAL 
is set.
.SH "CONFORMING TO"
4.4BSD, SVr4, POSIX 1003.1g draft (these function calls appeared in 4.2BSD).
.SH NOTE
The prototypes given above follow the Single Unix Specification,
as glibc2 also does; the
.I flags
argument was `int' in BSD 4.*, but `unsigned int' in libc4 and libc5;
the
.I len
argument was `int' in BSD 4.* and libc4, but `size_t' in libc5;
the
.I tolen
argument was `int' in BSD 4.* and libc4 and libc5.
See also
.BR accept (2).
.SH "SEE ALSO"
.BR fcntl (2),
.BR recv (2),
.BR select (2),
.BR getsockopt (2),
.BR sendfile (2),
.BR socket (2),
.BR write (2),
.BR socket (7),
.BR ip (7),
.BR tcp (7),
.BR udp (7)