1.\" Copyright (c) 1983, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)send.2 6.9 (Berkeley) 5/1/91 33.\" 34.Dd May 1, 1991 35.Dt SEND 2 36.Os BSD 4.2 37.Sh NAME 38.Nm send , 39.Nm sendto , 40.Nm sendmsg 41.Nd send a message from a socket 42.Sh SYNOPSIS 43.Fd #include <sys/types.h> 44.Fd #include <sys/socket.h> 45.Ft int 46.Fn send "int s" "const void *msg" "int len" "int flags" 47.Ft int 48.Fn sendto "int s" "const void *msg" "int len" "int flags" "const struct sockaddr *to" "int tolen" 49.Ft int 50.Fn sendmsg "int s" "const struct msghdr *msg" "int flags" 51.Sh DESCRIPTION 52.Fn Send , 53.Fn sendto , 54and 55.Fn sendmsg 56are used to transmit a message to another socket. 57.Fn Send 58may be used only when the socket is in a 59.Em connected 60state, while 61.Fn sendto 62and 63.Fn sendmsg 64may be used at any time. 65.Pp 66The address of the target is given by 67.Fa to 68with 69.Fa tolen 70specifying its size. 71The length of the message is given by 72.Fa len . 73If the message is too long to pass atomically through the 74underlying protocol, the error 75.Er EMSGSIZE 76is returned, and 77the message is not transmitted. 78.Pp 79No indication of failure to deliver is implicit in a 80.Fn send . 81Locally detected errors are indicated by a return value of -1. 82.Pp 83If no messages space is available at the socket to hold 84the message to be transmitted, then 85.Fn send 86normally blocks, unless the socket has been placed in 87non-blocking I/O mode. 88The 89.Xr select 2 90call may be used to determine when it is possible to 91send more data. 92.Pp 93The 94.Fa flags 95parameter may include one or more of the following: 96.Bd -literal 97#define MSG_OOB 0x1 /* process out-of-band data */ 98#define MSG_DONTROUTE 0x4 /* bypass routing, use direct interface */ 99.Ed 100.Pp 101The flag 102.Dv MSG_OOB 103is used to send 104.Dq out-of-band 105data on sockets that support this notion (e.g. 106.Dv SOCK_STREAM ) ; 107the underlying protocol must also support 108.Dq out-of-band 109data. 110.Dv MSG_DONTROUTE 111is usually used only by diagnostic or routing programs. 112.Pp 113See 114.Xr recv 2 115for a description of the 116.Fa msghdr 117structure. 118.Sh RETURN VALUES 119The call returns the number of characters sent, or -1 120if an error occurred. 121.Sh ERRORS 122.Fn Send , 123.Fn sendto , 124and 125.Fn sendmsg 126fail if: 127.Bl -tag -width [EWOULDBLOCK] 128.It Bq Er EBADF 129An invalid descriptor was specified. 130.It Bq Er ENOTSOCK 131The argument 132.Fa s 133is not a socket. 134.It Bq Er EFAULT 135An invalid user space address was specified for a parameter. 136.It Bq Er EMSGSIZE 137The socket requires that message be sent atomically, 138and the size of the message to be sent made this impossible. 139.It Bq Er EWOULDBLOCK 140The socket is marked non-blocking and the requested operation 141would block. 142.It Bq Er ENOBUFS 143The system was unable to allocate an internal buffer. 144The operation may succeed when buffers become available. 145.It Bq Er ENOBUFS 146The output queue for a network interface was full. 147This generally indicates that the interface has stopped sending, 148but may be caused by transient congestion. 149.El 150.Sh SEE ALSO 151.Xr fcntl 2 , 152.Xr recv 2 , 153.Xr select 2 , 154.Xr getsockopt 2 , 155.Xr socket 2 , 156.Xr write 2 157.Sh HISTORY 158The 159.Nm 160function call appeared in 161.Bx 4.2 . 162