1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
|
.\" Copyright (c) 1983, 1990, 1991 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $Id: recv.2,v 1.5 1999/11/19 15:34:44 hanataka Exp $
.\"
.\" Modified Sat Jul 24 00:22:20 1993 by Rik Faith <faith@cs.unc.edu>
.\" Modified Tue Oct 22 17:45:19 1996 by Eric S. Raymond <esr@thyrsus.com>
.\" Modified 1998,1999 by Andi Kleen
.\"
.\" Japanese Version Copyright (c) 1996 Akira Yoshiyama
.\" all rights reserved.
.\" Translated Thu Jul 18 01:24:02 JST 1996
.\" by Akira Yoshiyama <yosshy@jedi.seg.kobe-u.ac.jp>
.\" Modified Sun Dec 14 22:37:11 JST 1997
.\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\" Modified Sat Aug 14 10:48:41 JST 1999
.\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\"
.TH RECV 2 "Apr 1999" "Linux Man Page" "Linux Programmer's Manual"
.SH ̾
recv, recvfrom, recvmsg \- åȤå
.SH
.B #include <sys/types.h>
.br
.B #include <sys/socket.h>
.sp
.BI "int recv(int " s ", void *" buf ", size_t " len ", int " flags );
.sp
.BI "int recvfrom(int " s ", void *" buf ", size_t " len ,
.BI "int " flags ", struct sockaddr *" from ", socklen_t *" fromlen );
.sp
.BI "int recvmsg(int " s ", struct msghdr *" msg ", int " flags );
.SH
.B recvfrom
.B recvmsg
ϥåȤå뤿˻ѤåȤ³ظ
(connection-oriened)ɤ˴ؤ餺åȤΥǡ뤳ȤǤ롣
.I from
NULL ʳǡåȤ³ظǤʤ
.I from
˥åΥɥ쥹롣
.I fromlen
ξѤΥѥǡǽ
.IR from
˳ƤХåե礭Ƥ֤äƤˤ
.I from
˼ºݤ쥢ɥ쥹礭˽֤롣
.PP
.B recv
̾
.I ³줿(connected)
å(
.BR connect (2)
)ˤĤƤΤѤ졢
.I from
ѥ NULL
.B recvfrom
Ǥ롣
ˤϻĤΥ롼ϥåĹ֤
åĹͿ줿ХåեǼޤʤäˤ
ååȤμˤäƤ;ʬΥХȤϼΤƤ
⤷ʤ(
.BR socket (2)
)
.PP
åȤ˼å¸ߤʤä硢ѤΥ
å夹ޤԤġåȤ(nonblocking)
ꤵƤ(
.BR fcntl (2)
) \-1 ֤ѿ
.I errno
.B EAGAIN
ꤵ롣
̾ᤷ̰ʲǼǡ֤
̤äѤޤǼޤԤĤȤϤʤư
.BR socket (7)
˵Ҥ줿åؤΥץ
.B SO_RCVLOWAT
.B SO_RCVTIMEO
αƶ롣
.P
.BR select (2)
.BR poll (2)
ϤĥǡϤꤹ뤿˻ѤǤ롣
.PP
recv
.I flags
ϰʲͤΡİʾ
.I or
Ǥ:
.TP
.B MSG_OOB
Υե饰̾ΥǡȥǼǤʤӰ賰(out-of-band)ǡ
뤳Ȥ᤹롣̾Υǡ塼Ƭ®ãǡ֤
ץȥ¸ߤ롢ǤΤ褦ʥץȥǤϤΥե饰
ѤǤʤ
.TP
.B MSG_PEEK
Υե饰ϼ塼κǽΥǡ塼ǡ֤
ˤä³Ʊǡ֤ȤǤ롣
.TP
.B MSG_WAITALL
Υե饰ᤷ̤ޤ(block)뤳Ȥ᤹롣
ʤ顢ʥμ顼(disconnect)ȯ
˼ǡۤʤ뷿äˤϡᤷ̤꾯ʤǡ
֤Ȥ롣
.TP
.B MSG_ERRQUEUE
顼塼ѥåȤФ
.TP
.B MSG_NOSIGNAL
ΥեåϥȥॽåȤ¦äȯ
.B SIGPIPE
ʥȯʤ褦ˤ롣
.TP
.B MSG_ERRQUEUE
Υե饰ϥ塼줿顼åȤΥ顼塼
褦ˤ롣Υ顼ŪʥåȶϤ롣
.\" ancilliary ancillary Υݡ
Ūʥåηϥץȥ˰¸Ƥ롣(IP ξ
.BR IP_RECVERR )
Υ顼
.B sock_extended_err
¤Τ:
.IP
.RS
.ne 18
.nf
.ta 4n 20n 32n
.\" XXX switch to standard types
#define SO_EE_ORIGIN_NONE 0
#define SO_EE_ORIGIN_LOCAL 1
#define SO_EE_ORIGIN_ICMP 2
#define SO_EE_ORIGIN_ICMP6 3
struct sock_extended_err
{
__u32 ee_errno; /* error number */
__u8 ee_origin; /* where the error originated */
__u8 ee_type; /* type */
__u8 ee_code; /* code */
__u8 ee_pad;
__u32 ee_info; /* additional information */
__u32 ee_data; /* other data */
};
struct sockaddr *SOCK_EE_OFFENDER(struct sock_extended_err *);
.ta
.fi
.RE
.IP
.B ee_errno
ˤϥ塼줿顼Υ顼ֹ椬äƤ롣
.B ee_origin
ˤϥ顼ȯΥꥸ(origin code)äƤ롣
¾Υեɤϥץȥ¸Ǥ롣
.B SOCK_EE_OFFENDER
ϥ顼ȯͥåȥ֥ȤΥɥ쥹ؤΥݥ֤
ɥ쥹ξˤ
.B sockaddr
.I sa_family
С
.B AF_UNSPEC
ˤʤäƤꡢ¾Υեɤ̤Ǥ롣顼ȯѥå
Ѳ٤̾ΥǡȤϤ롣
.IP
ǤΥ顼ξˤϥɥ쥹Ϥʤ(
.R cmsghdr
.I cmsg_len
Сǥå뤳ȤǤ)
顼ä硢
.B MSG_ERRQUEUE
.BR msghdr
ꤵ롣顼Ϥȡ
ڥǥƤåȡ顼Υ塼줿顼
˴Ťƺƺ졢ΥåκݤϤ롣
.PP
.B recvmsg
ľͿѥο餹
.I msghdr
¤ΤѤ롣ι¤Τ
.IR <sys/socket.h>
ǰʲΤ褦Ƥ :
.IP
.RS
.nf
.ta 4n 17n 33n
struct msghdr {
void * msg_name; /* optional address */
socklen_t msg_namelen; /* size of address */
struct iovec * msg_iov; /* scatter/gather array */
size_t msg_iovlen; /* # elements in msg_iov */
void * msg_control; /* ancillary data, see below */
socklen_t msg_controllen; /* ancillary data buffer len */
int msg_flags; /* flags on received message */
};
.ta
.fi
.RE
.PP
.I msg_name
.I msg_namelen
ϥåȤ³ƤʤˡΥɥ쥹Ǽ롣
̾ɬפʤˤ
.I msg_name
NULL 뤳ȤǤ롣
.I msg_iov
.I msg_iovlen
եɤ
.BR readv (2)
˵ҤƤ褦/ѤΥ٥ꤹ롣
.IR msg_control
եɤ
.IR msg_controllen
Ĺ¾ΥåϢΥץȥ椹Хåե
¾ŪʥǡΤΥХåեؤΥݥǤ롣
.B recvmsg
ƤФ줿
.I msg_controllen
.I msg_control
ѲǽʥХåեĹäƤɬפ롣
뤫֤äƤ硢åĹäƤ롣
.PP
åη:
.PP
.RS
.nf
.ta 4n 16n 28n
struct cmsghdr {
socklen_t cmsg_len; /* data byte count, including hdr */
int cmsg_level; /* originating protocol */
int cmsg_type; /* protocol-specific type */
/* followed by
u_char cmsg_data[]; */
};
.ta
.fi
.RE
.PP
Ūʥǡ
.BR cmsg (3)
줿ޥǤΤߥ٤Ǥ롣
.PP
ȤơLinux ϤŪǡΥᥫ˥ĥ顼
IP ץ䡢Unix åȴ֤ǥե롦ǥץ
ϤΤ˻Ѥ롣
.PP
.I msg_flags
եɤϼåȤ褦ֵѻꤵ롣
.B MSG_EOR
ϥ쥳ɤν(end-of-record)Υǡϴʥ쥳ɤ
֤Ȥ(Ūˤ
.BR SOCK_SEQPACKET
ΥåȤǻѤ)
.B MSG_TRUNC
ϡǡबͿ줿Хåե礭ä
ǡΤϤ߽ФʬΤƤ줿Ȥ
.B MSG_CTRUNC
ŪʥǡΤΥХåեˡǡΰ
ΤƤ줿
®ãǡӰ賰ǡȤ
.B MSG_OOB
֤롣
.B MSG_ERRQUEUE
ϥǡƤʤåȤΥ顼塼ĥ顼
Ȥ
.SH ֤
ΥϼХȿ֤顼ξ \-1 ֤롣
.SH 顼
ϥåؤȯŪʥ顼Ǥ롣ؤ
ץȥ롦⥸塼뤫֤¾Υ顼뤫⤷ʤ
Υޥ˥奢Ȥ뤳ȡ
.TP 0.8i
.B EBADF
.I s
̵ʥǥץǤ롣
.TP
.B ENOTCONN
åȤ³ظץȥ뤬ƤƤꡢ
ޤ³Ƥʤ(
.BR connect (2)
.BR accept (2)
Ȥ뤳)
.TP
.B ENOTSOCK
.I s
åȤȤƤʤ
.TP
.B EAGAIN
åȤ(non-blocking)ꤵƤߤ
˻ڤ(timeout)ꤵƤꡢǡ
ڤˤʤä
.TP
.B EINTR
ǡ˥ʥ(signal)Ƴޤ줿
.TP
.B EFAULT
ХåեؤΥݥץΥɥ쥹ֳؤƤ롣
.TP
.B EINVAL
̵ʰϤ줿
.SH
4.4BSD (δؿ 4.2BSD Ǹ줿)
.SH
嵭Υץȥפ glibc2 ˤäƤ롣
Single Unix Specification Ǥ ssize_t ֤ȤƱͤǤ롣
( BSD 4.* libc4 libc5 `int' ѤƤ)
.I flags
BSD 4.* Ǥ `int' libc4 libc5 Ǥ `unsigned int' Ǥ롣
.I len
BSD 4.* Ǥ `int' libc4 libc5 Ǥ `size_t' Ǥ롣
.I fromlen
BSD 4.*, libc4, libc5 Ǥ `int *' Ǥ롣
ߤ `socklen_t *' POSIX ȯ줿
.BR accept (2)
⻲Ȥ뤳ȡ
.SH Ϣ
.BR fcntl (2),
.BR read (2),
.BR select (2),
.BR getsockopt (2),
.BR socket (2),
.BR cmsg (3)
|