subscribe linux-man
modify some words
but not good enough
In memories of HIZUKI AYAKA ,the angel!
月
吹智也
'\" t
.\" Copyright (c) 1983, 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: socket.2,v 1.4 1999/05/13 11:33:42 freitag Exp $
.\"
.\" Modified 1993-07-24 by Rik Faith <faith@xxxxxxxxxx>
.\" Modified 1996-10-22 by Eric S. Raymond <esr@xxxxxxxxxxx>
.\" Modified 1998, 1999 by Andi Kleen <ak@xxxxxx>
.\" Modified 2002-07-17 by Michael Kerrisk <mtk.manpages@xxxxxxxxx>
.\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@xxxxxxxxx>
.\"
.TH SOCKET 2 2009-01-19 "Linux" "Linux Programmer's Manual"
.SH å??å?
socket - 建ç«?ä¸?个ç?¨äº?交æµ?ç??端ç?¹
.SH ��
.BR "#include <sys/types.h>" " /* See NOTES */"
.br
.B #include <sys/socket.h>
.sp
.BI "int socket(int " domain ", int " type ", int " protocol );
.SH æ??è¿°
.BR socket ()
建ç«?ä¸?个ç?¨äº?交æµ?ç??端ç?¹å¹¶ä¸?è¿?å??ä¸?个æ??述符ã??
.PP
The
.I domain
å??æ?°æ??å®?ä¸?个é??讯å??å??ï¼?é??æ?©ç??å??è®®å°?ä¼?ç?¨äº?é??讯ã??å??è®®å??å?¨
.IR <sys/socket.h> .
ä¸å®?ä¹?ã?? ç?®å??å·²ç?¥ç??æ ¼å¼?å??æ?¬ï¼?
.TS
tab(:);
l l l.
å??称:ç?®ç??ï¼?æ??å??页
T{
.BR AF_UNIX ", " æ?¬å?°é??讯:
T}:T{
unix(7)
T}:T{
.BR unix (7)
T}
T{
.B AF_INET
T}:IPv4 ç½?ç»?å??è®®:T{
.BR ip (7)
T}
T{
.B AF_INET6
T}:IPv6 ç½?ç»?å??è®®:T{
.BR ipv6 (7)
T}
T{
.B AF_IPX
T}:IPX \- Novell å??è®®
T{
.B AF_NETLINK
T}:T{
å??æ ¸ç?¨æ?·ç??é?¢è®¾å¤?
T}:T{
.BR netlink (7)
T}
T{
.B AF_X25
T}:ITU-T X.25 / ISO-8208 å??è®®:T{
.BR x25 (7)
T}
T{
.B AF_AX25
T}:T{
Amateur radio AX.25 protocol
T}:
T{
.B AF_ATMPVC
T}:Access to raw ATM PVCs:
T{
.B AF_APPLETALK
T}:Appletalk:T{
.BR ddp (7)
T}
T{
.B AF_PACKET
T}:T{
åº?å±?å??è¿?æ?¥
T}:T{
.BR packet (7)
T}
.TE
.PP
å¥?æ?¥å?é??è¿?
.IR type ,
å??æ?°æ?¥ç¡®å®?é??ä¿¡è¯ä¹?ã??ç?®å??å®?ä¹?ç??ç±»å??æ??ï¼?
.TP 16
.B SOCK_STREAM
æ??ä¾?æ??åº?ç??ï¼?å?¯é? ç??ï¼?å??å??ç??ï¼?å?ºäº?å?è??æµ?ç??é??讯ã??å?¯è?½æ?¯æ??带å¤?ä¼ è¾?ã??
.TP
.B SOCK_DGRAM
æ??ä¾?æ?°æ?®æ?¥ï¼?ä¸?é?¢å??è¿?æ?¥ç??, ä¸?å?¯é? ç??å?ºå®?æ??大é?¿åº¦ç??ä¿¡æ?¯ï¼?ã??
.TP
.B SOCK_SEQPACKET
æ??ä¾?æ??åº?ç??ï¼?å?¯é? ç??ï¼?å??å??ç??ï¼?å?ºäº?å?ºå®?æ??大é?¿åº¦ç??æ?°æ?®æ?¥ä¼ è¾?è·¯å¾?ï¼?é??è¦?ä¸?个读å??æ?´ä¸ªä¼´æ??è¾?å?¥ç³»ç»?è°?ç?¨ç??å??ç??ç?¨æ?·ã??
.TP
.B SOCK_RAW
æ??ä¾?æ?ªå? å·¥(raw)ç??ç½?ç»?å??è®®é??é??ã??
.TP
.B SOCK_RDM
æ??ä¾?å?¯é? ç??æ?°æ?®æ?¥å±?ï¼?ä½?æ?¯ä¸?ä¿?è¯?顺åº?ã??
.TP
.B SOCK_PACKET
åº?å¼?ç??ï¼?ä¸?åº?该å?¨æ?°ç??ç¨?åº?ä¸ä½¿ç?¨ï¼?å??è??
.BR packet (7).
.PP
ä¸?äº?å¥?æ?¥å?ç±»å??并æ?ªè¢«æ??æ??ç??å??è®®å®?ç?°ï¼? ä¾?å¦?ï¼?
.B SOCK_SEQPACKET
并�被 AF_INET
.BR AF_INET .
å®?ç?°ã??
.PP
� Linux 2.6.27 ���
.I type
å??æ?°å?¯ä»¥æ??ä¾?å?¶ä»?ç??å??è?½ï¼? 注æ??ä¸?äº?å¥?æ?¥å?ç±»å??å?¯è?½å??æ?¬ä¸?ä¸?å?¼ç??æ??ä½?ï¼?ç?¨æ?¥ä¿®æ?¹
.BR socket ():
ç??è¡?为ã??
.TP 16
.B SOCK_NONBLOCK
设置
.BR O_NONBLOCK
ç??æ ?å¿?äº?æ?°æ??å¼?ç??æ??件æ??述符ã?? é??è¿?è¿?个æ ?å¿?å?¯ä»¥ä¸?ç?¨è°?ç?¨
.BR fcntl(2)
æ?¥è¾¾å?°ç?¸å??ç??ç»?æ??ã??
.TP
.B SOCK_CLOEXEC
设置 close-on-exec
.RB ( FD_CLOEXEC )
ç??æ ?å¿?äº?æ?°æ??å¼?ç??æ??件æ??述符ã??å??è§?
.BR open (2)
ä¸å?³äº?
.B O_CLOEXEC
ç??æ??è¿°ï¼?å? 为ä¸?äº?å??å? è¿?个æ ?å¿?å¾?æ??ç?¨ã??
.PP
.I protocol
æ??å®?ä¸?个å??è®®ç?¨äº?å¥?æ?¥å?ã??æ??å®?ä¸?个å??è®®ç?¨äº?å¥?æ?¥å?ã??ä¸?è?¬æ??å?µä¸?ï¼?å?¨ç»?å®?ç??å??è®®ä¸å?ªå??许å?¨ä¸?个å¥?æ?¥å?ä¸?使ç?¨ä¸?个å??è®®ï¼? 注æ??
.I protocol
å?¯ä»¥æ??å®?为æ?°å? 0 ã??
ä½?æ?¯ï¼? å?¯è?½å?å?¨ç??å¾?å¤?å??è®®ï¼? ä½?æ?¯å?¨æ?¬æ??å??ç??å??è®®å¿?须使ç?¨ä¸?个ã??å??è®®ç?¨äº?æ??å®?é??讯å??ç??å?°æ?¹ç??\*(lqé??讯å??å??\*(rqï¼? å??è??
.BR protocols (5)ã??
å??è??
.BR getprotoent (3)
ä¸å?³äº?å¦?ä½?æ??å??è®®å??称å?符串ä¸?å??è®®ç¼?å?·è¿?è¡?æ? å°?ã??
.PP
.B SOCK_STREAM
ç±»å??ç??å¥?æ?¥å?æ?¯å??å??ç?´æ?¥æ?°æ?®æµ?ç??ï¼?å??管é??å??å??ç?¸ä¼¼ã?? ä»?们ä¸?对记å½?溢å?ºæ??ä¾?ä¿?æ?¤ã?? ä¸?个å¥?æ?¥å?æµ?å?¨æ?¥å??æ??å??å?ºä»»ä½?æ?°æ?®æ?¶å¿?é¡»å¤?äº?
.I connected
ç??ç?¶æ??ã??å??å?¶å®?å¥?æ?¥å?é??è¿?
.BR connect (2)
è°?ç?¨æ?¥å»ºç«?è¿?æ?¥ã??
ä¸?æ?¦è¿?æ?¥ï¼? æ?°æ?®å?¯è?½é??è¿?
.BR read (2)
å??
.BR write (2)
ç³»ç»?è°?ç?¨æ?¥ä¼ è¾?ï¼?ä¹?æ??è??æ?¯ä¸?å??ç??
.BR send (2)
å??
.BR recv (2)
ç³»ç»?è°?ç?¨ã??å½?ä¼?è¯?ç»?æ??æ?¶ï¼?å?¯è?½ä¼?æ?§è¡?
.BR close (2)
带�������
.BR send (2)
å??
.BR recv (2)
æ??è¿°ä¸?æ?¥å??ã??
.PP
.B SOCK_STREAM
ç±»å??ç??ç??é??ä¿¡å??è®®åº?ç¡®ä¿?ä¿¡æ?¯ä¸?丢失ä¸?é??å¤?ã??å¦?æ??ä¸?å??æ??å??è®®ç¼?å?²ç??æ?°æ?®ä¸?è?½å?¨å??ç??æ?¶é?´å??ä¼ è¾?ï¼?è¿?æ?¥ä¼?被认为è¶?æ?¶ã??å½?å?¨å¥?æ?¥å?ä¸?å?¯ç?¨
.B SO_KEEPALIVE
ï¼?å??è®®ä¼?以å?¶ç?¹å®?æ?¹å¼?æ£?æ?¥å?¦ä¸?端æ?¯å?¦æ´»ç??ã??å½?ä¸?个è¿?ç¨?æ?¥å??æ??å??é??äº?ä¸?个é??误ç??æ?°æ?®æµ?ï¼?ä¼?产ç??并æ?¥å??ä¸?个
.B SIGPIPE
ä¿¡å?·ï¼?对äº?é??å??é»?认å¤?ç??æ¤ä¿¡å?·ç??è¿?ç¨?ï¼?å®?å°?ä¼?é??å?ºã??
.B SOCK_SEQPACKET
å¥?æ?¥å?é??ç?¨å??
.B SOCK_STREAM
å¥?æ?¥å?ç?¸å??ç??ç³»ç»?è°?ç?¨ã??å?¯ä¸?ä¸?å??ç??æ?¯ï¼?
.BR read (2)
ç³»ç»?è°?ç?¨å?ªä¼?è¿?å??请æ±?ç??æ?°æ?®é??ï¼?并å°?ä½?ä¸?å?°è¾¾ç??ä»»ä½?æ?°æ?®æ?°æ?®å??丢å¼?ã??æ¤å¤?æ??æ??ç??æ¶?æ?¯è¾¹ç??ç??ä¼ å?¥ç??â??â??æ?°æ?®æ?¥å°?被ä¿?ç??ã??
.PP
.B SOCK_DGRAM
å??
.B SOCK_RAW
ç±»å??ç??å¥?æ?¥å?æ?¯æ??ç?¨
.BR sendto (2)
ç³»ç»?è°?ç?¨æ?¥å??é??æ?°æ?®æ?¥ï¼? æ?°æ?®æ?¥é??常æ?¯ç?¨
.BR recvfrom (2),
æ?¥æ?¥å??ç??ï¼?è¿?个è°?ç?¨ä¼?å?¨ä¸?ä¸?个æ?°æ?®æ?¥ä¸å??ç?¬ç??è¿?å??å??é??è??ç??å?°å??ã??
.PP
.B SOCK_PACKET
æ?¯ä¸?个é??ç??ç??å¥?æ?¥å?ç±»å??ï¼?ç?¨æ?¥ä»?设å¤?驱å?¨ä¸æ?¥å??å??å§?æ?°æ?®ï¼?å·²ç»?被
.BR packet (7)
è°?ç?¨å??代ã??
.PP
.BR fcntl (2)
ç??
.B F_SETOWN
æ??ä½?å?¯ä»¥å?¨å¸¦å¤?æ?°æ?®å?°è¾¾æ?¶è®©è¿?ç¨?æ??è¿?ç¨?ç»?ä¼?æ?¶å?°ä¸?个
.B SIGURG
ä¿¡å?·ï¼?æ??è??å?¨
.B SOCK_STREAM
ç±»å??ç??è¿?æ?¥å?¨è¢«ä¸?æ??æ??å?°æ??æ?æ?¶ï¼?æ?¶å?°
.B SIGPIPE
ä¿¡å?·ã??è¿?个æ??ä½?ä¹?å?¯è?½è¢«ç?¨äº?让è¿?ç¨?æ??è¿?ç¨?ç»?é??è¿?
.BR SIGIO .
æ?¥æ?¶ I/O å?? I/O ä¸?å??æ¥ç??é??ç?¥ã??使ç?¨
.B F_SETOWN
ç?å??äº?使ç?¨äº?
.B FIOSETOWN
æ??
.B SIOCSPGRP
å??æ?°ç??
.BR ioctl (2)
ç³»ç»?è°?ç?¨ã??
.PP
å½?ç½?ç»?å??å??议模å??å??å?ºä¸?个é??误æ??å?µç??ä¿¡å?·(ä¾?å¦?, 对 IP 使ç?¨ ICMP æ¶?æ?¯ï¼? ï¼?å¥?æ?¥å?å°?ä¼?设置ä¸? pending é??误æ ?å¿?ã?? 对å¥?æ?¥å?æ?¥ä¸?å?»ç??æ??ä½?å°?ä¼?è¿?å?? pending é??误ç??é??误代ç ?ã??对äº?ä¸?äº?å??è®®ï¼?å?¯è?½ä¼?为æ¯?ä¸?个æ?¥å?æ?¥å?¯ç?¨ä¸?个ç?¨äº?å??å?ºè¯¦ç»?é??误信æ?¯ç??é??误å??é??ï¼?
å??è§?
.BR ip (7)
ä¸ç??
.B IP_RECVERR
ã??
.PP
å¥?æ?¥å?ç??æ??ä½?ç?±å¥?æ?¥å?级ç??
.IR é??项
æ?¥æ?§å?¶ã??
è¿?äº?é??项å®?ä¹?äº?
.IR <sys/socket.h>
ä¸ã??
.BR setsockopt (2)å??
.BR setsockopt (2)
ç?¨äº?å??å?«ç?¨äº?设置å??读å??é??项ã??
.SH "è¿?å??å?¼"
æ??å??æ?¶ï¼?ä¼?è¿?å??æ?°å¥?æ?¥å?ç??æ??件æ??述符ã??é??误æ?¶ï¼?è¿?å?? \-1 ï¼?å??æ?¶
.I errno
ä¼?被é??å½?设置ã??
.SH é??误
.TP
.B EACCES
ä¸?å??许å??建æ??å®?ç?? ç±»å?? å??/æ?? æ??å®?ç??å??è®®ç??å¥?æ?¥å?ã??
.TP
.B EAFNOSUPPORT
å·¥å?·ä¸?æ?¯æ??æ??å®?ç??å?°å??ã??
.TP
.B EINVAL
æ?ªç?¥å??è®®ï¼?æ??å??è®®ç»?ä¸?å?¯ç?¨ã??
.TP
.B EINVAL
.\" Since Linux 2.6.27
é??误ç??
.IR type
æ ?å¿?ã??
.TP
.B EMFILE
è¿?ç¨?æ??件表溢å?ºã??
.TP
.B ENFILE
å·²ç»?è¾¾å?°ç³»ç»?ä¸?é??ç??æ??件æ??å¼?æ?°ã??
.TP
.BR ENOBUFS " æ?? " ENOMEM
没æ??足å¤?ç??å??å?ï¼?ç?´å?°æ??å?¯ç?¨ç??èµ?æº?å¥?æ?¥å?ä¸?è?½è¢«å??建ã??
.TP
.B EPROTONOSUPPORT
å??议类å??æ??æ??å®?ç??å??è®®ä¸?被å½?å??å??æ??æ?¯æ??ã??
.PP
å?¶å®?ç??é??误å?¯è?½æ?¯ç?±å??议模å??产ç??ç??ã??
.SH "�容�"
4.4BSD, POSIX.1-2001.
.B SOCK_NONBLOCK
å??
.B SOCK_CLOEXEC
æ ?å¿?æ?¯ Linux ç?¹æ??ç??ã??
.BR socket ()
appeared in 4.2BSD.
å?ºç?°äº? 4.2BSD ã??é??常ï¼?é?? BSD ç³»ç»?ç?? BSD å¥?æ?¥å?å±?å??é??æ?¯å?¯ç§»æ¤?ç??ï¼?å??æ?¬ System V ç??å??ç§?ï¼?ã??
.SH 注æ??
并ä¸?è¦?æ±?å??å?«
.IR <sys/types.h>
ï¼?è¿?个头æ??件å?¨ Linux ä¸?æ?¯ä¸?å¿?é¡»ç??ã?? å?¯æ?¯ä¸?äº?å??å?²ä¸?ç?? (BSD) å·¥å?·è¦?æ±?è¿?个头æ??件ï¼? å?¯ç§»æ¤?ç¨?åº?å¾?å?¯è?½å¸?æ??å??å?«å®?ã??
4.x BSD ä¸?æ??æ?¾å?ºå®?ç??å??è®®ç»?æ??
.BR PF_UNIX ,
.BR PF_INET ,
ç?ç?ï¼?ä½?æ?¯ AF_UNIX ç?ï¼?å®?们æ?¯ç?¨äº?å?°å??ç»?ç??ã??å?¯æ?¯ BSD ç?? man page ä¿?è¯?â?? å??è®®ç»?ä¸?è?¬ç?äº?å?°å??ç»?â??ï¼?é??å??ç??æ ?å??å?¨æ¯?个å?°æ?¹é?½ä½¿ç?¨äº? AF_* ã??
.I <sys/types.h>
æ??件头å?ªå?¨ libc4 以å??æ?¯å¿?é¡»ç??ã?? ä¸?äº?å??ï¼? å¦? util-linux, claim ï¼?æ?¯ç?¨äº?å?¨æ??以 Linux ç??æ?¬å??åº?ä¸?å?¯ç§»æ¤?ç??ã??å®?们确å®?é??è¦?è¿?个头æ??件ã??
.SH ä¾?å?
å?¨
.BR getaddrinfo (3).
ä¸æ??ä¸?个使ç?¨
.BR socket ()
ç??ä¾?å?ã??
.SH "å??è§?"
.BR accept (2),
.BR bind (2),
.BR connect (2),
.BR fcntl (2),
.BR getpeername (2),
.BR getsockname (2),
.BR getsockopt (2),
.BR ioctl (2),
.BR listen (2),
.BR read (2),
.BR recv (2),
.BR select (2),
.BR send (2),
.BR shutdown (2),
.BR socketpair (2),
.BR write (2),
.BR getprotoent (3),
.BR ip (7),
.BR socket (7),
.BR tcp (7),
.BR udp (7),
.BR unix (7)
.PP
\(lqAn Introductory 4.3BSD Interprocess Communication Tutorialâ?? å?¨
.IUNIX Programmer's Supplementary Documents Volume 1
ä¸è¢«é??å?°ã??
.PP
\(lqBSD Interprocess Communication Tutorial\(rq
å?¨
.I UNIX Programmer's Supplementary Documents Volume 1
ä¸è¢«é??å?°ã??
.SH COLOPHON
This page is part of release 3.27 of the Linux
.I man-pages
project.
A description of the project,
and information about reporting bugs,
can be found at
http://www.kernel.org/doc/man-pages/.