socket()函式用於根據指定的地址族、數據類型和協定來分配一個套接口的描述字及其所用的資源。如果協定protocol未指定(等於0),則使用預設的連線方式。
對於使用一給定地址族的某一特定套接口,只支持一種協定。但地址族可設為AF_UNSPEC(未指定),這樣的話協定參數就要指定了。協定號特定於進行通訊的“通訊域”。
基本介紹
- 中文名:socket()
- 作用:分配一個套接口
- 支持協定:TCP/UDP協定
- 返回值:描述符
簡述
注釋
返回值
參見
int socket(intaf,inttype,intprotocol);
#defineAF_UNSPEC0/*unspecified*/#defineAF_UNIX1/*localtohost(pipes,portals)*/#defineAF_INET2/*internetwork:UDP,TCP,etc.*/#defineAF_IMPLINK3/*arpanetimpaddresses*/#defineAF_PUP4/*pupprotocols:e.g.BSP*/#defineAF_CHAOS5/*mitCHAOSprotocols*/#defineAF_NS6/*XEROXNSprotocols*/#defineAF_IPXAF_NS/*IPXprotocols:IPX,SPX,etc.*/#defineAF_ISO7/*ISOprotocols*/#defineAF_OSIAF_ISO/*OSIisISO*/#defineAF_ECMA8/*europeancomputermanufacturers*/#defineAF_DATAKIT9/*datakitprotocols*/#defineAF_CCITT10/*CCITTprotocols,X.25etc*/#defineAF_SNA11/*IBMSNA*/#defineAF_DECnet12/*DECnet*/#defineAF_DLI13/*Directdatalinkinterface*/#defineAF_LAT14/*LAT*/#defineAF_HYLINK15/*NSCHyperchannel*/#defineAF_APPLETALK16/*AppleTalk*/#defineAF_NETBIOS17/*NetBios-styleaddresses*/#defineAF_VOICEVIEW18/*VoiceView*/#defineAF_FIREFOX19/*ProtocolsfromFirefox*/#defineAF_UNKNOWN120/*Somebodyisusingthis!*/#defineAF_BAN21/*Banyan*/#defineAF_ATM22/*NativeATMServices*/#defineAF_INET623/*InternetworkVersion6*/#defineAF_CLUSTER24/*MicrosoftWolfpack*/#defineAF_1284425/*IEEE1284.4WGAF*/
#defineSOCK_STREAM1/*streamsocket*/#defineSOCK_DGRAM2/*datagramsocket*/#defineSOCK_RAW3/*raw-protocolinterface*/#defineSOCK_RDM4/*reliably-deliveredmessage*/#defineSOCK_SEQPACKET5/*sequencedpacketstream*/
#defineIPPROTO_IP0/*dummyforIP*/#defineIPPROTO_ICMP1/*controlmessageprotocol*/#defineIPPROTO_IGMP2/*internetgroupmanagementprotocol*/#defineIPPROTO_GGP3/*gateway^2(deprecated)*/#defineIPPROTO_TCP6/*tcp*/#defineIPPROTO_PUP12/*pup*/#defineIPPROTO_UDP17/*userdatagramprotocol*/#defineIPPROTO_IDP22/*xnsidp*/#defineIPPROTO_ND77/*UNOFFICIALnetdiskproto*/