xref: /csrg-svn/lib/libc/sys/send.2 (revision 47208)
1.\" Copyright (c) 1983, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)send.2	6.7 (Berkeley) 03/10/91
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 int
20.Fn send "int s" "const char *msg" "int len" "int flags"
21.Ft int
22.Fn sendto "int s" "const char *msg" "int len" "int flags" "const struct sockaddr *to" "int tolen"
23.Ft int
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.Pp
71.Bd -literal
72#define	MSG_OOB		0x1	/* process out-of-band data */
73#define	MSG_DONTROUTE	0x4	/* bypass routing, use direct interface */
74.Ed
75.Pp
76The flag
77.Dv MSG_OOB
78is used to send
79.Dq out-of-band
80data on sockets that support this notion (e.g.
81.Dv SOCK_STREAM ) ;
82the underlying protocol must also support
83.Dq out-of-band
84data.
85.Dv MSG_DONTROUTE
86is usually used only by diagnostic or routing programs.
87.Pp
88See
89.Xr recv 2
90for a description of the
91.Fa msghdr
92structure.
93.Sh RETURN VALUES
94The call returns the number of characters sent, or -1
95if an error occurred.
96.Sh ERRORS
97.Fn Send ,
98.Fn sendto ,
99and
100.Fn sendmsg
101fail if:
102.Bl -tag -width [EWOULDBLOCK]
103.It Bq Er EBADF
104An invalid descriptor was specified.
105.It Bq Er ENOTSOCK
106The argument
107.Fa s
108is not a socket.
109.It Bq Er EFAULT
110An invalid user space address was specified for a parameter.
111.It Bq Er EMSGSIZE
112The socket requires that message be sent atomically,
113and the size of the message to be sent made this impossible.
114.It Bq Er EWOULDBLOCK
115The socket is marked non-blocking and the requested operation
116would block.
117.It Bq Er ENOBUFS
118The system was unable to allocate an internal buffer.
119The operation may succeed when buffers become available.
120.It Bq Er ENOBUFS
121The output queue for a network interface was full.
122This generally indicates that the interface has stopped sending,
123but may be caused by transient congestion.
124.El
125.Sh SEE ALSO
126.Xr fcntl 2 ,
127.Xr recv 2 ,
128.Xr select 2 ,
129.Xr getsockopt 2 ,
130.Xr socket 2 ,
131.Xr write 2
132.Sh HISTORY
133The
134.Nm
135function call appeared in
136.Bx 4.2 .
137