date and time created 91/03/06 18:09:53 by bostic
[unix-history] / usr / src / lib / libc / sys / send.2
CommitLineData
da268306
KB
1.\" Copyright (c) 1983 The Regents of the University of California.
2.\" All rights reserved.
7611a06d 3.\"
91cff1e1 4.\" %sccs.include.redist.man%
da268306 5.\"
91cff1e1 6.\" @(#)send.2 6.6 (Berkeley) %G%
7611a06d 7.\"
2b8c449b 8.TH SEND 2 ""
7611a06d
KM
9.UC 5
10.SH NAME
11send, sendto, sendmsg \- send a message from a socket
12.SH SYNOPSIS
13.nf
14.ft B
15#include <sys/types.h>
16#include <sys/socket.h>
17.PP
18.ft B
19cc = send(s, msg, len, flags)
20int cc, s;
21char *msg;
22int len, flags;
23.PP
24.ft B
25cc = sendto(s, msg, len, flags, to, tolen)
26int cc, s;
27char *msg;
28int len, flags;
29struct sockaddr *to;
30int tolen;
31.PP
32.ft B
33cc = sendmsg(s, msg, flags)
34int cc, s;
fc04ceb7 35struct msghdr *msg;
7611a06d
KM
36int flags;
37.fi
38.SH DESCRIPTION
39.IR Send ,
40.IR sendto ,
41and
42.I sendmsg
43are used to transmit a message to another socket.
44.I Send
45may be used only when the socket is in a
46.I connected
47state, while
48.I sendto
49and
50.I sendmsg
51may be used at any time.
52.PP
53The address of the target is given by
54.I to
55with
56.I tolen
57specifying its size.
58The length of the message is given by
59.IR len .
60If the message is too long to pass atomically through the
61underlying protocol, then the error EMSGSIZE is returned, and
62the message is not transmitted.
63.PP
64No indication of failure to deliver is implicit in a
65.IR send .
66Return values of \-1 indicate some locally detected errors.
67.PP
68If no messages space is available at the socket to hold
69the message to be transmitted, then
70.I send
71normally blocks, unless the socket has been placed in
def9d0f9 72non-blocking I/O mode.
7611a06d
KM
73The
74.IR select (2)
75call may be used to determine when it is possible to
76send more data.
77.PP
78The
79.I flags
def9d0f9
MK
80parameter may include one or more of the following:
81.PP
82.nf
83.RS
84.ta \w'#define\ \ 'u +\w'MSG_DONTROUTE\ \ \ 'u +\w'0x\0\0\0\ \ 'u
85#define MSG_OOB 0x1 /* process out-of-band data */
86#define MSG_DONTROUTE 0x4 /* bypass routing, use direct interface */
87.RE
88.fi
89The flag MSG_OOB is used to send \*(lqout-of-band\*(rq
90data on sockets that support this notion (e.g. SOCK_STREAM);
91the underlying protocol must also support \*(lqout-of-band\*(rq data.
92MSG_DONTROUTE is usually used only by diagnostic or routing programs.
7611a06d
KM
93.PP
94See
95.IR recv (2)
96for a description of the
97.I msghdr
98structure.
99.SH "RETURN VALUE
100The call returns the number of characters sent, or \-1
101if an error occurred.
102.SH "ERRORS
103.TP 20
104[EBADF]
105An invalid descriptor was specified.
106.TP 20
107[ENOTSOCK]
108The argument \fIs\fP is not a socket.
109.TP 20
110[EFAULT]
111An invalid user space address was specified for a parameter.
112.TP 20
113[EMSGSIZE]
114The socket requires that message be sent atomically,
115and the size of the message to be sent made this impossible.
116.TP 20
117[EWOULDBLOCK]
118The socket is marked non-blocking and the requested operation
119would block.
def9d0f9
MK
120.TP 20
121[ENOBUFS]
122The system was unable to allocate an internal buffer.
123The operation may succeed when buffers become available.
124.TP 20
125[ENOBUFS]
126The output queue for a network interface was full.
127This generally indicates that the interface has stopped sending,
128but may be caused by transient congestion.
7611a06d 129.SH SEE ALSO
def9d0f9 130fcntl(2), recv(2), select(2), getsockopt(2), socket(2), write(2)