161183Sbostic.\" Copyright (c) 1983, 1991, 1993 261183Sbostic.\" The Regents of the University of California. All rights reserved. 320257Smckusick.\" 443568Strent.\" %sccs.include.redist.man% 520257Smckusick.\" 6*66184Sbostic.\" @(#)send.2 8.2 (Berkeley) 02/21/94 736759Sbostic.\" 847208Scael.Dd 947208Scael.Dt SEND 2 1047208Scael.Os BSD 4.2 1147208Scael.Sh NAME 1247208Scael.Nm send , 1347208Scael.Nm sendto , 1447208Scael.Nm sendmsg 1547208Scael.Nd send a message from a socket 1647208Scael.Sh SYNOPSIS 1747208Scael.Fd #include <sys/types.h> 1847208Scael.Fd #include <sys/socket.h> 19*66184Sbostic.Ft ssize_t 20*66184Sbostic.Fn send "int s" "const void *msg" "size_t len" "int flags" 21*66184Sbostic.Ft ssize_t 22*66184Sbostic.Fn sendto "int s" "const void *msg" "size_t len" "int flags" "const struct sockaddr *to" "int tolen" 23*66184Sbostic.Ft ssize_t 2447208Scael.Fn sendmsg "int s" "const struct msghdr *msg" "int flags" 2547208Scael.Sh DESCRIPTION 2647208Scael.Fn Send , 2747208Scael.Fn sendto , 2820257Smckusickand 2947208Scael.Fn sendmsg 3020257Smckusickare used to transmit a message to another socket. 3147208Scael.Fn Send 3220257Smckusickmay be used only when the socket is in a 3347208Scael.Em connected 3420257Smckusickstate, while 3547208Scael.Fn sendto 3620257Smckusickand 3747208Scael.Fn sendmsg 3820257Smckusickmay be used at any time. 3947208Scael.Pp 4020257SmckusickThe address of the target is given by 4147208Scael.Fa to 4220257Smckusickwith 4347208Scael.Fa tolen 4420257Smckusickspecifying its size. 4520257SmckusickThe length of the message is given by 4647208Scael.Fa len . 4720257SmckusickIf the message is too long to pass atomically through the 4847208Scaelunderlying protocol, the error 4947208Scael.Er EMSGSIZE 5047208Scaelis returned, and 5120257Smckusickthe message is not transmitted. 5247208Scael.Pp 5320257SmckusickNo indication of failure to deliver is implicit in a 5447208Scael.Fn send . 5547208ScaelLocally detected errors are indicated by a return value of -1. 5647208Scael.Pp 5720257SmckusickIf no messages space is available at the socket to hold 5820257Smckusickthe message to be transmitted, then 5947208Scael.Fn send 6020257Smckusicknormally blocks, unless the socket has been placed in 6128126Skarelsnon-blocking I/O mode. 6220257SmckusickThe 6347208Scael.Xr select 2 6420257Smckusickcall may be used to determine when it is possible to 6520257Smckusicksend more data. 6647208Scael.Pp 6720257SmckusickThe 6847208Scael.Fa flags 6928126Skarelsparameter may include one or more of the following: 7047208Scael.Bd -literal 7147449Scael#define MSG_OOB 0x1 /* process out-of-band data */ 7247449Scael#define MSG_DONTROUTE 0x4 /* bypass routing, use direct interface */ 7347208Scael.Ed 7447208Scael.Pp 7547208ScaelThe flag 7647208Scael.Dv MSG_OOB 7747208Scaelis used to send 7847208Scael.Dq out-of-band 7947208Scaeldata on sockets that support this notion (e.g. 8047208Scael.Dv SOCK_STREAM ) ; 8147208Scaelthe underlying protocol must also support 8247208Scael.Dq out-of-band 8347208Scaeldata. 8447208Scael.Dv MSG_DONTROUTE 8547208Scaelis usually used only by diagnostic or routing programs. 8647208Scael.Pp 8720257SmckusickSee 8847208Scael.Xr recv 2 8920257Smckusickfor a description of the 9047208Scael.Fa msghdr 9120257Smckusickstructure. 9247208Scael.Sh RETURN VALUES 9347208ScaelThe call returns the number of characters sent, or -1 9420257Smckusickif an error occurred. 9547208Scael.Sh ERRORS 9647208Scael.Fn Send , 9747208Scael.Fn sendto , 9847208Scaeland 9947208Scael.Fn sendmsg 10047208Scaelfail if: 10153310Sbostic.Bl -tag -width [EMSGSIZE] 10247208Scael.It Bq Er EBADF 10320257SmckusickAn invalid descriptor was specified. 10447208Scael.It Bq Er ENOTSOCK 10547208ScaelThe argument 10647208Scael.Fa s 10747208Scaelis not a socket. 10847208Scael.It Bq Er EFAULT 10920257SmckusickAn invalid user space address was specified for a parameter. 11047208Scael.It Bq Er EMSGSIZE 11120257SmckusickThe socket requires that message be sent atomically, 11220257Smckusickand the size of the message to be sent made this impossible. 11353310Sbostic.It Bq Er EAGAIN 11420257SmckusickThe socket is marked non-blocking and the requested operation 11520257Smckusickwould block. 11647208Scael.It Bq Er ENOBUFS 11728126SkarelsThe system was unable to allocate an internal buffer. 11828126SkarelsThe operation may succeed when buffers become available. 11947208Scael.It Bq Er ENOBUFS 12028126SkarelsThe output queue for a network interface was full. 12128126SkarelsThis generally indicates that the interface has stopped sending, 12228126Skarelsbut may be caused by transient congestion. 12347208Scael.El 12447208Scael.Sh SEE ALSO 12547208Scael.Xr fcntl 2 , 12647208Scael.Xr recv 2 , 12747208Scael.Xr select 2 , 12847208Scael.Xr getsockopt 2 , 12947208Scael.Xr socket 2 , 13047208Scael.Xr write 2 13147208Scael.Sh HISTORY 13247208ScaelThe 13347208Scael.Nm 13447208Scaelfunction call appeared in 13547208Scael.Bx 4.2 . 136