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