Commit | Line | Data |
---|---|---|
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 | |
11 | send, 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 | |
19 | cc = send(s, msg, len, flags) | |
20 | int cc, s; | |
21 | char *msg; | |
22 | int len, flags; | |
23 | .PP | |
24 | .ft B | |
25 | cc = sendto(s, msg, len, flags, to, tolen) | |
26 | int cc, s; | |
27 | char *msg; | |
28 | int len, flags; | |
29 | struct sockaddr *to; | |
30 | int tolen; | |
31 | .PP | |
32 | .ft B | |
33 | cc = sendmsg(s, msg, flags) | |
34 | int cc, s; | |
fc04ceb7 | 35 | struct msghdr *msg; |
7611a06d KM |
36 | int flags; |
37 | .fi | |
38 | .SH DESCRIPTION | |
39 | .IR Send , | |
40 | .IR sendto , | |
41 | and | |
42 | .I sendmsg | |
43 | are used to transmit a message to another socket. | |
44 | .I Send | |
45 | may be used only when the socket is in a | |
46 | .I connected | |
47 | state, while | |
48 | .I sendto | |
49 | and | |
50 | .I sendmsg | |
51 | may be used at any time. | |
52 | .PP | |
53 | The address of the target is given by | |
54 | .I to | |
55 | with | |
56 | .I tolen | |
57 | specifying its size. | |
58 | The length of the message is given by | |
59 | .IR len . | |
60 | If the message is too long to pass atomically through the | |
61 | underlying protocol, then the error EMSGSIZE is returned, and | |
62 | the message is not transmitted. | |
63 | .PP | |
64 | No indication of failure to deliver is implicit in a | |
65 | .IR send . | |
66 | Return values of \-1 indicate some locally detected errors. | |
67 | .PP | |
68 | If no messages space is available at the socket to hold | |
69 | the message to be transmitted, then | |
70 | .I send | |
71 | normally blocks, unless the socket has been placed in | |
def9d0f9 | 72 | non-blocking I/O mode. |
7611a06d KM |
73 | The |
74 | .IR select (2) | |
75 | call may be used to determine when it is possible to | |
76 | send more data. | |
77 | .PP | |
78 | The | |
79 | .I flags | |
def9d0f9 MK |
80 | parameter 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 | |
89 | The flag MSG_OOB is used to send \*(lqout-of-band\*(rq | |
90 | data on sockets that support this notion (e.g. SOCK_STREAM); | |
91 | the underlying protocol must also support \*(lqout-of-band\*(rq data. | |
92 | MSG_DONTROUTE is usually used only by diagnostic or routing programs. | |
7611a06d KM |
93 | .PP |
94 | See | |
95 | .IR recv (2) | |
96 | for a description of the | |
97 | .I msghdr | |
98 | structure. | |
99 | .SH "RETURN VALUE | |
100 | The call returns the number of characters sent, or \-1 | |
101 | if an error occurred. | |
102 | .SH "ERRORS | |
103 | .TP 20 | |
104 | [EBADF] | |
105 | An invalid descriptor was specified. | |
106 | .TP 20 | |
107 | [ENOTSOCK] | |
108 | The argument \fIs\fP is not a socket. | |
109 | .TP 20 | |
110 | [EFAULT] | |
111 | An invalid user space address was specified for a parameter. | |
112 | .TP 20 | |
113 | [EMSGSIZE] | |
114 | The socket requires that message be sent atomically, | |
115 | and the size of the message to be sent made this impossible. | |
116 | .TP 20 | |
117 | [EWOULDBLOCK] | |
118 | The socket is marked non-blocking and the requested operation | |
119 | would block. | |
def9d0f9 MK |
120 | .TP 20 |
121 | [ENOBUFS] | |
122 | The system was unable to allocate an internal buffer. | |
123 | The operation may succeed when buffers become available. | |
124 | .TP 20 | |
125 | [ENOBUFS] | |
126 | The output queue for a network interface was full. | |
127 | This generally indicates that the interface has stopped sending, | |
128 | but may be caused by transient congestion. | |
7611a06d | 129 | .SH SEE ALSO |
def9d0f9 | 130 | fcntl(2), recv(2), select(2), getsockopt(2), socket(2), write(2) |